Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

can-route

Package Overview
Dependencies
Maintainers
4
Versions
118
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

can-route - npm Package Compare versions

Comparing version 3.0.0-pre.16 to 3.0.0-pre.17

53

can-route.js

@@ -124,6 +124,2 @@ /*jshint -W079 */

var isDefineMap = function(map) {
return types.isMapLike(map) && typeof map.get === "function";
};
// A ~~throttled~~ debounced function called multiple times will only fire once the

@@ -247,3 +243,3 @@ // timer runs down. Each call resets the timer.

// trigger a url change so its possible to live-bind on url-based changes
canBatch.trigger(eventsObject,"__url",[path, lastHash]);
canEvent.dispatch.call(eventsObject,"__url",[path, lastHash]);
lastHash = path;

@@ -318,2 +314,3 @@ changedAttrs = [];

curParams =canRoute.deparam(hash);
var matched;

@@ -326,5 +323,9 @@ // if the hash data is currently changing, or

matched = curParams.route;
delete curParams.route;
canRoute.matched(matched);
canRoute.attr(curParams);
curParams.route = matched;
// trigger a url change so its possible to live-bind on url-based changes
canRoute.batch.trigger.call(eventsObject,"__url",[hash, lastHash]);
canEvent.dispatch.call(eventsObject,"__url",[hash, lastHash]);
canRoute.batch.stop();

@@ -408,3 +409,3 @@ }

// fall back to legacy :foo RegExp if necessary
matcher = colonMatcher.test(route.route) ? colonMatcher : curliesMatcher;
matcher = colonMatcher.test(route.route) ? colonMatcher : curliesMatcher;
// Create the url by replacing the var names with the provided data.

@@ -429,3 +430,3 @@ // If the default value is found an empty string is inserted.

if (_setRoute) {
canRoute.attr('route', route.route);
canRoute.matched(route.route);
}

@@ -543,2 +544,3 @@ return res + (after ? canRoute._call("querySeparator") + after : "");

map: function(data){
dev.warn('Set route.data directly instead of calling route.map');
canRoute.data = data;

@@ -837,3 +839,25 @@ },

}
}
},
/**
* @function can-route.matched matched
* @parent can-route.static
* @description A compute representing the currently matched route.
* @signature `route.matched()`
* @return {String} The currently matched route.
*
* @body
* Use `route.matched()` to find the currently matched route.
*
* ```js
* route("{type}", { type: "foo" });
* route("{type}/{subtype}");
*
* route.matched(); // "{type}"
*
* route.data.subtype = "foo";
*
* route.matched(); // "{type}/{subtype}"
* ```
*/
matched: compute()
});

@@ -903,13 +927,2 @@

}
if(isDefineMap(data) && Object.isSealed(data)) {
var proto = data.constructor.prototype;
// Set a constructor definition so can-define knows this already exists.
var definitions = proto._define.definitions;
if(!definitions.route) {
var errMsg = "Cannot map a DefineMap without a 'route' property defined.";
throw new Error(errMsg);
}
}
}

@@ -916,0 +929,0 @@ });

@@ -192,3 +192,3 @@ @function can-route can-route

The matched route is the one that will be used to set the `window.location.hash`. The process can-route uses to find the matched route is:
The matched route is stored in the compute `route.matched` and is used to set the `window.location.hash`. The process can-route uses to find the matched route is:
- Find all routes with all of their map properties set

@@ -209,3 +209,3 @@ - If multiple routes are matched, find the route with the highest number of set properties

route.data.route; // "{page}/{section}"
route.matched(); // "{page}/{section}"
```

@@ -222,3 +222,3 @@

route.data.route; // "{page}"
route.matched(); // "{page}"
```

@@ -238,3 +238,3 @@

