本文整理匯總了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 }]);
});