Dart 2 updates
This commit is contained in:
parent
3a5f4609db
commit
6bf72feffc
9 changed files with 38 additions and 28 deletions
|
@ -1,2 +1,5 @@
|
||||||
|
# 2.0.7
|
||||||
|
* Minor strong mode updates to work with stricter Dart 2.
|
||||||
|
|
||||||
# 2.0.5
|
# 2.0.5
|
||||||
* Patch to work with `combinator@1.0.0`.
|
* Patch to work with `combinator@1.0.0`.
|
|
@ -1,2 +1,3 @@
|
||||||
analyzer:
|
analyzer:
|
||||||
strong-mode: true
|
strong-mode:
|
||||||
|
implicit-casts: false
|
|
@ -39,7 +39,7 @@ abstract class BrowserRouter extends Router {
|
||||||
void listen();
|
void listen();
|
||||||
|
|
||||||
/// Identical to [all].
|
/// Identical to [all].
|
||||||
Route on(Pattern path, handler, {List middleware});
|
Route on(String path, handler, {List middleware});
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class _BrowserRouterImpl extends Router implements BrowserRouter {
|
abstract class _BrowserRouterImpl extends Router implements BrowserRouter {
|
||||||
|
@ -64,7 +64,7 @@ abstract class _BrowserRouterImpl extends Router implements BrowserRouter {
|
||||||
@override
|
@override
|
||||||
void go(Iterable linkParams) => _goTo(navigate(linkParams));
|
void go(Iterable linkParams) => _goTo(navigate(linkParams));
|
||||||
|
|
||||||
Route on(Pattern path, handler, {List middleware}) =>
|
Route on(String path, handler, {List middleware}) =>
|
||||||
all(path, handler, middleware: middleware);
|
all(path, handler, middleware: middleware);
|
||||||
|
|
||||||
void prepareAnchors() {
|
void prepareAnchors() {
|
||||||
|
@ -176,7 +176,7 @@ class _PushStateRouter extends _BrowserRouterImpl {
|
||||||
|
|
||||||
void handleState(state) {
|
void handleState(state) {
|
||||||
if (state is Map && state.containsKey('path')) {
|
if (state is Map && state.containsKey('path')) {
|
||||||
var path = state['path'];
|
var path = state['path'].toString();
|
||||||
final resolved = resolveAbsolute(path).first;
|
final resolved = resolveAbsolute(path).first;
|
||||||
|
|
||||||
if (resolved != null && resolved.route != _current) {
|
if (resolved != null && resolved.route != _current) {
|
||||||
|
|
|
@ -3,34 +3,34 @@ part of angel_route.src.router;
|
||||||
class RouteGrammar {
|
class RouteGrammar {
|
||||||
static final RegExp rgx = new RegExp(r'\((.+)\)');
|
static final RegExp rgx = new RegExp(r'\((.+)\)');
|
||||||
static final Parser<String> notSlash =
|
static final Parser<String> notSlash =
|
||||||
match(new RegExp(r'[^/]+')).value((r) => r.span.text);
|
match<String>(new RegExp(r'[^/]+')).value((r) => r.span.text);
|
||||||
static final Parser<RegExp> regExp =
|
static final Parser<RegExp> regExp =
|
||||||
match(rgx).map((r) => new RegExp(r.scanner.lastMatch[1]));
|
match<RegExp>(rgx).map((r) => new RegExp(r.scanner.lastMatch[1]));
|
||||||
static final Parser<String> parameterName =
|
static final Parser<String> parameterName =
|
||||||
match(new RegExp(r':([A-Za-z0-9_]+)'))
|
match<String>(new RegExp(r':([A-Za-z0-9_]+)'))
|
||||||
.value((r) => r.span.text.substring(1));
|
.value((r) => r.span.text.substring(1));
|
||||||
|
|
||||||
static final Parser<ParameterSegment> parameterSegment = chain([
|
static final Parser<ParameterSegment> parameterSegment = chain([
|
||||||
parameterName,
|
parameterName,
|
||||||
match('?').value((r) => true).opt(),
|
match<bool>('?').value((r) => true).opt(),
|
||||||
regExp.opt(),
|
regExp.opt(),
|
||||||
]).map((r) {
|
]).map((r) {
|
||||||
var s = new ParameterSegment(r.value[0], r.value[2]);
|
var s = new ParameterSegment(r.value[0].toString(), r.value[2] as RegExp);
|
||||||
return r.value[1] == true ? new OptionalSegment(s) : s;
|
return r.value[1] == true ? new OptionalSegment(s) : s;
|
||||||
});
|
});
|
||||||
|
|
||||||
static final Parser<WildcardSegment> wildcardSegment =
|
static final Parser<WildcardSegment> wildcardSegment =
|
||||||
match('*').value((r) => new WildcardSegment());
|
match<WildcardSegment>('*').value((r) => new WildcardSegment());
|
||||||
|
|
||||||
static final Parser<ConstantSegment> constantSegment =
|
static final Parser<ConstantSegment> constantSegment =
|
||||||
notSlash.map((r) => new ConstantSegment(r.value));
|
notSlash.map((r) => new ConstantSegment(r.value));
|
||||||
|
|
||||||
static final Parser<RouteSegment> routeSegment =
|
static final Parser<RouteSegment> routeSegment =
|
||||||
any([parameterSegment, wildcardSegment, constantSegment]);
|
any<RouteSegment>([parameterSegment, wildcardSegment, constantSegment]);
|
||||||
|
|
||||||
static final Parser<RouteDefinition> routeDefinition = routeSegment
|
static final Parser<RouteDefinition> routeDefinition = routeSegment
|
||||||
.separatedBy(match('/'))
|
.separatedBy(match('/'))
|
||||||
.map((r) => new RouteDefinition(r.value ?? []))
|
.map<RouteDefinition>((r) => new RouteDefinition(r.value ?? []))
|
||||||
.surroundedBy(match('/').star().opt());
|
.surroundedBy(match('/').star().opt());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +60,8 @@ class RouteDefinition {
|
||||||
if (out == null)
|
if (out == null)
|
||||||
out = s.compile(isLast);
|
out = s.compile(isLast);
|
||||||
else
|
else
|
||||||
out = s.compileNext(out.then(match('/')).index(0), isLast);
|
out = s.compileNext(
|
||||||
|
out.then(match('/')).index(0).cast<Map<String, dynamic>>(), isLast);
|
||||||
}
|
}
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
|
@ -86,13 +87,13 @@ class ConstantSegment extends RouteSegment {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Parser<Map<String, dynamic>> compile(bool isLast) {
|
Parser<Map<String, dynamic>> compile(bool isLast) {
|
||||||
return match(text).value((r) => {});
|
return match<Map<String, dynamic>>(text).value((r) => {});
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Parser<Map<String, dynamic>> compileNext(
|
Parser<Map<String, dynamic>> compileNext(
|
||||||
Parser<Map<String, dynamic>> p, bool isLast) {
|
Parser<Map<String, dynamic>> p, bool isLast) {
|
||||||
return p.then(compile(isLast)).index(0);
|
return p.then(compile(isLast)).index(0).cast<Map<String, dynamic>>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,7 +116,7 @@ class WildcardSegment extends RouteSegment {
|
||||||
@override
|
@override
|
||||||
Parser<Map<String, dynamic>> compileNext(
|
Parser<Map<String, dynamic>> compileNext(
|
||||||
Parser<Map<String, dynamic>> p, bool isLast) {
|
Parser<Map<String, dynamic>> p, bool isLast) {
|
||||||
return p.then(_compile(isLast)).index(0);
|
return p.then(_compile(isLast)).index(0).cast<Map<String, dynamic>>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,9 +138,11 @@ class OptionalSegment extends ParameterSegment {
|
||||||
@override
|
@override
|
||||||
Parser<Map<String, dynamic>> compileNext(
|
Parser<Map<String, dynamic>> compileNext(
|
||||||
Parser<Map<String, dynamic>> p, bool isLast) {
|
Parser<Map<String, dynamic>> p, bool isLast) {
|
||||||
return p.then(_compile().opt()).map((r) {
|
var pp = p.then(_compile().opt());
|
||||||
if (r.value[1] == null) return r.value[0];
|
return pp.map((r) {
|
||||||
return r.value[0]..addAll({name: Uri.decodeComponent(r.value[1])});
|
if (r.value[1] == null) return r.value[0] as Map<String, dynamic>;
|
||||||
|
return (r.value[0] as Map<String, dynamic>)
|
||||||
|
..addAll({name: Uri.decodeComponent(r.value[1].toString())});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -156,9 +159,9 @@ class ParameterSegment extends RouteSegment {
|
||||||
return 'Param: $name';
|
return 'Param: $name';
|
||||||
}
|
}
|
||||||
|
|
||||||
Parser<Map<String, dynamic>> _compile() {
|
Parser<String> _compile() {
|
||||||
return regExp != null
|
return regExp != null
|
||||||
? match(regExp).value((r) => r.span.text)
|
? match<String>(regExp).value((r) => r.span.text)
|
||||||
: RouteGrammar.notSlash;
|
: RouteGrammar.notSlash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,7 +174,8 @@ class ParameterSegment extends RouteSegment {
|
||||||
Parser<Map<String, dynamic>> compileNext(
|
Parser<Map<String, dynamic>> compileNext(
|
||||||
Parser<Map<String, dynamic>> p, bool isLast) {
|
Parser<Map<String, dynamic>> p, bool isLast) {
|
||||||
return p.then(_compile()).map((r) {
|
return p.then(_compile()).map((r) {
|
||||||
return r.value[0]..addAll({name: Uri.decodeComponent(r.value[1])});
|
return (r.value[0] as Map<String, dynamic>)
|
||||||
|
..addAll({name: Uri.decodeComponent(r.value[1].toString())});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,5 +18,6 @@ class MiddlewarePipeline {
|
||||||
return _handlers = handlers;
|
return _handlers = handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
MiddlewarePipeline(this.routingResults);
|
MiddlewarePipeline(Iterable<RoutingResult> routingResults)
|
||||||
|
: this.routingResults = routingResults.toList();
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ class Route {
|
||||||
: _routeDefinition = RouteGrammar.routeDefinition
|
: _routeDefinition = RouteGrammar.routeDefinition
|
||||||
.parse(new SpanScanner(path.replaceAll(_straySlashes, '')))
|
.parse(new SpanScanner(path.replaceAll(_straySlashes, '')))
|
||||||
.value {
|
.value {
|
||||||
if (_routeDefinition?.segments?.isNotEmpty != true) _parser = match('').value((r) => {});
|
if (_routeDefinition?.segments?.isNotEmpty != true) _parser = match<Map<String, dynamic>>('').value((r) => {});
|
||||||
}
|
}
|
||||||
|
|
||||||
factory Route.join(Route a, Route b) {
|
factory Route.join(Route a, Route b) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
name: angel_route
|
name: angel_route
|
||||||
description: A powerful, isomorphic routing library for Dart.
|
description: A powerful, isomorphic routing library for Dart.
|
||||||
version: 2.0.6
|
version: 2.0.7
|
||||||
author: Tobe O <thosakwe@gmail.com>
|
author: Tobe O <thosakwe@gmail.com>
|
||||||
homepage: https://github.com/angel-dart/angel_route
|
homepage: https://github.com/angel-dart/angel_route
|
||||||
environment:
|
environment:
|
||||||
|
|
|
@ -8,7 +8,7 @@ main() {
|
||||||
router.get('/user/:id', 'GET');
|
router.get('/user/:id', 'GET');
|
||||||
router.get('/first/:first/last/:last', 'GET').name = 'full_name';
|
router.get('/first/:first/last/:last', 'GET').name = 'full_name';
|
||||||
|
|
||||||
navigate(params) {
|
navigate(Iterable params) {
|
||||||
final uri = router.navigate(params);
|
final uri = router.navigate(params);
|
||||||
print('Uri: $uri');
|
print('Uri: $uri');
|
||||||
return uri;
|
return uri;
|
||||||
|
|
|
@ -89,10 +89,11 @@ main() {
|
||||||
|
|
||||||
if (pipeline.handlers.isEmpty) {
|
if (pipeline.handlers.isEmpty) {
|
||||||
res
|
res
|
||||||
..statusCode = HttpStatus.NOT_FOUND
|
..statusCode = 404
|
||||||
..writeln('404 Not Found');
|
..writeln('404 Not Found');
|
||||||
} else {
|
} else {
|
||||||
for (final handler in pipeline.handlers) {
|
for (bool Function(HttpRequest, HttpResponse) handler
|
||||||
|
in pipeline.handlers) {
|
||||||
if (!await handler(req, res)) break;
|
if (!await handler(req, res)) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue