mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
imp: add debug mode to store
This commit is contained in:
+19
-1
@@ -44,17 +44,28 @@ interface StoreConfig {
|
|||||||
actions?: any;
|
actions?: any;
|
||||||
mutations?: any;
|
mutations?: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface StoreOption {
|
||||||
|
debug?: boolean;
|
||||||
|
}
|
||||||
export class Store extends EventBus {
|
export class Store extends EventBus {
|
||||||
_state: any;
|
_state: any;
|
||||||
actions: any;
|
actions: any;
|
||||||
mutations: any;
|
mutations: any;
|
||||||
_isMutating: boolean = false;
|
_isMutating: boolean = false;
|
||||||
|
history: any[] = [];
|
||||||
|
debug: boolean;
|
||||||
|
|
||||||
constructor(config: StoreConfig = {}) {
|
constructor(config: StoreConfig, options: StoreOption = {}) {
|
||||||
super();
|
super();
|
||||||
|
this.debug = options.debug || false;
|
||||||
this._state = Object.assign({}, config.state);
|
this._state = Object.assign({}, config.state);
|
||||||
this.actions = config.actions;
|
this.actions = config.actions;
|
||||||
this.mutations = config.mutations;
|
this.mutations = config.mutations;
|
||||||
|
|
||||||
|
if (this.debug) {
|
||||||
|
this.history.push({ state: this.state });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get state() {
|
get state() {
|
||||||
@@ -81,6 +92,13 @@ export class Store extends EventBus {
|
|||||||
this._isMutating = true;
|
this._isMutating = true;
|
||||||
|
|
||||||
this.mutations[type].call(null, this._state, payload);
|
this.mutations[type].call(null, this._state, payload);
|
||||||
|
if (this.debug) {
|
||||||
|
this.history.push({
|
||||||
|
state: this.state,
|
||||||
|
mutation: type,
|
||||||
|
payload: payload
|
||||||
|
});
|
||||||
|
}
|
||||||
await Promise.resolve();
|
await Promise.resolve();
|
||||||
if (this._isMutating) {
|
if (this._isMutating) {
|
||||||
this._isMutating = false;
|
this._isMutating = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user