can-route
Advanced tools
Comparing version 3.0.0-pre.3 to 3.0.0-pre.4
@@ -75,3 +75,21 @@ /*jshint -W079 */ | ||
}; | ||
var attrHelper = function (prop, value) { | ||
if("attr" in this) { | ||
return this.attr.apply(this, arguments); | ||
} else { | ||
if(arguments.length > 1) { | ||
this.set(prop, value); | ||
return this; | ||
} else if(typeof prop === 'object') { | ||
this.set(prop); | ||
return this; | ||
} else if(arguments.length === 1){ | ||
return this.get(prop); | ||
} else { | ||
return this.toObject(); | ||
} | ||
} | ||
}; | ||
// Helper for convert any object (or value) to stringified object (or value) | ||
@@ -231,3 +249,3 @@ var stringify = function (obj) { | ||
else if(Object.prototype.toString.call(old[attr]) === "[object Object]") { | ||
recursiveClean( old[attr], cur[attr], data.attr(attr) ); | ||
recursiveClean( old[attr], cur[attr], attrHelper.call(data,attr) ); | ||
} | ||
@@ -725,5 +743,3 @@ } | ||
},{ | ||
"*": { | ||
type: "string" | ||
} | ||
"*": "stringOrObservable" | ||
}); | ||
@@ -753,19 +769,6 @@ return setRouteData(new DefaultRouteMap()); | ||
canRoute.attr = function (prop, value) { | ||
if("attr" in canRoute.data) { | ||
return canRoute.data.attr.apply(canRoute.data, arguments); | ||
} else { | ||
if(arguments.length > 1) { | ||
canRoute.data.set(prop, value); | ||
return canRoute.data; | ||
} else if(typeof prop === 'object') { | ||
canRoute.data.set(prop); | ||
return canRoute.data; | ||
} else if(arguments.length === 1){ | ||
return canRoute.data.get(prop); | ||
} else { | ||
return canRoute.data.toObject(); | ||
} | ||
} | ||
canRoute.attr = function(){ | ||
return attrHelper.apply(canRoute.data,arguments); | ||
}; | ||
@@ -772,0 +775,0 @@ |
{ | ||
"name": "can-route", | ||
"version": "3.0.0-pre.3", | ||
"version": "3.0.0-pre.4", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "homepage": "", |
@@ -7,2 +7,3 @@ /* jshint asi:true */ | ||
var makeArray = require('can-util/js/make-array/make-array'); | ||
var mockRoute = require("./mock-route-binding"); | ||
@@ -578,6 +579,6 @@ require('can-observe-info'); | ||
test("canRoute.map: route is initialized from URL first, then URL params are added from canRoute.data", function(){ | ||
setupRouteTest(function (iframe, iCanRoute, loc) { | ||
setupRouteTest(function (iframe, iCanRoute, loc, win) { | ||
iCanRoute(":type/:id"); | ||
var AppState = DefineMap.extend({seal: false},{}); | ||
var AppState = win.DefineMap.extend({seal: false},{}); | ||
var appState = new AppState({section: 'home'}); | ||
@@ -749,4 +750,4 @@ | ||
setTimeout(function() { | ||
equal(iCanRoute.attr("panelA.id"), 20, "id should change"); | ||
equal(iCanRoute.attr("panelA.show"), undefined, "show should be removed"); | ||
equal(iCanRoute.data.panelA.id, 20, "id should change"); | ||
equal(iCanRoute.data.panelA.show, undefined, "show should be removed"); | ||
@@ -763,3 +764,3 @@ teardownRouteTest(); | ||
setupRouteTest(function (iframe, route) { | ||
var appVM = new DefineMap(); | ||
var appVM = new (DefineMap.extend({seal: false},{'*': "stringOrObservable"})); | ||
@@ -773,3 +774,3 @@ route.map(appVM); | ||
appVM.attr('action', 10); | ||
appVM.set('action', 10); | ||
@@ -787,5 +788,5 @@ // check after 30ms to see that we only have a single call | ||
setupRouteTest(function (iframe, route) { | ||
var appVM = new (DefineMap.extend({define: { | ||
action: {serialize: false} | ||
}}))(); | ||
var appVM = new (DefineMap.extend({ | ||
action: {serialize: false, type: "*"} | ||
}))(); | ||
@@ -799,3 +800,3 @@ route.map(appVM); | ||
appVM.attr('action', function() {}); | ||
appVM.set('action', function() {}); | ||
@@ -826,3 +827,3 @@ // check after 30ms to see that we only have a single call | ||
iCanRoute.bind("change", function() { | ||
iCanRoute.serializedCompute.bind("change", function() { | ||
counter++; | ||
@@ -961,16 +962,30 @@ }); | ||
test("two way binding canRoute.map with DefineMap instance", function(){ | ||
expect(1); | ||
var AppState = DefineMap.extend(); | ||
expect(2); | ||
stop(); | ||
mockRoute.start() | ||
var AppState = DefineMap.extend({seal: false},{"*": "stringOrObservable"}); | ||
var appState = new AppState(); | ||
canRoute.map(appState); | ||
canRoute.ready(); | ||
canRoute.on('change', function(){ | ||
canRoute.serializedCompute.bind('change', function(){ | ||
equal(canRoute.attr('name'), 'Brian', 'appState is bound to canRoute'); | ||
canRoute.off('change'); | ||
appState.removeAttr('name'); | ||
canRoute.serializedCompute.unbind('change'); | ||
appState.name = undefined; | ||
setTimeout(function(){ | ||
equal( mockRoute.hash(), "#"); | ||
mockRoute.stop(); | ||
start(); | ||
},20); | ||
}); | ||
appState.attr('name', 'Brian'); | ||
appState.set('name', 'Brian'); | ||
}); | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
72775
18
2374
0