route.data.route; // "{page}/{section}"
route.matched(); // "{page}/{section}"
```

@@ -254,3 +254,3 @@

route.data.route; // ""
route.matched(); // ""
```
{
"name": "can-route",
"version": "3.0.0-pre.16",
"version": "3.0.0-pre.17",
"description": "",

@@ -5,0 +5,0 @@ "homepage": "",

@@ -23,3 +23,3 @@ /* jshint asi:true */

canRoute.routes = {};
canRoute(":page", {
canRoute("{page}", {
page: "index"

@@ -31,3 +31,3 @@ });

page: "can.Control",
route: ":page"
route: "{page}"
});

@@ -38,3 +38,3 @@

page: "index",
route: ":page"
route: "{page}"
});

@@ -46,7 +46,7 @@

where: "there",
route: ":page"
route: "{page}"
});
canRoute.routes = {};
canRoute(":page/:index", {
canRoute("{page}/{index}", {
page: "index",

@@ -61,3 +61,3 @@ index: "foo"

where: "there",
route: ":page/:index"
route: "{page}/{index}"
}, "default value and queryparams");

@@ -69,3 +69,3 @@ });

canRoute.routes = {};
canRoute("pages/:var1/:var2/:var3", {
canRoute("pages/{var1}/{var2}/{var3}", {
var1: 'default1',

@@ -88,3 +88,3 @@ var2: 'default2',

var3: 'val3',
route: "pages/:var1/:var2/:var3"
route: "pages/{var1}/{var2}/{var3}"
});

@@ -109,3 +109,3 @@ });

