can-route
Advanced tools
Comparing version 4.3.12 to 4.4.0
@@ -12,3 +12,4 @@ "use strict"; | ||
var makeCompute = require("can-simple-observable/make-compute/make-compute"); | ||
var SimpleMap = require("can-simple-map"); | ||
var RouteData = require("./src/routedata"); | ||
var stringCoercingMapDecorator = require("./src/string-coercion").stringCoercingMapDecorator; | ||
@@ -327,50 +328,3 @@ var registerRoute = require("./src/register"); | ||
}); | ||
// Helper for convert any object (or value) to stringified object (or value) | ||
var stringify = function (obj) { | ||
// Object is array, plain object, Map or List | ||
if (obj && typeof obj === "object") { | ||
if (obj && typeof obj === "object" && ("serialize" in obj)) { | ||
obj = obj.serialize(); | ||
} else { | ||
// Get array from array-like or shallow-copy object | ||
obj = typeof obj.slice === "function" ? obj.slice() : canReflect.assign({}, obj); | ||
} | ||
// Convert each object property or array item into stringified new | ||
canReflect.eachKey(obj, function (val, prop) { | ||
obj[prop] = stringify(val); | ||
}); | ||
// Object supports toString function | ||
} else if (obj !== undefined && obj !== null && (typeof obj.toString === "function" )) { | ||
obj = obj.toString(); | ||
} | ||
return obj; | ||
}; | ||
// everything in the backing Map is a string | ||
// add type coercion during Map setter to coerce all values to strings so unexpected conflicts don't happen. | ||
// https://github.com/canjs/canjs/issues/2206 | ||
var stringCoercingMapDecorator = function(map) { | ||
var sym = canSymbol.for("can.route.stringCoercingMapDecorator"); | ||
if(!map.attr[sym]) { | ||
var attrSuper = map.attr; | ||
map.attr = function(prop, val) { | ||
var serializable = typeof prop === "string" && | ||
(this.define === undefined || this.define[prop] === undefined || !!this.define[prop].serialize), | ||
args; | ||
if (serializable) { // if setting non-str non-num attr | ||
args = stringify(Array.apply(null, arguments)); | ||
} else { | ||
args = arguments; | ||
} | ||
return attrSuper.apply(this, args); | ||
}; | ||
canReflect.setKeyValue(map.attr, sym, true); | ||
} | ||
return map; | ||
}; | ||
var viewModelSymbol = canSymbol.for("can.viewModel"); | ||
@@ -382,3 +336,3 @@ Object.defineProperty(canRoute,"data", { | ||
} else { | ||
return setRouteData( stringCoercingMapDecorator( new SimpleMap() ) ); | ||
return setRouteData(new RouteData()); | ||
} | ||
@@ -385,0 +339,0 @@ }, |
{ | ||
"name": "can-route", | ||
"version": "4.3.12", | ||
"version": "4.4.0", | ||
"description": "Observable front-end application routing for CanJS.", | ||
@@ -17,2 +17,3 @@ "homepage": "https://canjs.com/doc/can-route.html", | ||
"scripts": { | ||
"ci": "npm run test && node test/test-saucelabs.js", | ||
"preversion": "npm test", | ||
@@ -23,2 +24,3 @@ "postpublish": "git push --tags && git push", | ||
"jshint": "jshint ./*.js src/*.js test/*.js --config", | ||
"http-server": "http-server -p 3000 --silent", | ||
"release:pre": "npm version prerelease && npm publish --tag pre", | ||
@@ -53,3 +55,2 @@ "release:patch": "npm version patch && npm publish", | ||
"can-route-hash": "<2.0.0", | ||
"can-simple-map": "^4.0.0", | ||
"can-simple-observable": "^2.0.0", | ||
@@ -60,6 +61,7 @@ "can-string": "<2.0.0", | ||
"devDependencies": { | ||
"can-define": "^2.0.0", | ||
"can-define": "^2.6.0", | ||
"can-map": "^4.0.0", | ||
"can-observe": "^2.0.0", | ||
"can-route-mock": "<2.0.0", | ||
"can-simple-map": "^4.0.0", | ||
"can-stache-key": "^1.0.0", | ||
@@ -69,2 +71,3 @@ "can-test-helpers": "^1.1.2", | ||
"done-serve": "^2.0.0", | ||
"http-server": "^0.11.1", | ||
"jshint": "^2.9.1", | ||
@@ -74,4 +77,5 @@ "steal": "^2.0.0", | ||
"steal-tools": "^1.1.2", | ||
"test-saucelabs": "0.0.6", | ||
"testee": "^0.8.0" | ||
} | ||
} |
@@ -12,2 +12,3 @@ "use strict"; | ||
var diffObject = require('can-diff/map/map'); | ||
var RouteData = require("./routedata"); | ||
// `RegExp` used to match route variables of the type '{name}'. | ||
@@ -99,2 +100,21 @@ // Any word character or a period is matched. | ||
} | ||
// Assign to the instance props | ||
if(this.data instanceof RouteData) { | ||
var routeData = this.data; | ||
canReflect.eachIndex(names, function(name) { | ||
var type = "string"; | ||
var defaultValue = defaults[name]; | ||
var typeOf = typeof defaultValue; | ||
if(defaultValue != null) { | ||
type = typeOf; | ||
} | ||
canReflect.defineInstanceKey(routeData.constructor, name, { | ||
type: type | ||
}); | ||
}); | ||
} | ||
//!steal-remove-end | ||
@@ -101,0 +121,0 @@ // Add route in a form that can be easily figured out. |
var canRoute = require("can-route"); | ||
var SimpleMap = require("can-simple-map"); | ||
var RouteData = require("../src/routedata"); | ||
@@ -16,3 +16,3 @@ var RouteMock = require("can-route-mock"); | ||
this.hash.value = ""; | ||
canRoute.data = new SimpleMap(); | ||
canRoute.data = new RouteData(); | ||
//canRoute._setup(); | ||
@@ -25,3 +25,3 @@ }, | ||
this.hash = new RouteMock(); | ||
canRoute.data = new SimpleMap(); | ||
canRoute.data = new RouteData(); | ||
//canRoute.bindings.mock.unbind(); | ||
@@ -28,0 +28,0 @@ //canRoute._setup(); |
@@ -5,2 +5,3 @@ var canRoute = require('can-route'); | ||
var canSymbol = require("can-symbol"); | ||
var mockRoute = require("./mock-route-binding"); | ||
@@ -29,1 +30,39 @@ require('can-observation'); | ||
}); | ||
QUnit.asyncTest("Default map registers properties", function(){ | ||
mockRoute.start(); | ||
canRoute.register("{type}/{id}"); | ||
canRoute._onStartComplete = function () { | ||
var after = mockRoute.hash.get(); | ||
equal(after, "cat/5", "same URL"); | ||
equal(canRoute.data.type, "cat", "conflicts should be won by the URL"); | ||
equal(canRoute.data.id, "5", "conflicts should be won by the URL"); | ||
QUnit.start(); | ||
mockRoute.stop(); | ||
}; | ||
mockRoute.hash.value = "#!cat/5"; | ||
canRoute.start(); | ||
}); | ||
QUnit.asyncTest("Property defaults influence the Type", function(){ | ||
mockRoute.start(); | ||
canRoute.register("{type}/{id}/{more}", { type: "dog", "id": 14, more: null }); | ||
canRoute._onStartComplete = function () { | ||
var after = mockRoute.hash.get(); | ||
equal(after, "cat/7/stuff", "same URL"); | ||
equal(canRoute.data.type, "cat", "conflicts should be won by the URL"); | ||
deepEqual(canRoute.data.id, 7, "conflicts should be won by the URL"); | ||
deepEqual(canRoute.data.more, "stuff", "null defaults are converted"); | ||
QUnit.start(); | ||
mockRoute.stop(); | ||
}; | ||
mockRoute.hash.value = "#!cat/7/stuff"; | ||
canRoute.start(); | ||
}); |
Sorry, the diff of this file is not supported yet
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
112641
18
44
2615
16
- Removedcan-simple-map@^4.0.0
- Removedcan-construct@3.5.7(transitive)
- Removedcan-simple-map@4.3.3(transitive)