diff --git a/README.md b/README.md index f0dee8fc..709a7ddf 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # angel_framework -[![pub 1.0.0-dev.57](https://img.shields.io/badge/pub-1.0.0--dev.57-red.svg)](https://pub.dartlang.org/packages/angel_framework) +[![pub 1.0.0-dev.58](https://img.shields.io/badge/pub-1.0.0--dev.58-red.svg)](https://pub.dartlang.org/packages/angel_framework) [![build status](https://travis-ci.org/angel-dart/framework.svg)](https://travis-ci.org/angel-dart/framework) Core libraries for the Angel Framework. diff --git a/lib/src/http/controller.dart b/lib/src/http/controller.dart index 36149027..bde968f9 100644 --- a/lib/src/http/controller.dart +++ b/lib/src/http/controller.dart @@ -39,7 +39,7 @@ class Controller { Controller({this.debug: false}); Future call(Angel app) async { - _app = app; + _app = app..container.singleton(this); // Load global expose decl ClassMirror classMirror = reflectClass(this.runtimeType); diff --git a/lib/src/http/map_service.dart b/lib/src/http/map_service.dart index 7084548b..d5a1bd69 100644 --- a/lib/src/http/map_service.dart +++ b/lib/src/http/map_service.dart @@ -64,7 +64,7 @@ class MapService extends Service { if (data is! Map) throw new AngelHttpException.badRequest( message: - 'MapService does not support `create` with ${data.runtimeType}.'); + 'MapService does not support `modify` with ${data.runtimeType}.'); var item = await read(id); return item ..addAll(data) @@ -76,7 +76,7 @@ class MapService extends Service { if (data is! Map) throw new AngelHttpException.badRequest( message: - 'MapService does not support `create` with ${data.runtimeType}.'); + 'MapService does not support `update` with ${data.runtimeType}.'); if (!items.any(_matchesId(id))) throw new AngelHttpException.notFound( message: 'No record found for ID $id'); diff --git a/lib/src/http/server.dart b/lib/src/http/server.dart index ec4ef8be..be412695 100644 --- a/lib/src/http/server.dart +++ b/lib/src/http/server.dart @@ -24,8 +24,11 @@ typedef Future ServerGenerator(InternetAddress address, int port); typedef Future AngelErrorHandler( AngelHttpException err, RequestContext req, ResponseContext res); -/// A function that configures an [AngelBase] server in some way. -typedef Future AngelConfigurer(AngelBase app); +/// A function that configures an [Angel] server in some way. +typedef Future AngelConfigurer(Angel app); + +/// A function that takes no parameters. +typedef ParameterlessFunction(); /// A powerful real-time/REST/MVC server class. class Angel extends AngelBase { @@ -153,6 +156,8 @@ class Angel extends AngelBase { if (result is bool) return result == true; + else if (result is RequestHandler) + return await executeHandler(result, req, res); else if (result != null) { res.serialize(result); return false; @@ -161,7 +166,9 @@ class Angel extends AngelBase { } if (handler is RequestHandler) { - await handler(req, res); + var result = await handler(req, res); + if (result is RequestHandler) + return await executeHandler(result, req, res); return res.isOpen; } @@ -169,6 +176,8 @@ class Angel extends AngelBase { var result = await handler; if (result is bool) return result == true; + else if (result is RequestHandler) + return await executeHandler(result, req, res); else if (result != null) { res.serialize(result); return false; @@ -180,6 +189,8 @@ class Angel extends AngelBase { var result = await runContained(handler, req, res); if (result is bool) return result == true; + else if (result is RequestHandler) + return await executeHandler(result, req, res); else if (result != null) { res.serialize(result); return false; @@ -479,8 +490,10 @@ class Angel extends AngelBase { /// Predetermines what needs to be injected for a handler to run. InjectionRequest preInject(Function handler) { - ClosureMirror closureMirror = reflect(handler); var injection = new InjectionRequest(); + if (handler is ParameterlessFunction) return injection; + + ClosureMirror closureMirror = reflect(handler); // Load parameters for (var parameter in closureMirror.function.parameters) { diff --git a/lib/src/http/typed_service.dart b/lib/src/http/typed_service.dart index 09dd0f39..f6612ed4 100644 --- a/lib/src/http/typed_service.dart +++ b/lib/src/http/typed_service.dart @@ -10,7 +10,7 @@ class TypedService extends Service { TypedService(this.inner) : super() { if (!reflectType(T).isAssignableTo(reflectType(Model))) throw new Exception( - "If you specify a type for MongoService, it must extend Model."); + "If you specify a type for TypedService, it must extend Model."); } deserialize(x) { diff --git a/pubspec.yaml b/pubspec.yaml index 3d28f5a4..dba3746a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: angel_framework -version: 1.0.0-dev.57 +version: 1.0.0-dev.58 description: Core libraries for the Angel framework. author: Tobe O homepage: https://github.com/angel-dart/angel_framework