canRoute.routes = {};
canRoute("pages/:page", {
canRoute("pages/{page}", {
page: "index"

@@ -125,3 +125,3 @@ })

canRoute("pages/:page/:foo", {
canRoute("pages/{page}/{foo}", {
page: "index",

@@ -174,3 +174,3 @@ foo: "bar"

canRoute.routes = {};
canRoute(":page", {
canRoute("{page}", {
page: "index"

@@ -184,3 +184,3 @@ })

canRoute("pages/:p1/:p2/:p3", {
canRoute("pages/{p1}/{p2}/{p3}", {
p1: "index",

@@ -209,3 +209,3 @@ p2: "foo",

canRoute("pages/:p1", {
canRoute("pages/{p1}", {
p2: "foo"

@@ -222,3 +222,3 @@ })

canRoute(":page/:type", {
canRoute("{page}/{type}", {
page: "index",

@@ -283,3 +283,3 @@ type: "foo"

canRoute.routes = {};
canRoute(":foo/:bar", {
canRoute("{foo}/{bar}", {
foo: 1,

@@ -298,3 +298,3 @@ bar: 2

bar: 2,
route: ":foo/:bar"
route: "{foo}/{bar}"
})

@@ -305,6 +305,6 @@ })

canRoute.routes = {};
canRoute(":who", {
canRoute("{who}", {
who: "index"
});
canRoute("search/:search");
canRoute("search/{search}");

@@ -314,3 +314,3 @@ var obj = canRoute.deparam("can.Control");

who: "can.Control",
route: ":who"
route: "{who}"
});

@@ -321,3 +321,3 @@

search: "can.Control",
route: "search/:search"
route: "search/{search}"
}, "bad deparam");

@@ -338,6 +338,6 @@

canRoute.routes = {};
canRoute(":type", {
canRoute("{type}", {
who: "index"
});
canRoute(":type/:id");
canRoute("{type}/{id}");

@@ -353,3 +353,3 @@ equal(canRoute.param({

canRoute.routes = {};
canRoute(":foo");
canRoute("{foo}");
var res = canRoute.link("Hello", {

@@ -391,3 +391,3 @@ foo: "bar",

canRoute.routes = {};
canRoute(":type/:id");
canRoute("{type}/{id}");
var res = canRoute.deparam("foo/" + encodeURIComponent("\/"))

@@ -405,3 +405,3 @@ equal(res.id, "\/")

canRoute.routes = {};
canRoute(":who");
canRoute("{who}");
canRoute("", {

@@ -420,4 +420,4 @@ foo: "bar"

canRoute.routes = {};
canRoute(":foo");
canRoute(":bar")
canRoute("{foo}");
canRoute("{bar}")

@@ -427,3 +427,3 @@ var obj = canRoute.deparam("abc");

foo: "abc",
route: ":foo"
route: "{foo}"
});

@@ -437,3 +437,3 @@ });

});
canRoute("something/:bar");
canRoute("something/{bar}");
var res = canRoute.param({

@@ -447,3 +447,3 @@ bar: "foo"

canRoute(":recipe", {
canRoute("{recipe}", {
recipe: "recipe1",

@@ -453,3 +453,3 @@ task: "task3"

canRoute(":recipe/:task", {
canRoute("{recipe}/{task}", {
recipe: "recipe1",

@@ -475,3 +475,3 @@ task: "task3"

canRoute.routes = {};
canRoute(":foo-:bar");
canRoute("{foo}-{bar}");

@@ -482,3 +482,3 @@ var obj = canRoute.deparam("abc-def");

bar: "def",
route: ":foo-:bar"
route: "{foo}-{bar}"
});

@@ -540,3 +540,3 @@

iCanRoute("", {});
iCanRoute.serializedCompute.bind('change', function(){
iCanRoute.matched.bind('change', function(){
ok(true, 'change triggered once')

@@ -585,3 +585,3 @@ start();

iCanRoute(":type/:id");
iCanRoute("{type}/{id}");
var AppState = DefineMap.extend({seal: false},{});

@@ -611,3 +611,3 @@ var appState = new AppState({type: "dog", id: '4'});

iCanRoute(":type/:id");
iCanRoute("{type}/{id}");
var AppState = win.DefineMap.extend({seal: false},{});

@@ -641,3 +641,3 @@ var appState = new AppState({section: 'home'});

iCanRoute.ready();
iCanRoute(":type/:id");
iCanRoute("{type}/{id}");
iCanRoute.attr({

@@ -683,4 +683,4 @@ type: "bar",

iCanRoute.ready();
iCanRoute(":type");
iCanRoute(":type/:id");
iCanRoute("{type}");
iCanRoute("{type}/{id}");
iCanRoute.attr({

@@ -843,3 +843,3 @@ type: "bar"

iCanRoute.ready();
iCanRoute(":path");
iCanRoute("{path}");

@@ -882,3 +882,3 @@ iCanRoute.attr('path', 'foo');

canRoute.routes = {};
canRoute(":page\\.html", {
canRoute("{page}\\.html", {
page: "index"

@@ -890,3 +890,3 @@ });

page: "can.Control",
route: ":page\\.html"
route: "{page}\\.html"
});

@@ -956,3 +956,3 @@

route.routes = {};
route(":type/:id");
route("{type}/{id}");

@@ -1068,3 +1068,3 @@ route.attr({

QUnit.ok(canRoute.url({page: "recipe", id: 6}, true), "not all equal");
mockRoute.stop();

@@ -1076,31 +1076,28 @@ QUnit.start();

test("Throws on DefineMap that's sealed and no 'route' defined", function(){
test("matched() compute", function() {
stop();
var AppState = DefineMap.extend({
page: "string"
seal: false
}, {
type: "string",
subtype: "string"
});
var appState = new AppState();
try {
canRoute.map(appState);
canRoute.data = appState;
canRoute("{type}", { type: "foo" });
canRoute("{type}/{subtype}");
canRoute.ready();
QUnit.ok(false, "This should have thrown");
} catch(err) {
QUnit.ok(true, "Threw because no 'route' defined");
}
});
equal(appState.route, undefined, "should not set route on appState");
equal(canRoute.matched(), "{type}", "should set route.matched property");
test("Throws on a DefineMap derived constructor with no 'route' defined", function(){
var AppState = DefineMap.extend({
page: "string"
});
try {
canRoute.map(AppState);
appState.subtype = "bar";
QUnit.ok(false, "This should have thrown");
} catch(err) {
QUnit.ok(true, "Threw because no 'route' defined");
}
setTimeout(function() {
equal(canRoute.matched(), "{type}/{subtype}", "should update route.matched property");
start();
}, 200);
});
}

@@ -22,2 +22,42 @@ /* jshint asi:true */

canRoute.routes = {};
canRoute("{page}", {
page: "index"
});
var obj = canRoute.deparam("can.Control");
deepEqual(obj, {
page: "can.Control",
route: "{page}"
});
obj = canRoute.deparam("");
deepEqual(obj, {
page: "index",
route: "{page}"
});
obj = canRoute.deparam("can.Control&where=there");
deepEqual(obj, {
page: "can.Control",
where: "there",
route: "{page}"
});
canRoute.routes = {};
canRoute("{page}/{index}", {
page: "index",
index: "foo"
});
obj = canRoute.deparam("can.Control/&where=there");
deepEqual(obj, {
page: "can.Control",
index: "foo",
where: "there",
route: "{page}/{index}"
}, "default value and queryparams");
});
test("deparam - `:page` syntax", function () {
canRoute.routes = {};
canRoute(":page", {

@@ -64,3 +104,3 @@ page: "index"

canRoute.routes = {};
canRoute("pages/:var1/:var2/:var3", {
canRoute("pages/{var1}/{var2}/{var3}", {
var1: 'default1',

@@ -83,3 +123,3 @@ var2: 'default2',

var3: 'val3',
route: "pages/:var1/:var2/:var3"
route: "pages/{var1}/{var2}/{var3}"
});

@@ -104,2 +144,48 @@ });

canRoute.routes = {};
canRoute("pages/{page}", {
page: "index"
})
var res = canRoute.param({
page: "foo"
});
equal(res, "pages/foo")
res = canRoute.param({
page: "foo",
index: "bar"
});
equal(res, "pages/foo&index=bar")
canRoute("pages/{page}/{foo}", {
page: "index",
foo: "bar"
})
res = canRoute.param({
page: "foo",
foo: "bar",
where: "there"
});
equal(res, "pages/foo/&where=there")
// There is no matching route so the hash should be empty.
res = canRoute.param({});
equal(res, "")
canRoute.routes = {};
res = canRoute.param({
page: "foo",
bar: "baz",
where: "there"
});
equal(res, "&page=foo&bar=baz&where=there")
res = canRoute.param({});
equal(res, "")
});
test("param - `:page` syntax", function () {
canRoute.routes = {};
canRoute("pages/:page", {

@@ -168,3 +254,3 @@ page: "index"

canRoute.routes = {};
canRoute(":page", {
canRoute("{page}", {
page: "index"

@@ -178,3 +264,3 @@ })

canRoute("pages/:p1/:p2/:p3", {
canRoute("pages/{p1}/{p2}/{p3}", {
p1: "index",

@@ -203,3 +289,3 @@ p2: "foo",

canRoute("pages/:p1", {
canRoute("pages/{p1}", {
p2: "foo"

@@ -216,3 +302,3 @@ })

canRoute(":page/:type", {
canRoute("{page}/{type}", {
page: "index",

@@ -277,3 +363,3 @@ type: "foo"

canRoute.routes = {};
canRoute(":foo/:bar", {
canRoute("{foo}/{bar}", {
foo: 1,

@@ -292,3 +378,3 @@ bar: 2

bar: 2,
route: ":foo/:bar"
route: "{foo}/{bar}"
})

@@ -299,6 +385,6 @@ })

canRoute.routes = {};
canRoute(":who", {
canRoute("{who}", {
who: "index"
});
canRoute("search/:search");
canRoute("search/{search}");

@@ -308,3 +394,3 @@ var obj = canRoute.deparam("can.Control");

who: "can.Control",
route: ":who"
route: "{who}"
});

@@ -315,3 +401,3 @@

search: "can.Control",
route: "search/:search"
route: "search/{search}"
}, "bad deparam");

@@ -332,6 +418,6 @@

canRoute.routes = {};
canRoute(":type", {
canRoute("{type}", {
who: "index"
});
canRoute(":type/:id");
canRoute("{type}/{id}");

@@ -347,3 +433,3 @@ equal(canRoute.param({

canRoute.routes = {};
canRoute(":foo");
canRoute("{foo}");
var res = canRoute.link("Hello", {

@@ -385,3 +471,3 @@ foo: "bar",

canRoute.routes = {};
canRoute(":type/:id");
canRoute("{type}/{id}");
var res = canRoute.deparam("foo/" + encodeURIComponent("\/"))

@@ -399,3 +485,3 @@ equal(res.id, "\/")

canRoute.routes = {};
canRoute(":who");
canRoute("{who}");
canRoute("", {

@@ -414,4 +500,4 @@ foo: "bar"

canRoute.routes = {};
canRoute(":foo");
canRoute(":bar")
canRoute("{foo}");
canRoute("{bar}")

@@ -421,3 +507,3 @@ var obj = canRoute.deparam("abc");

foo: "abc",
route: ":foo"
route: "{foo}"
});

@@ -431,3 +517,3 @@ });

});
canRoute("something/:bar");
canRoute("something/{bar}");
var res = canRoute.param({

@@ -441,3 +527,3 @@ bar: "foo"

canRoute(":recipe", {
canRoute("{recipe}", {
recipe: "recipe1",

@@ -447,3 +533,3 @@ task: "task3"

canRoute(":recipe/:task", {
canRoute("{recipe}/{task}", {
recipe: "recipe1",

@@ -469,3 +555,3 @@ task: "task3"

canRoute.routes = {};
canRoute(":foo-:bar");
canRoute("{foo}-{bar}");

@@ -476,3 +562,3 @@ var obj = canRoute.deparam("abc-def");

bar: "def",
route: ":foo-:bar"
route: "{foo}-{bar}"
});

@@ -535,3 +621,3 @@

iCanRoute("", {});
iCanRoute.bind('change', function(){
iCanRoute.matched.bind('change', function(){
ok(true, 'change triggered once')

@@ -579,3 +665,3 @@ start();

iCanRoute(":type/:id");
iCanRoute("{type}/{id}");
var AppState = Map.extend();

@@ -605,3 +691,3 @@ var appState = new AppState({type: "dog", id: '4'});

iCanRoute(":type/:id");
iCanRoute("{type}/{id}");
var AppState = win.CanMap.extend();

@@ -635,3 +721,3 @@ var appState = new AppState({section: 'home'});

iCanRoute.ready();
iCanRoute(":type/:id");
iCanRoute("{type}/{id}");
iCanRoute.attr({

@@ -677,4 +763,4 @@ type: "bar",

iCanRoute.ready();
iCanRoute(":type");
iCanRoute(":type/:id");
iCanRoute("{type}");
iCanRoute("{type}/{id}");
iCanRoute.attr({

@@ -836,3 +922,3 @@ type: "bar"

iCanRoute.ready();
iCanRoute(":path");
iCanRoute("{path}");

@@ -875,3 +961,3 @@ iCanRoute.attr('path', 'foo');

canRoute.routes = {};
canRoute(":page\\.html", {
canRoute("{page}\\.html", {
page: "index"

@@ -883,3 +969,3 @@ });

page: "can.Control",
route: ":page\\.html"
route: "{page}\\.html"
});

@@ -949,3 +1035,3 @@

route.routes = {};
route(":type/:id");
route("{type}/{id}");

@@ -1000,4 +1086,23 @@ route.attr({

test("matched() compute", function() {
stop();
var AppState = Map.extend();
var appState = new AppState();
canRoute.data = appState;
canRoute("{type}", { type: "foo" });
canRoute("{type}/{subtype}");
canRoute.ready();
equal(appState.attr("route"), undefined, "should not set route on appState");
equal(canRoute.matched(), "{type}", "should set route.matched property");
appState.attr("subtype", "bar");
setTimeout(function() {
equal(canRoute.matched(), "{type}/{subtype}", "should update route.matched property");
start();
}, 200);
});
}
require("./route-test");
require("./route-curlies-syntax-test");
require("./route-define-test");
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc