本文整理汇总了TypeScript中route-recognizer.map函数的典型用法代码示例。如果您正苦于以下问题:TypeScript map函数的具体用法?TypeScript map怎么用?TypeScript map使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了map函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: function
QUnit.test("delegate can change added routes", (assert: Assert) => {
router.delegate = {
willAddRoute: function(context, route) {
if (!context) { return route; }
context = context.split(".").slice(-1)[0];
return context + "." + route;
},
// Test that both delegates work together
contextEntered: function(_, match) {
match("/").to("index");
}
};
router.map(function(match) {
match("/").to("application", function(match) {
match("/posts").to("posts", function(match) {
match("/:post_id").to("post");
});
});
});
matchesRoute(assert, "/posts", [{ handler: "application", params: {}, isDynamic: false }, { handler: "application.posts", params: {}, isDynamic: false }, { handler: "posts.index", params: {}, isDynamic: false }]);
matchesRoute(assert, "/posts/1", [{ handler: "application", params: {}, isDynamic: false }, { handler: "application.posts", params: {}, isDynamic: false }, { handler: "posts.post", params: { post_id: "1" }, isDynamic: true }]);
});
开发者ID:nathanhammond,项目名称:route-recognizer,代码行数:25,代码来源:router-tests.ts
示例2: match
QUnit.test("supports add-route callback", (assert: Assert) => {
const invocations: string[] = [];
router.map(function(match) {
match('/').to('application', function(match) {
match('/loading').to('loading');
match('/_unused_dummy_error_path_route_application/:error').to('error');
match('/lobby').to('lobby', function(match) {
match('/loading').to('lobby.loading');
match('/_unused_dummy_error_path_route_lobby/:error').to('lobby.error');
match(':lobby_id').to('lobby.index');
match('/list').to('lobby.list');
});
match('/').to('index');
});
}, function (router, route) {
invocations.push(route.map(e => e.handler).join('.'));
router.add(route);
});
const expected = [
'application.loading',
'application.error',
'application.lobby.lobby.loading',
'application.lobby.lobby.error',
'application.lobby.lobby.index',
'application.lobby.lobby.list',
'application.index'
];
assert.deepEqual(expected, invocations, 'invokes for the correct set of routes');
matchesRoute(assert, "/lobby/loading", [{ handler: "application", params: {}, isDynamic: false }, { handler: "lobby", params: {}, isDynamic: false }, { handler: "lobby.loading", params: {}, isDynamic: false }]);
});
开发者ID:nathanhammond,项目名称:route-recognizer,代码行数:34,代码来源:router-tests.ts
注:本文中的route-recognizer.map函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论