@storex/core
Advanced tools
Comparing version 1.0.22 to 1.0.23
@@ -28,10 +28,10 @@ export interface dependenceDispatcher { | ||
static register(func: any, dispatcher: (Dispatcher | DispatcherRegisterOptions)[]): void; | ||
dispatchOne: (func: any) => Promise<void>; | ||
dispatchOnce: (func: any) => Promise<void>; | ||
static unregister(func: any, dispatcher: (Dispatcher | DispatcherRegisterOptions)[]): void; | ||
_sentOnChange: () => this; | ||
register(func: (a: this) => any, eventNames?: string[]): void; | ||
unregisterFromAll(func: any): void; | ||
unregister(func: any, eventNames?: string[]): void; | ||
register: (func: (a: this) => any, eventNames?: string[]) => void; | ||
unregisterFromAll: (func: any) => void; | ||
unregister: (func: any, eventNames?: string[]) => void; | ||
dispatch(eventNames?: string[]): void; | ||
destroy(): void; | ||
destroy: () => void; | ||
} |
@@ -20,7 +20,3 @@ "use strict"; | ||
}; | ||
this.dispatchOne = (func) => __awaiter(this, void 0, void 0, function* () { | ||
const finish = () => { | ||
this._dispatch_count--; | ||
this.dispatch(); | ||
}; | ||
this.dispatchOnce = (func) => __awaiter(this, void 0, void 0, function* () { | ||
this._dispatch_count++; | ||
@@ -32,5 +28,8 @@ try { | ||
} | ||
finish(); | ||
console.log("dic once"); | ||
this._dispatch_count--; | ||
this.dispatch(); | ||
} | ||
catch (err) { | ||
this._dispatch_count--; | ||
throw err; | ||
@@ -40,2 +39,35 @@ } | ||
this._sentOnChange = () => this; | ||
this.register = (func, eventNames) => { | ||
if (eventNames && eventNames.length) { | ||
eventNames.forEach(eventName => { | ||
if (!this._eventsRegisterFunc[eventName]) { | ||
this._eventsRegisterFunc[eventName] = new Set(); | ||
} | ||
this._eventsRegisterFunc[eventName].add(func); | ||
}); | ||
} | ||
else { | ||
this._eventsRegisterFunc.onChange.add(func); | ||
} | ||
}; | ||
this.unregisterFromAll = (func) => { | ||
for (const event of Object.keys(this._eventsRegisterFunc)) { | ||
this._eventsRegisterFunc[event].delete(func); | ||
} | ||
}; | ||
this.unregister = (func, eventNames) => { | ||
if (eventNames && eventNames.length) { | ||
eventNames.forEach(eventName => { | ||
if (this._eventsRegisterFunc[eventName]) { | ||
this._eventsRegisterFunc[eventName].delete(func); | ||
} | ||
}); | ||
} | ||
else { | ||
this._eventsRegisterFunc.onChange.delete(func); | ||
} | ||
}; | ||
this.destroy = () => { | ||
// todo | ||
}; | ||
// todo dependencies | ||
@@ -73,32 +105,2 @@ this._events = new Set(events); | ||
} | ||
register(func, eventNames) { | ||
if (eventNames && eventNames.length) { | ||
eventNames.forEach(eventName => { | ||
if (!this._eventsRegisterFunc[eventName]) { | ||
this._eventsRegisterFunc[eventName] = new Set(); | ||
} | ||
this._eventsRegisterFunc[eventName].add(func); | ||
}); | ||
} | ||
else { | ||
this._eventsRegisterFunc.onChange.add(func); | ||
} | ||
} | ||
unregisterFromAll(func) { | ||
for (const event of Object.keys(this._eventsRegisterFunc)) { | ||
this._eventsRegisterFunc[event].delete(func); | ||
} | ||
} | ||
unregister(func, eventNames) { | ||
if (eventNames && eventNames.length) { | ||
eventNames.forEach(eventName => { | ||
if (this._eventsRegisterFunc[eventName]) { | ||
this._eventsRegisterFunc[eventName].delete(func); | ||
} | ||
}); | ||
} | ||
else { | ||
this._eventsRegisterFunc.onChange.delete(func); | ||
} | ||
} | ||
dispatch(eventNames) { | ||
@@ -140,6 +142,3 @@ let funcs_array = [...this._eventsRegisterFunc.onChange]; | ||
} | ||
destroy() { | ||
// todo | ||
} | ||
} | ||
exports.Dispatcher = Dispatcher; |
{ | ||
"name": "@storex/core", | ||
"version": "1.0.22", | ||
"version": "1.0.23", | ||
"description": "Binding store to your app", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
14927
393