Skip to content

Commit 816332e

Browse files
check if props exist before running connection.id (#516)
* Do not call connection.id if props does not exist * Add test for no props passed to new DefineMap * Use can-reflect to ensure map-like props during constructor hydrate Co-authored-by: Bradley Momberger <[email protected]>
1 parent 30ef907 commit 816332e

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

can/constructor-hydrate/constructor-hydrate-test.js

+20
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,23 @@ QUnit.test("Two objects with no id", function(assert) {
5454
new Hub({name: 'One'});
5555
assert.ok(true, 'Should allow to create two instances without an id (no Max Call Stack error)');
5656
});
57+
58+
QUnit.test("No Props passed to new DefineMap, doesn't blow up", function(assert) {
59+
var Hub = DefineMap.extend({});
60+
Hub.List = DefineList.extend({
61+
'#': { Type: Hub }
62+
});
63+
var HubConnection = connect([
64+
constructorBehavior,
65+
constructorStore,
66+
mapBehavior,
67+
hydrateBehavior,
68+
], { Map: Hub, List: Hub.List });
69+
70+
var hub1 = new Hub();
71+
hub1.name = 'One';
72+
HubConnection.addInstanceReference(hub1);
73+
assert.ok(!HubConnection.instanceStore.has(undefined), 'The instanceStore should not have an "undefined" key item');
74+
new Hub({name: 'One'});
75+
assert.ok(true, 'Should allow to create two instances without an id (no Max Call Stack error)');
76+
});

can/constructor-hydrate/constructor-hydrate.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,19 @@
9595

9696
var connect = require("../../can-connect");
9797
var Construct = require("can-construct");
98+
var canReflect = require("can-reflect");
9899

99100
var constructorHydrateBehavior = connect.behavior("can-connect/can/construct-hydrate", function(baseConnect){
100101
return {
101102
init: function(){
102103
var oldSetup = this.Map.prototype.setup;
103104
var connection = this;
104105
this.Map.prototype.setup = function(props){
105-
if (connection.instanceStore.has( connection.id(props) )) {
106-
return new Construct.ReturnValue( connection.hydrateInstance(props) );
106+
if (
107+
canReflect.isMapLike(props) &&
108+
connection.instanceStore.has(connection.id(props))
109+
) {
110+
return new Construct.ReturnValue(connection.hydrateInstance(props));
107111
}
108112
return oldSetup.apply(this, arguments);
109113
};

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"steal-qunit": "^2.0.0",
5151
"steal-tools": "^1.0.0",
5252
"test-saucelabs": "^0.0.6",
53-
"testee": "^0.9.0"
53+
"testee": "^0.10.2"
5454
},
5555
"steal": {
5656
"plugins": [

test/test-saucelabs.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,6 @@ SauceLabs({
4646
url: "http://localhost:3000/test/test.html?hidepassed",
4747
platforms: platforms
4848
}],
49-
runInSeries: true,
49+
runInParallel: false,
5050
zeroAssertionsPass: false
5151
});

0 commit comments

Comments
 (0)