Skip to content

Commit

Permalink
commit dist
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Gran committed Jun 2, 2016
1 parent 0e059b3 commit 8759bb7
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions dist/MobStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var stores = [];
var $stores = {};
var $inject = Symbol('inject');
var $pushOrMerge = Symbol('pushOrMerge');

/**
* Base class for making observable datastores.
Expand Down Expand Up @@ -56,6 +58,10 @@ var MobStore = function () {

_classCallCheck(this, MobStore);

if (undefined !== $stores[type]) {
throw new Error('It is not allowed to create duplicate MobStore instances. Only create one per `type`');
}

this.collectionName = collectionName;

/// TODO reject/throw if type by this name already exists.
Expand All @@ -76,7 +82,7 @@ var MobStore = function () {

this.injectCallbackCache = [];

stores.push(this);
$stores[type] = this;
}

_createClass(MobStore, [{
Expand All @@ -86,10 +92,13 @@ var MobStore = function () {
/**
* Inject JSON data into this store.
* @param {Object|Object[]} jsondata - A single instance or an array of instances to inject into this store.
* @param {number} level - internal use only
* @param {function[]} callbackFns - internal use only
*/
value: function inject(jsondata) {
return this[$inject](jsondata);
}
}, {
key: $inject,
value: function value(jsondata) {
var _this = this;

var level = arguments.length <= 1 || arguments[1] === undefined ? 0 : arguments[1];
Expand All @@ -99,10 +108,10 @@ var MobStore = function () {

return (0, _mobx.transaction)(function () {
var instances = objs.map(function (obj) {
var _pushOrMerge = _this.pushOrMerge(obj);
var _$pushOrMerge = _this[$pushOrMerge](obj);

var instance = _pushOrMerge.instance;
var callbacks = _pushOrMerge.callbacks;
var instance = _$pushOrMerge.instance;
var callbacks = _$pushOrMerge.callbacks;

MobStore.merge(callbackFns, callbacks);
var associatedObjects = _this.type.associatedObjectsFor(obj);
Expand All @@ -116,7 +125,7 @@ var MobStore = function () {
if (assocStore) {
var aInstances = undefined;
if (value) {
var result = assocStore.inject(value, level + 1, callbackFns);
var result = assocStore[$inject](value, level + 1, callbackFns);
aInstances = result.instances;
callbackFns = result.callbackFns;
}
Expand All @@ -143,8 +152,8 @@ var MobStore = function () {
});
}
}, {
key: 'pushOrMerge',
value: function pushOrMerge(object) {
key: $pushOrMerge,
value: function value(object) {
var callbacks = [];
var instance = this.find(object.id);
if (instance && Object.keys(instance).length > 0) {
Expand Down Expand Up @@ -242,14 +251,12 @@ var MobStore = function () {
}, {
key: 'storeForType',
value: function storeForType(typeName) {
return stores.find(function (s) {
return s.type.name == typeName;
});
return $stores[typeName];
}
}, {
key: 'clearStores',
value: function clearStores() {
stores = [];
$stores = {};
}

// fast way to merge two arrays, per https://jsperf.com/array-prototype-push-apply-vs-concat/5
Expand Down

0 comments on commit 8759bb7

Please sign in to comment.