Skip to content

Commit

Permalink
Fix exception if bootstrap non-existent store
Browse files Browse the repository at this point in the history
Prevent exception if trying to bootstrap with non-existent store.
  • Loading branch information
bkniffler authored and goatslacker committed Mar 19, 2015
1 parent 175cbf9 commit b458450
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 22 deletions.
21 changes: 16 additions & 5 deletions dist/alt-browser-with-addons.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(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){
"use strict";

/**
* This mixin lets you setup your listeners. It is similar to Fluxible's mixin.
*
Expand Down Expand Up @@ -79,6 +80,7 @@ module.exports = FluxyMixin;

},{"./Subscribe":4}],2:[function(require,module,exports){
"use strict";

var Subscribe = require("./Subscribe");

var ListenerMixin = {
Expand Down Expand Up @@ -109,6 +111,7 @@ module.exports = ListenerMixin;

},{"./Subscribe":4}],3:[function(require,module,exports){
"use strict";

/**
* This mixin automatically sets the state for you based on the key you provide
*
Expand Down Expand Up @@ -190,6 +193,7 @@ module.exports = ReactStateMagicMixin;

},{"./Subscribe":4}],4:[function(require,module,exports){
"use strict";

var Symbol = require("es-symbol");
var MIXIN_REGISTRY = Symbol("alt store listeners");

Expand Down Expand Up @@ -1241,11 +1245,13 @@ var setAppState = function (instance, data, onStore) {
var obj = JSON.parse(data);
Object.keys(obj).forEach(function (key) {
var store = instance.stores[key];
if (store[LIFECYCLE].deserialize) {
obj[key] = store[LIFECYCLE].deserialize(obj[key]) || obj[key];
if (store) {
if (store[LIFECYCLE].deserialize) {
obj[key] = store[LIFECYCLE].deserialize(obj[key]) || obj[key];
}
assign(store[STATE_CONTAINER], obj[key]);
onStore(store);
}
assign(store[STATE_CONTAINER], obj[key]);
onStore(store);
});
};

Expand Down Expand Up @@ -1422,7 +1428,9 @@ var Alt = (function () {
}

return this.createActions(function () {
this.generateActions.apply(this, actionNames);
var _ref;

(_ref = this).generateActions.apply(_ref, actionNames);
});
}
},
Expand Down Expand Up @@ -1574,6 +1582,7 @@ module.exports = Alt;

},{"es-symbol":5,"eventemitter3":6,"flux":7,"object-assign":10}],13:[function(require,module,exports){
"use strict";

/**
* ActionListeners(alt: AltInstance): ActionListenersInstance
*
Expand Down Expand Up @@ -1636,6 +1645,7 @@ ActionListeners.prototype.removeAllActionListeners = function () {

},{"es-symbol":5}],14:[function(require,module,exports){
"use strict";

/**
* DispatcherRecorder(alt: AltInstance): DispatcherInstance
*
Expand Down Expand Up @@ -1738,6 +1748,7 @@ DispatcherRecorder.prototype.replay = function (replayTime, done) {

},{}],15:[function(require,module,exports){
"use strict";

/**
* makeFinalStore(alt: AltInstance): AltStore
*
Expand Down
14 changes: 9 additions & 5 deletions dist/alt-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -989,11 +989,13 @@ var setAppState = function (instance, data, onStore) {
var obj = JSON.parse(data);
Object.keys(obj).forEach(function (key) {
var store = instance.stores[key];
if (store[LIFECYCLE].deserialize) {
obj[key] = store[LIFECYCLE].deserialize(obj[key]) || obj[key];
if (store) {
if (store[LIFECYCLE].deserialize) {
obj[key] = store[LIFECYCLE].deserialize(obj[key]) || obj[key];
}
assign(store[STATE_CONTAINER], obj[key]);
onStore(store);
}
assign(store[STATE_CONTAINER], obj[key]);
onStore(store);
});
};

Expand Down Expand Up @@ -1170,7 +1172,9 @@ var Alt = (function () {
}

return this.createActions(function () {
this.generateActions.apply(this, actionNames);
var _ref;

(_ref = this).generateActions.apply(_ref, actionNames);
});
}
},
Expand Down
10 changes: 6 additions & 4 deletions dist/alt-with-runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,13 @@ var setAppState = function (instance, data, onStore) {
var obj = JSON.parse(data);
Object.keys(obj).forEach(function (key) {
var store = instance.stores[key];
if (store[LIFECYCLE].deserialize) {
obj[key] = store[LIFECYCLE].deserialize(obj[key]) || obj[key];
if (store) {
if (store[LIFECYCLE].deserialize) {
obj[key] = store[LIFECYCLE].deserialize(obj[key]) || obj[key];
}
assign(store[STATE_CONTAINER], obj[key]);
onStore(store);
}
assign(store[STATE_CONTAINER], obj[key]);
onStore(store);
});
};

Expand Down
10 changes: 6 additions & 4 deletions dist/alt.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,13 @@ var setAppState = function (instance, data, onStore) {
var obj = JSON.parse(data);
Object.keys(obj).forEach(function (key) {
var store = instance.stores[key];
if (store[LIFECYCLE].deserialize) {
obj[key] = store[LIFECYCLE].deserialize(obj[key]) || obj[key];
if (store) {
if (store[LIFECYCLE].deserialize) {
obj[key] = store[LIFECYCLE].deserialize(obj[key]) || obj[key];
}
assign(store[STATE_CONTAINER], obj[key]);
onStore(store);
}
assign(store[STATE_CONTAINER], obj[key]);
onStore(store);
});
};

Expand Down
10 changes: 6 additions & 4 deletions src/alt.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,13 @@ const setAppState = (instance, data, onStore) => {
const obj = JSON.parse(data)
Object.keys(obj).forEach((key) => {
const store = instance.stores[key]
if (store[LIFECYCLE].deserialize) {
obj[key] = store[LIFECYCLE].deserialize(obj[key]) || obj[key]
if (store) {
if (store[LIFECYCLE].deserialize) {
obj[key] = store[LIFECYCLE].deserialize(obj[key]) || obj[key]
}
assign(store[STATE_CONTAINER], obj[key])
onStore(store)
}
assign(store[STATE_CONTAINER], obj[key])
onStore(store)
})
}

Expand Down
6 changes: 6 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,12 @@ const tests = {

assert.isFunction(actions.foo, 'action still exists')
},

'recycle store that does not exist'() {
assert.doesNotThrow(() => {
alt.bootstrap('{"AStoreThatIJustMadeUpButDoesNotReallyExist": {}}')
})
},
}

export default tests

0 comments on commit b458450

Please sign in to comment.