@storex/core
Advanced tools
Comparing version 1.0.10 to 1.0.11
@@ -14,3 +14,4 @@ export interface dependenceStore { | ||
_events: any; | ||
_waited_to_update_funcs: any; | ||
_waited_to_update_funcs: Set<any>; | ||
_dispatch_count: number; | ||
_eventsListenFunc: { | ||
@@ -17,0 +18,0 @@ [key: string]: Set<(a: any) => any>; |
@@ -5,2 +5,4 @@ "use strict"; | ||
constructor({ events, dependencies } = { events: [], dependencies: [] }) { | ||
this._waited_to_update_funcs = new Set(); | ||
this._dispatch_count = 0; | ||
this._eventsListenFunc = { | ||
@@ -60,24 +62,20 @@ onChange: new Set() | ||
} | ||
const funcs = new Set(funcs_array); | ||
if (!this._waited_to_update_funcs) { | ||
this._waited_to_update_funcs = funcs; | ||
setTimeout(() => { | ||
try { | ||
const message = this._sentOnChange(); | ||
for (const func of this._waited_to_update_funcs) { | ||
func(message); | ||
} | ||
this._waited_to_update_funcs = new Set([ | ||
...funcs_array, | ||
...this._waited_to_update_funcs | ||
]); | ||
if (this._dispatch_count === 0) { | ||
//setTimeout(() => { | ||
try { | ||
const message = this._sentOnChange(); | ||
for (const func of this._waited_to_update_funcs) { | ||
func(message); | ||
} | ||
catch (err) { | ||
console.error(err); | ||
} | ||
this._waited_to_update_funcs = undefined; | ||
}, 0); | ||
} | ||
catch (err) { | ||
console.error(err); | ||
} | ||
this._waited_to_update_funcs = new Set(); | ||
//}, 0); | ||
} | ||
else { | ||
this._waited_to_update_funcs = new Set([ | ||
...funcs, | ||
...this._waited_to_update_funcs | ||
]); | ||
} | ||
} | ||
@@ -84,0 +82,0 @@ destroy() { |
@@ -19,4 +19,4 @@ "use strict"; | ||
try { | ||
this.__dispatch_count++; | ||
const result = original.apply(this, arguments); | ||
store.dispatch.apply(this, [eventNames]); | ||
// console.log(`Result: ${result}`); | ||
@@ -29,2 +29,6 @@ return result; | ||
} | ||
finally { | ||
this.__dispatch_count--; | ||
store.dispatch.apply(this, [eventNames]); | ||
} | ||
}; | ||
@@ -31,0 +35,0 @@ } |
{ | ||
"name": "@storex/core", | ||
"version": "1.0.10", | ||
"version": "1.0.11", | ||
"description": "Binding store to your app", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
8430
227