Comparing version 0.4.0 to 0.4.1
58
index.js
@@ -96,2 +96,31 @@ (function() { | ||
var baseStoreProto = { | ||
getState: function() { | ||
return this.__state; | ||
}, | ||
setState: function(state) { | ||
if (typeof state !== "object") { | ||
throw new Error("setState only accepts objects"); | ||
} | ||
// Poor man's inefficient but strict & safe change check. I know. | ||
var changed = Object.keys(state).some(function(prop) { | ||
return !this.__state.hasOwnProperty(prop) || | ||
state[prop] !== this.__state[prop]; | ||
}, this); | ||
if (!changed) return; | ||
this.__state = merge({}, this.__state, state); | ||
this.__listeners.forEach(function(listener) { | ||
listener(this.__state); | ||
}.bind(this)); | ||
}, | ||
subscribe: function(listener) { | ||
this.__listeners.push(listener); | ||
}, | ||
unsubscribe: function(listener) { | ||
this.__listeners = this.__listeners.filter(function(registered) { | ||
return registered !== listener; | ||
}); | ||
} | ||
}; | ||
DocBrown.createStore = function(storeProto) { | ||
@@ -122,34 +151,7 @@ if (typeof storeProto !== "object") { | ||
} | ||
BaseStore.prototype = merge({ | ||
get state() { | ||
return this.__state; | ||
}, | ||
getState: function() { | ||
return this.__state; | ||
}, | ||
setState: function(state) { | ||
if (typeof state !== "object") { | ||
throw new Error("setState only accepts objects"); | ||
} | ||
// Poor man's inefficient but strict & safe change check. I know. | ||
var changed = Object.keys(state).some(function(prop) { | ||
return !this.__state.hasOwnProperty(prop) || | ||
state[prop] !== this.__state[prop]; | ||
}, this); | ||
if (!changed) return; | ||
this.__state = merge({}, this.__state, state); | ||
this.__listeners.forEach(function(listener) { | ||
listener(this.__state); | ||
}.bind(this)); | ||
}, | ||
subscribe: function(listener) { | ||
this.__listeners.push(listener); | ||
}, | ||
unsubscribe: function(listener) { | ||
this.__listeners = this.__listeners.filter(function(registered) { | ||
return registered !== listener; | ||
}); | ||
} | ||
}, storeProto); | ||
}, baseStoreProto, storeProto); | ||
return BaseStore; | ||
@@ -156,0 +158,0 @@ }; |
{ | ||
"name": "docbrown", | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"description": "Flux experiment.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
653
32129