This commit is contained in:
thosakwe 2017-02-24 19:16:31 -05:00
parent 58d5b0972e
commit fbd26eb448
6 changed files with 23 additions and 10 deletions

View file

@ -1,6 +1,6 @@
# angel_framework # 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) [![build status](https://travis-ci.org/angel-dart/framework.svg)](https://travis-ci.org/angel-dart/framework)
Core libraries for the Angel Framework. Core libraries for the Angel Framework.

View file

@ -39,7 +39,7 @@ class Controller {
Controller({this.debug: false}); Controller({this.debug: false});
Future call(Angel app) async { Future call(Angel app) async {
_app = app; _app = app..container.singleton(this);
// Load global expose decl // Load global expose decl
ClassMirror classMirror = reflectClass(this.runtimeType); ClassMirror classMirror = reflectClass(this.runtimeType);

View file

@ -64,7 +64,7 @@ class MapService extends Service {
if (data is! Map) if (data is! Map)
throw new AngelHttpException.badRequest( throw new AngelHttpException.badRequest(
message: message:
'MapService does not support `create` with ${data.runtimeType}.'); 'MapService does not support `modify` with ${data.runtimeType}.');
var item = await read(id); var item = await read(id);
return item return item
..addAll(data) ..addAll(data)
@ -76,7 +76,7 @@ class MapService extends Service {
if (data is! Map) if (data is! Map)
throw new AngelHttpException.badRequest( throw new AngelHttpException.badRequest(
message: message:
'MapService does not support `create` with ${data.runtimeType}.'); 'MapService does not support `update` with ${data.runtimeType}.');
if (!items.any(_matchesId(id))) if (!items.any(_matchesId(id)))
throw new AngelHttpException.notFound( throw new AngelHttpException.notFound(
message: 'No record found for ID $id'); message: 'No record found for ID $id');

View file

@ -24,8 +24,11 @@ typedef Future<HttpServer> ServerGenerator(InternetAddress address, int port);
typedef Future AngelErrorHandler( typedef Future AngelErrorHandler(
AngelHttpException err, RequestContext req, ResponseContext res); AngelHttpException err, RequestContext req, ResponseContext res);
/// A function that configures an [AngelBase] server in some way. /// A function that configures an [Angel] server in some way.
typedef Future AngelConfigurer(AngelBase app); typedef Future AngelConfigurer(Angel app);
/// A function that takes no parameters.
typedef ParameterlessFunction();
/// A powerful real-time/REST/MVC server class. /// A powerful real-time/REST/MVC server class.
class Angel extends AngelBase { class Angel extends AngelBase {
@ -153,6 +156,8 @@ class Angel extends AngelBase {
if (result is bool) if (result is bool)
return result == true; return result == true;
else if (result is RequestHandler)
return await executeHandler(result, req, res);
else if (result != null) { else if (result != null) {
res.serialize(result); res.serialize(result);
return false; return false;
@ -161,7 +166,9 @@ class Angel extends AngelBase {
} }
if (handler is RequestHandler) { 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; return res.isOpen;
} }
@ -169,6 +176,8 @@ class Angel extends AngelBase {
var result = await handler; var result = await handler;
if (result is bool) if (result is bool)
return result == true; return result == true;
else if (result is RequestHandler)
return await executeHandler(result, req, res);
else if (result != null) { else if (result != null) {
res.serialize(result); res.serialize(result);
return false; return false;
@ -180,6 +189,8 @@ class Angel extends AngelBase {
var result = await runContained(handler, req, res); var result = await runContained(handler, req, res);
if (result is bool) if (result is bool)
return result == true; return result == true;
else if (result is RequestHandler)
return await executeHandler(result, req, res);
else if (result != null) { else if (result != null) {
res.serialize(result); res.serialize(result);
return false; return false;
@ -479,8 +490,10 @@ class Angel extends AngelBase {
/// Predetermines what needs to be injected for a handler to run. /// Predetermines what needs to be injected for a handler to run.
InjectionRequest preInject(Function handler) { InjectionRequest preInject(Function handler) {
ClosureMirror closureMirror = reflect(handler);
var injection = new InjectionRequest(); var injection = new InjectionRequest();
if (handler is ParameterlessFunction) return injection;
ClosureMirror closureMirror = reflect(handler);
// Load parameters // Load parameters
for (var parameter in closureMirror.function.parameters) { for (var parameter in closureMirror.function.parameters) {

View file

@ -10,7 +10,7 @@ class TypedService<T> extends Service {
TypedService(this.inner) : super() { TypedService(this.inner) : super() {
if (!reflectType(T).isAssignableTo(reflectType(Model))) if (!reflectType(T).isAssignableTo(reflectType(Model)))
throw new Exception( 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) { deserialize(x) {

View file

@ -1,5 +1,5 @@
name: angel_framework name: angel_framework
version: 1.0.0-dev.57 version: 1.0.0-dev.58
description: Core libraries for the Angel framework. description: Core libraries for the Angel framework.
author: Tobe O <thosakwe@gmail.com> author: Tobe O <thosakwe@gmail.com>
homepage: https://github.com/angel-dart/angel_framework homepage: https://github.com/angel-dart/angel_framework