Skip to content

Commit b458450

Browse files
bknifflergoatslacker
authored andcommitted
Fix exception if bootstrap non-existent store
Prevent exception if trying to bootstrap with non-existent store.
1 parent 175cbf9 commit b458450

File tree

6 files changed

+49
-22
lines changed

6 files changed

+49
-22
lines changed

dist/alt-browser-with-addons.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Alt = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
22
"use strict";
3+
34
/**
45
* This mixin lets you setup your listeners. It is similar to Fluxible's mixin.
56
*
@@ -79,6 +80,7 @@ module.exports = FluxyMixin;
7980

8081
},{"./Subscribe":4}],2:[function(require,module,exports){
8182
"use strict";
83+
8284
var Subscribe = require("./Subscribe");
8385

8486
var ListenerMixin = {
@@ -109,6 +111,7 @@ module.exports = ListenerMixin;
109111

110112
},{"./Subscribe":4}],3:[function(require,module,exports){
111113
"use strict";
114+
112115
/**
113116
* This mixin automatically sets the state for you based on the key you provide
114117
*
@@ -190,6 +193,7 @@ module.exports = ReactStateMagicMixin;
190193

191194
},{"./Subscribe":4}],4:[function(require,module,exports){
192195
"use strict";
196+
193197
var Symbol = require("es-symbol");
194198
var MIXIN_REGISTRY = Symbol("alt store listeners");
195199

@@ -1241,11 +1245,13 @@ var setAppState = function (instance, data, onStore) {
12411245
var obj = JSON.parse(data);
12421246
Object.keys(obj).forEach(function (key) {
12431247
var store = instance.stores[key];
1244-
if (store[LIFECYCLE].deserialize) {
1245-
obj[key] = store[LIFECYCLE].deserialize(obj[key]) || obj[key];
1248+
if (store) {
1249+
if (store[LIFECYCLE].deserialize) {
1250+
obj[key] = store[LIFECYCLE].deserialize(obj[key]) || obj[key];
1251+
}
1252+
assign(store[STATE_CONTAINER], obj[key]);
1253+
onStore(store);
12461254
}
1247-
assign(store[STATE_CONTAINER], obj[key]);
1248-
onStore(store);
12491255
});
12501256
};
12511257

@@ -1422,7 +1428,9 @@ var Alt = (function () {
14221428
}
14231429

14241430
return this.createActions(function () {
1425-
this.generateActions.apply(this, actionNames);
1431+
var _ref;
1432+
1433+
(_ref = this).generateActions.apply(_ref, actionNames);
14261434
});
14271435
}
14281436
},
@@ -1574,6 +1582,7 @@ module.exports = Alt;
15741582

15751583
},{"es-symbol":5,"eventemitter3":6,"flux":7,"object-assign":10}],13:[function(require,module,exports){
15761584
"use strict";
1585+
15771586
/**
15781587
* ActionListeners(alt: AltInstance): ActionListenersInstance
15791588
*
@@ -1636,6 +1645,7 @@ ActionListeners.prototype.removeAllActionListeners = function () {
16361645

16371646
},{"es-symbol":5}],14:[function(require,module,exports){
16381647
"use strict";
1648+
16391649
/**
16401650
* DispatcherRecorder(alt: AltInstance): DispatcherInstance
16411651
*
@@ -1738,6 +1748,7 @@ DispatcherRecorder.prototype.replay = function (replayTime, done) {
17381748

17391749
},{}],15:[function(require,module,exports){
17401750
"use strict";
1751+
17411752
/**
17421753
* makeFinalStore(alt: AltInstance): AltStore
17431754
*

dist/alt-browser.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -989,11 +989,13 @@ var setAppState = function (instance, data, onStore) {
989989
var obj = JSON.parse(data);
990990
Object.keys(obj).forEach(function (key) {
991991
var store = instance.stores[key];
992-
if (store[LIFECYCLE].deserialize) {
993-
obj[key] = store[LIFECYCLE].deserialize(obj[key]) || obj[key];
992+
if (store) {
993+
if (store[LIFECYCLE].deserialize) {
994+
obj[key] = store[LIFECYCLE].deserialize(obj[key]) || obj[key];
995+
}
996+
assign(store[STATE_CONTAINER], obj[key]);
997+
onStore(store);
994998
}
995-
assign(store[STATE_CONTAINER], obj[key]);
996-
onStore(store);
997999
});
9981000
};
9991001

@@ -1170,7 +1172,9 @@ var Alt = (function () {
11701172
}
11711173

11721174
return this.createActions(function () {
1173-
this.generateActions.apply(this, actionNames);
1175+
var _ref;
1176+
1177+
(_ref = this).generateActions.apply(_ref, actionNames);
11741178
});
11751179
}
11761180
},

dist/alt-with-runtime.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,13 @@ var setAppState = function (instance, data, onStore) {
244244
var obj = JSON.parse(data);
245245
Object.keys(obj).forEach(function (key) {
246246
var store = instance.stores[key];
247-
if (store[LIFECYCLE].deserialize) {
248-
obj[key] = store[LIFECYCLE].deserialize(obj[key]) || obj[key];
247+
if (store) {
248+
if (store[LIFECYCLE].deserialize) {
249+
obj[key] = store[LIFECYCLE].deserialize(obj[key]) || obj[key];
250+
}
251+
assign(store[STATE_CONTAINER], obj[key]);
252+
onStore(store);
249253
}
250-
assign(store[STATE_CONTAINER], obj[key]);
251-
onStore(store);
252254
});
253255
};
254256

dist/alt.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,11 +258,13 @@ var setAppState = function (instance, data, onStore) {
258258
var obj = JSON.parse(data);
259259
Object.keys(obj).forEach(function (key) {
260260
var store = instance.stores[key];
261-
if (store[LIFECYCLE].deserialize) {
262-
obj[key] = store[LIFECYCLE].deserialize(obj[key]) || obj[key];
261+
if (store) {
262+
if (store[LIFECYCLE].deserialize) {
263+
obj[key] = store[LIFECYCLE].deserialize(obj[key]) || obj[key];
264+
}
265+
assign(store[STATE_CONTAINER], obj[key]);
266+
onStore(store);
263267
}
264-
assign(store[STATE_CONTAINER], obj[key]);
265-
onStore(store);
266268
});
267269
};
268270

src/alt.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,13 @@ const setAppState = (instance, data, onStore) => {
227227
const obj = JSON.parse(data)
228228
Object.keys(obj).forEach((key) => {
229229
const store = instance.stores[key]
230-
if (store[LIFECYCLE].deserialize) {
231-
obj[key] = store[LIFECYCLE].deserialize(obj[key]) || obj[key]
230+
if (store) {
231+
if (store[LIFECYCLE].deserialize) {
232+
obj[key] = store[LIFECYCLE].deserialize(obj[key]) || obj[key]
233+
}
234+
assign(store[STATE_CONTAINER], obj[key])
235+
onStore(store)
232236
}
233-
assign(store[STATE_CONTAINER], obj[key])
234-
onStore(store)
235237
})
236238
}
237239

test/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,6 +1195,12 @@ const tests = {
11951195

11961196
assert.isFunction(actions.foo, 'action still exists')
11971197
},
1198+
1199+
'recycle store that does not exist'() {
1200+
assert.doesNotThrow(() => {
1201+
alt.bootstrap('{"AStoreThatIJustMadeUpButDoesNotReallyExist": {}}')
1202+
})
1203+
},
11981204
}
11991205

12001206
export default tests

0 commit comments

Comments
 (0)