本文整理汇总了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 }]);
});
示例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 }]);
});