Skip to content

Commit

Permalink
Add store instance properties
Browse files Browse the repository at this point in the history
  • Loading branch information
goatslacker committed Mar 20, 2015
1 parent 984cd99 commit e76ae26
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 40 deletions.
20 changes: 12 additions & 8 deletions dist/alt-browser-with-addons.js
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,7 @@ var assign = _interopRequire(require("object-assign"));
var ACTION_HANDLER = Symbol("action creator handler");
var ACTION_KEY = Symbol("holds the actions uid symbol for listening");
var ACTION_UID = Symbol("the actions uid name");
var ALL_LISTENERS = Symbol("name of listeners");
var EE = Symbol("event emitter instance");
var INIT_SNAPSHOT = Symbol("init snapshot storage");
var LAST_SNAPSHOT = Symbol("last snapshot storage");
Expand Down Expand Up @@ -1047,7 +1048,7 @@ var getInternalMethods = function (obj, excluded) {
};

var AltStore = (function () {
function AltStore(dispatcher, model, state) {
function AltStore(dispatcher, model, state, StoreModel) {
var _this8 = this;

_classCallCheck(this, AltStore);
Expand All @@ -1056,6 +1057,9 @@ var AltStore = (function () {
this[LIFECYCLE] = {};
this[STATE_CONTAINER] = state || model;

this.listenerNames = model[ALL_LISTENERS];
this.StoreModel = typeof StoreModel === "function" ? StoreModel : assign({}, StoreModel);

assign(this[LIFECYCLE], model[LIFECYCLE]);
assign(this, model[PUBLIC_METHODS]);

Expand Down Expand Up @@ -1145,11 +1149,9 @@ var StoreMixinListeners = {
}

// You can pass in the constant or the function itself
if (symbol[ACTION_KEY]) {
this[LISTENERS][symbol[ACTION_KEY]] = handler.bind(this);
} else {
this[LISTENERS][symbol] = handler.bind(this);
}
var key = symbol[ACTION_KEY] ? symbol[ACTION_KEY] : symbol;
this[LISTENERS][key] = handler.bind(this);
this[ALL_LISTENERS].push(Symbol.keyFor(key));
},

bindActions: function bindActions(actions) {
Expand Down Expand Up @@ -1291,6 +1293,7 @@ var createStoreFromObject = function (alt, StoreModel, key, saveStore) {
var storeInstance = undefined;

var StoreProto = {};
StoreProto[ALL_LISTENERS] = [];
StoreProto[LIFECYCLE] = {};
StoreProto[LISTENERS] = {};

Expand Down Expand Up @@ -1325,7 +1328,7 @@ var createStoreFromObject = function (alt, StoreModel, key, saveStore) {
}

// create the instance and assign the public methods to the instance
storeInstance = assign(new AltStore(alt.dispatcher, StoreProto, StoreProto.state), StoreProto.publicMethods);
storeInstance = assign(new AltStore(alt.dispatcher, StoreProto, StoreProto.state, StoreModel), StoreProto.publicMethods);

/* istanbul ignore else */
if (saveStore) {
Expand Down Expand Up @@ -1408,13 +1411,14 @@ var Alt = (function () {
}
});

Store.prototype[ALL_LISTENERS] = [];
Store.prototype[LIFECYCLE] = {};
Store.prototype[LISTENERS] = {};
Store.prototype[PUBLIC_METHODS] = {};

var store = new Store(this);

storeInstance = assign(new AltStore(this.dispatcher, store), getInternalMethods(StoreModel, builtIns));
storeInstance = assign(new AltStore(this.dispatcher, store, null, StoreModel), getInternalMethods(StoreModel, builtIns));

if (saveStore) {
this.stores[key] = storeInstance;
Expand Down
20 changes: 12 additions & 8 deletions dist/alt-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,7 @@ var assign = _interopRequire(require("object-assign"));
var ACTION_HANDLER = Symbol("action creator handler");
var ACTION_KEY = Symbol("holds the actions uid symbol for listening");
var ACTION_UID = Symbol("the actions uid name");
var ALL_LISTENERS = Symbol("name of listeners");
var EE = Symbol("event emitter instance");
var INIT_SNAPSHOT = Symbol("init snapshot storage");
var LAST_SNAPSHOT = Symbol("last snapshot storage");
Expand Down Expand Up @@ -795,7 +796,7 @@ var getInternalMethods = function (obj, excluded) {
};

var AltStore = (function () {
function AltStore(dispatcher, model, state) {
function AltStore(dispatcher, model, state, StoreModel) {
var _this8 = this;

_classCallCheck(this, AltStore);
Expand All @@ -804,6 +805,9 @@ var AltStore = (function () {
this[LIFECYCLE] = {};
this[STATE_CONTAINER] = state || model;

this.listenerNames = model[ALL_LISTENERS];
this.StoreModel = typeof StoreModel === "function" ? StoreModel : assign({}, StoreModel);

assign(this[LIFECYCLE], model[LIFECYCLE]);
assign(this, model[PUBLIC_METHODS]);

Expand Down Expand Up @@ -893,11 +897,9 @@ var StoreMixinListeners = {
}

// You can pass in the constant or the function itself
if (symbol[ACTION_KEY]) {
this[LISTENERS][symbol[ACTION_KEY]] = handler.bind(this);
} else {
this[LISTENERS][symbol] = handler.bind(this);
}
var key = symbol[ACTION_KEY] ? symbol[ACTION_KEY] : symbol;
this[LISTENERS][key] = handler.bind(this);
this[ALL_LISTENERS].push(Symbol.keyFor(key));
},

bindActions: function bindActions(actions) {
Expand Down Expand Up @@ -1039,6 +1041,7 @@ var createStoreFromObject = function (alt, StoreModel, key, saveStore) {
var storeInstance = undefined;

var StoreProto = {};
StoreProto[ALL_LISTENERS] = [];
StoreProto[LIFECYCLE] = {};
StoreProto[LISTENERS] = {};

Expand Down Expand Up @@ -1073,7 +1076,7 @@ var createStoreFromObject = function (alt, StoreModel, key, saveStore) {
}

// create the instance and assign the public methods to the instance
storeInstance = assign(new AltStore(alt.dispatcher, StoreProto, StoreProto.state), StoreProto.publicMethods);
storeInstance = assign(new AltStore(alt.dispatcher, StoreProto, StoreProto.state, StoreModel), StoreProto.publicMethods);

/* istanbul ignore else */
if (saveStore) {
Expand Down Expand Up @@ -1156,13 +1159,14 @@ var Alt = (function () {
}
});

Store.prototype[ALL_LISTENERS] = [];
Store.prototype[LIFECYCLE] = {};
Store.prototype[LISTENERS] = {};
Store.prototype[PUBLIC_METHODS] = {};

var store = new Store(this);

storeInstance = assign(new AltStore(this.dispatcher, store), getInternalMethods(StoreModel, builtIns));
storeInstance = assign(new AltStore(this.dispatcher, store, null, StoreModel), getInternalMethods(StoreModel, builtIns));

if (saveStore) {
this.stores[key] = storeInstance;
Expand Down
20 changes: 12 additions & 8 deletions dist/alt-with-runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var assign = babelHelpers.interopRequire(require("object-assign"));
var ACTION_HANDLER = Symbol("action creator handler");
var ACTION_KEY = Symbol("holds the actions uid symbol for listening");
var ACTION_UID = Symbol("the actions uid name");
var ALL_LISTENERS = Symbol("name of listeners");
var EE = Symbol("event emitter instance");
var INIT_SNAPSHOT = Symbol("init snapshot storage");
var LAST_SNAPSHOT = Symbol("last snapshot storage");
Expand Down Expand Up @@ -52,7 +53,7 @@ var getInternalMethods = function (obj, excluded) {
};

var AltStore = (function () {
function AltStore(dispatcher, model, state) {
function AltStore(dispatcher, model, state, StoreModel) {
var _this8 = this;

babelHelpers.classCallCheck(this, AltStore);
Expand All @@ -61,6 +62,9 @@ var AltStore = (function () {
this[LIFECYCLE] = {};
this[STATE_CONTAINER] = state || model;

this.listenerNames = model[ALL_LISTENERS];
this.StoreModel = typeof StoreModel === "function" ? StoreModel : assign({}, StoreModel);

assign(this[LIFECYCLE], model[LIFECYCLE]);
assign(this, model[PUBLIC_METHODS]);

Expand Down Expand Up @@ -148,11 +152,9 @@ var StoreMixinListeners = {
}

// You can pass in the constant or the function itself
if (symbol[ACTION_KEY]) {
this[LISTENERS][symbol[ACTION_KEY]] = handler.bind(this);
} else {
this[LISTENERS][symbol] = handler.bind(this);
}
var key = symbol[ACTION_KEY] ? symbol[ACTION_KEY] : symbol;
this[LISTENERS][key] = handler.bind(this);
this[ALL_LISTENERS].push(Symbol.keyFor(key));
},

bindActions: function bindActions(actions) {
Expand Down Expand Up @@ -294,6 +296,7 @@ var createStoreFromObject = function (alt, StoreModel, key, saveStore) {
var storeInstance = undefined;

var StoreProto = {};
StoreProto[ALL_LISTENERS] = [];
StoreProto[LIFECYCLE] = {};
StoreProto[LISTENERS] = {};

Expand Down Expand Up @@ -328,7 +331,7 @@ var createStoreFromObject = function (alt, StoreModel, key, saveStore) {
}

// create the instance and assign the public methods to the instance
storeInstance = assign(new AltStore(alt.dispatcher, StoreProto, StoreProto.state), StoreProto.publicMethods);
storeInstance = assign(new AltStore(alt.dispatcher, StoreProto, StoreProto.state, StoreModel), StoreProto.publicMethods);

/* istanbul ignore else */
if (saveStore) {
Expand Down Expand Up @@ -410,13 +413,14 @@ var Alt = (function () {
}
});

Store.prototype[ALL_LISTENERS] = [];
Store.prototype[LIFECYCLE] = {};
Store.prototype[LISTENERS] = {};
Store.prototype[PUBLIC_METHODS] = {};

var store = new Store(this);

storeInstance = assign(new AltStore(this.dispatcher, store), getInternalMethods(StoreModel, builtIns));
storeInstance = assign(new AltStore(this.dispatcher, store, null, StoreModel), getInternalMethods(StoreModel, builtIns));

if (saveStore) {
this.stores[key] = storeInstance;
Expand Down
20 changes: 12 additions & 8 deletions dist/alt.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var assign = _interopRequire(require("object-assign"));
var ACTION_HANDLER = Symbol("action creator handler");
var ACTION_KEY = Symbol("holds the actions uid symbol for listening");
var ACTION_UID = Symbol("the actions uid name");
var ALL_LISTENERS = Symbol("name of listeners");
var EE = Symbol("event emitter instance");
var INIT_SNAPSHOT = Symbol("init snapshot storage");
var LAST_SNAPSHOT = Symbol("last snapshot storage");
Expand Down Expand Up @@ -64,7 +65,7 @@ var getInternalMethods = function (obj, excluded) {
};

var AltStore = (function () {
function AltStore(dispatcher, model, state) {
function AltStore(dispatcher, model, state, StoreModel) {
var _this8 = this;

_classCallCheck(this, AltStore);
Expand All @@ -73,6 +74,9 @@ var AltStore = (function () {
this[LIFECYCLE] = {};
this[STATE_CONTAINER] = state || model;

this.listenerNames = model[ALL_LISTENERS];
this.StoreModel = typeof StoreModel === "function" ? StoreModel : assign({}, StoreModel);

assign(this[LIFECYCLE], model[LIFECYCLE]);
assign(this, model[PUBLIC_METHODS]);

Expand Down Expand Up @@ -162,11 +166,9 @@ var StoreMixinListeners = {
}

// You can pass in the constant or the function itself
if (symbol[ACTION_KEY]) {
this[LISTENERS][symbol[ACTION_KEY]] = handler.bind(this);
} else {
this[LISTENERS][symbol] = handler.bind(this);
}
var key = symbol[ACTION_KEY] ? symbol[ACTION_KEY] : symbol;
this[LISTENERS][key] = handler.bind(this);
this[ALL_LISTENERS].push(Symbol.keyFor(key));
},

bindActions: function bindActions(actions) {
Expand Down Expand Up @@ -308,6 +310,7 @@ var createStoreFromObject = function (alt, StoreModel, key, saveStore) {
var storeInstance = undefined;

var StoreProto = {};
StoreProto[ALL_LISTENERS] = [];
StoreProto[LIFECYCLE] = {};
StoreProto[LISTENERS] = {};

Expand Down Expand Up @@ -342,7 +345,7 @@ var createStoreFromObject = function (alt, StoreModel, key, saveStore) {
}

// create the instance and assign the public methods to the instance
storeInstance = assign(new AltStore(alt.dispatcher, StoreProto, StoreProto.state), StoreProto.publicMethods);
storeInstance = assign(new AltStore(alt.dispatcher, StoreProto, StoreProto.state, StoreModel), StoreProto.publicMethods);

/* istanbul ignore else */
if (saveStore) {
Expand Down Expand Up @@ -425,13 +428,14 @@ var Alt = (function () {
}
});

Store.prototype[ALL_LISTENERS] = [];
Store.prototype[LIFECYCLE] = {};
Store.prototype[LISTENERS] = {};
Store.prototype[PUBLIC_METHODS] = {};

var store = new Store(this);

storeInstance = assign(new AltStore(this.dispatcher, store), getInternalMethods(StoreModel, builtIns));
storeInstance = assign(new AltStore(this.dispatcher, store, null, StoreModel), getInternalMethods(StoreModel, builtIns));

if (saveStore) {
this.stores[key] = storeInstance;
Expand Down
22 changes: 14 additions & 8 deletions src/alt.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import assign from 'object-assign'
const ACTION_HANDLER = Symbol('action creator handler')
const ACTION_KEY = Symbol('holds the actions uid symbol for listening')
const ACTION_UID = Symbol('the actions uid name')
const ALL_LISTENERS = Symbol('name of listeners')
const EE = Symbol('event emitter instance')
const INIT_SNAPSHOT = Symbol('init snapshot storage')
const LAST_SNAPSHOT = Symbol('last snapshot storage')
Expand Down Expand Up @@ -51,11 +52,16 @@ const getInternalMethods = (obj, excluded) => {
}

class AltStore {
constructor(dispatcher, model, state) {
constructor(dispatcher, model, state, StoreModel) {
this[EE] = new EventEmitter()
this[LIFECYCLE] = {}
this[STATE_CONTAINER] = state || model

this.listenerNames = model[ALL_LISTENERS]
this.StoreModel = typeof StoreModel === 'function'
? StoreModel
: assign({}, StoreModel)

assign(this[LIFECYCLE], model[LIFECYCLE])
assign(this, model[PUBLIC_METHODS])

Expand Down Expand Up @@ -132,11 +138,9 @@ const StoreMixinListeners = {
}

// You can pass in the constant or the function itself
if (symbol[ACTION_KEY]) {
this[LISTENERS][symbol[ACTION_KEY]] = handler.bind(this)
} else {
this[LISTENERS][symbol] = handler.bind(this)
}
const key = symbol[ACTION_KEY] ? symbol[ACTION_KEY] : symbol
this[LISTENERS][key] = handler.bind(this)
this[ALL_LISTENERS].push(Symbol.keyFor(key))
},

bindActions(actions) {
Expand Down Expand Up @@ -273,6 +277,7 @@ const createStoreFromObject = (alt, StoreModel, key, saveStore) => {
let storeInstance

const StoreProto = {}
StoreProto[ALL_LISTENERS] = []
StoreProto[LIFECYCLE] = {}
StoreProto[LISTENERS] = {}

Expand Down Expand Up @@ -306,7 +311,7 @@ const createStoreFromObject = (alt, StoreModel, key, saveStore) => {

// create the instance and assign the public methods to the instance
storeInstance = assign(
new AltStore(alt.dispatcher, StoreProto, StoreProto.state),
new AltStore(alt.dispatcher, StoreProto, StoreProto.state, StoreModel),
StoreProto.publicMethods
)

Expand Down Expand Up @@ -378,14 +383,15 @@ class Alt {
}
})

Store.prototype[ALL_LISTENERS] = []
Store.prototype[LIFECYCLE] = {}
Store.prototype[LISTENERS] = {}
Store.prototype[PUBLIC_METHODS] = {}

const store = new Store(this)

storeInstance = assign(
new AltStore(this.dispatcher, store),
new AltStore(this.dispatcher, store, null, StoreModel),
getInternalMethods(StoreModel, builtIns)
)

Expand Down

0 comments on commit e76ae26

Please sign in to comment.