not-flux
Advanced tools
Comparing version 0.1.4 to 0.1.9
{ | ||
"name": "not-flux", | ||
"version": "0.1.4", | ||
"version": "0.1.9", | ||
"authors": [ | ||
@@ -17,3 +17,2 @@ "MikaAK <mikakalathil@gmail.com>" | ||
"model", | ||
"cache", | ||
"es6" | ||
@@ -32,4 +31,5 @@ ], | ||
"thaw.js": "~1.2.x", | ||
"angular": "~1.3.x" | ||
"angular": "~1.3.x", | ||
"nested-observe": "~1.2.1" | ||
} | ||
} |
@@ -17,5 +17,4 @@ "use strict"; | ||
} | ||
} | ||
}, | ||
babelHelpers = babel && angular.extend(helpers, babelHelpers) || helpers; | ||
} }, | ||
babelHelpers = babelHelpers && angular.extend(helpers, babelHelpers) || helpers; | ||
@@ -113,2 +112,3 @@ angular.module("not-flux", []).factory("NotFlux", ["Store", "Action", function (Store, Action) { | ||
angular.extend(this, this._pullData(data)); | ||
// Extend the new functions into the store | ||
@@ -119,3 +119,3 @@ angular.extend(this, this._filterFunctions(data)); | ||
// without thinking about it, as well as broadcast change events | ||
Object.observe(this, this._objectChanged); | ||
Nested.observe(this, this._objectChanged); | ||
@@ -173,8 +173,8 @@ // Run init function to be overloaded | ||
value: function emit() { | ||
value: function emit(_x, data) { | ||
var eventName = arguments[0] === undefined ? this.modelCacheId() : arguments[0]; | ||
var data = arguments[1] === undefined ? this : arguments[1]; | ||
// Broadcast events through the application scope only | ||
// passes a deep copy of the data | ||
$rootScope.$broadcast(eventName, this._filterData(data)); | ||
@@ -270,3 +270,5 @@ }, | ||
var cloneData = {}; | ||
if (data !== this) { | ||
return angular.copy(data); | ||
}var cloneData = {}; | ||
@@ -305,9 +307,26 @@ Object.keys(this._pullData(data)).forEach(function (key) { | ||
value: function _objectChanged(changes) { | ||
var object = changes[changes.length - 1].object, | ||
listeners = object._changeListeners; | ||
var changedStores, | ||
unique = _ && _.uniq || function (a, b, c) { | ||
//array,placeholder,placeholder taken from stack | ||
if (listeners.length) thaw(listeners, { | ||
each: function (i) { | ||
b = a.length; | ||
while (c = --b) while (c--) a[b] !== a[c] || a.splice(c, 1); | ||
return a; | ||
}; | ||
changedStores = unique(changes.filter(function (obj) { | ||
return !(obj.path === "/_changeListeners" && obj.removed.length); | ||
}).map(function (obj) { | ||
return obj.root; | ||
})); | ||
thaw(changedStores, { | ||
each: function each() { | ||
var _this = this; | ||
$rootScope.$apply(function () { | ||
return listeners[i](object._filterData()); | ||
_this._changeListeners.forEach(function (callback) { | ||
return callback(_this._filterData()); | ||
}); | ||
}); | ||
@@ -314,0 +333,0 @@ } |
{ | ||
"name": "not-flux", | ||
"version": "0.1.4", | ||
"version": "0.1.9", | ||
"description": "angular model store that allows you to share data over all instances, as well as storing all models in one location.", | ||
@@ -5,0 +5,0 @@ "main": "dist/notFlux.js", |
@@ -17,5 +17,5 @@ 'use strict' | ||
} | ||
} | ||
}, | ||
}, | ||
babelHelpers = (babel && angular.extend(helpers, babelHelpers)) || helpers | ||
babelHelpers = (babelHelpers && angular.extend(helpers, babelHelpers)) || helpers | ||
@@ -22,0 +22,0 @@ angular.module('not-flux', []) |
@@ -13,2 +13,3 @@ 'use strict' | ||
angular.extend(this, this._pullData(data)) | ||
// Extend the new functions into the store | ||
@@ -19,3 +20,3 @@ angular.extend(this, this._filterFunctions(data)) | ||
// without thinking about it, as well as broadcast change events | ||
Object.observe(this, this._objectChanged) | ||
Nested.observe(this, this._objectChanged) | ||
@@ -53,5 +54,6 @@ // Run init function to be overloaded | ||
// Emit events along scopes | ||
emit(eventName = this.modelCacheId(), data = this) { | ||
emit(eventName = this.modelCacheId(), data) { | ||
// Broadcast events through the application scope only | ||
// passes a deep copy of the data | ||
$rootScope.$broadcast(eventName, this._filterData(data)) | ||
@@ -130,4 +132,6 @@ } | ||
_filterData(data = this) { | ||
var cloneData = {} | ||
if (data !== this) return angular.copy(data) | ||
let cloneData = {} | ||
Object.keys(this._pullData(data)).forEach(key => { | ||
@@ -160,14 +164,27 @@ if (key[0] !== '_') | ||
_objectChanged(changes) { | ||
var object = changes[changes.length - 1].object, | ||
listeners = object._changeListeners | ||
_objectChanged(changes) { | ||
var changedStores, | ||
unique = _ && _.uniq || function(a,b,c) {//array,placeholder,placeholder taken from stack | ||
b = a.length; | ||
while (c = --b) | ||
while (c--) | ||
a[b] !== a[c] || a.splice(c,1); | ||
if (listeners.length) | ||
thaw(listeners, { | ||
each: i => { | ||
$rootScope.$apply(() => listeners[i](object._filterData())) | ||
} | ||
}) | ||
return a | ||
} | ||
changedStores = unique(changes | ||
.filter(obj => !(obj.path === '/_changeListeners' && obj.removed.length)) | ||
.map(obj => obj.root)) | ||
thaw(changedStores, { | ||
each: function() { | ||
$rootScope.$apply(() => { | ||
this._changeListeners.forEach(callback => callback(this._filterData())) | ||
}) | ||
} | ||
}) | ||
} | ||
} | ||
}]) |
Sorry, the diff of this file is not supported yet
63497
635