From 1623e92e946fc646ed813b9a3b61751dabeccd70 Mon Sep 17 00:00:00 2001 From: Tobe O Date: Thu, 19 Oct 2017 14:32:41 -0400 Subject: [PATCH] 1.1.0 --- .idea/hot.iml | 4 ---- README.md | 1 - example/basic/server.dart | 24 +++++++++++++++++------- lib/angel_hot.dart | 12 +++++------- pubspec.yaml | 8 +++----- 5 files changed, 25 insertions(+), 24 deletions(-) diff --git a/.idea/hot.iml b/.idea/hot.iml index 466ce67a..eae13016 100644 --- a/.idea/hot.iml +++ b/.idea/hot.iml @@ -5,10 +5,6 @@ - - - - diff --git a/README.md b/README.md index b6b0c587..c2b941a2 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,6 @@ In your `pubspec.yaml`: ```yaml dependencies: - angel_framework: ^1.0.0 angel_hot: ^1.0.0 ``` diff --git a/example/basic/server.dart b/example/basic/server.dart index 2bf80b3c..cd4c8194 100644 --- a/example/basic/server.dart +++ b/example/basic/server.dart @@ -1,10 +1,9 @@ import 'dart:async'; import 'dart:convert'; import 'dart:io'; -import 'package:angel_compress/angel_compress.dart'; -import 'package:angel_diagnostics/angel_diagnostics.dart'; import 'package:angel_framework/angel_framework.dart'; import 'package:angel_hot/angel_hot.dart'; +import 'package:logging/logging.dart'; import 'src/foo.dart'; main() async { @@ -20,19 +19,30 @@ main() async { } Future createServer() async { - // Max speed??? var app = new Angel(); app.lazyParseBodies = true; app.injectSerializer(JSON.encode); + // Edit this line, and then refresh the page in your browser! app.get('/', {'hello': 'hot world!'}); app.get('/foo', new Foo(bar: 'baz')); - app.after.add(() => throw new AngelHttpException.notFound()); + app.use(() => throw new AngelHttpException.notFound()); + + app.injectEncoders({ + 'gzip': GZIP.encoder, + 'deflate': ZLIB.encoder, + }); + + app.logger = new Logger('angel') + ..onRecord.listen((rec) { + print(rec); + if (rec.error != null) { + print(rec.error); + print(rec.stackTrace); + } + }); - app.responseFinalizers.add(gzip()); - //await app.configure(cacheResponses()); - await app.configure(logRequests()); return app; } diff --git a/lib/angel_hot.dart b/lib/angel_hot.dart index 5e904729..1fd46943 100644 --- a/lib/angel_hot.dart +++ b/lib/angel_hot.dart @@ -11,9 +11,7 @@ import 'package:html_builder/html_builder.dart'; import 'package:vm_service_client/vm_service_client.dart'; import 'package:watcher/watcher.dart'; -/// A typedef over a function that returns a fresh [Angel] instance, whether synchronously or asynchronously. -typedef FutureOr AngelGenerator(); - +/// A utility class that watches the filesystem for changes, and starts new instances of an Angel server. class HotReloader { VMServiceClient _client; final StreamController _onChange = @@ -25,7 +23,7 @@ class HotReloader { Duration _timeout; /// Invoked to load a new instance of [Angel] on file changes. - final AngelGenerator generator; + final FutureOr Function() generator; /// Fires whenever a file change. You might consider using this to trigger /// page reloads in a client. @@ -105,7 +103,7 @@ class HotReloader { Future _generateServer() async { var s = await generator() as Angel; - await Future.forEach(s.justBeforeStart, s.configure); + await Future.forEach(s.startupHooks, s.configure); s.optimizeForProduction(); return s; } @@ -214,14 +212,14 @@ class HotReloader { for (var client in ws.clients) { try { - client.io.close(WebSocketStatus.GOING_AWAY); + await client.close(WebSocketStatus.GOING_AWAY); } catch (e) { stderr.writeln( 'Couldn\'t close WebSocket from session #${client.request.session.id}: $e'); } } - Future.forEach(old.justBeforeStop, old.configure); + Future.forEach(old.shutdownHooks, old.configure); }); } diff --git a/pubspec.yaml b/pubspec.yaml index 43939d79..095ce871 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,21 +1,19 @@ name: angel_hot description: Supports hot reloading of Angel servers on file changes. -version: 1.0.1 +version: 1.1.0-alpha author: Tobe O homepage: https://github.com/angel-dart/hot environment: sdk: ">=1.19.0" dependencies: - angel_framework: ^1.0.0-dev - angel_websocket: ^1.0.0 + angel_framework: ^1.1.0-alpha + angel_websocket: ^1.1.0-alpha html_builder: ^1.0.0 vm_service_client: git: url: git://github.com/BlackHC/vm_service_client.git ref: reload_sources_poc dev_dependencies: - angel_compress: ^1.0.0 - angel_diagnostics: ^1.0.0 angel_test: ^1.0.0 http: ^0.11.3 test: ^0.12.15 \ No newline at end of file