[REF] store: make getters functions instead of properties

This commit is contained in:
Géry Debongnie
2019-05-10 11:50:04 +02:00
parent 147f6fced7
commit f52a15d7f6
2 changed files with 20 additions and 29 deletions
+4 -7
View File
@@ -47,7 +47,7 @@ export class Store extends EventBus {
env: any;
observer: Observer;
set: any;
getters: { [name: string]: Getter };
getters: { [name: string]: (payload?) => any };
constructor(config: StoreConfig, options: StoreOption = {}) {
super();
@@ -70,12 +70,9 @@ export class Store extends EventBus {
for (let entry of Object.entries(config.getters || {})) {
const name: string = entry[0];
const func: (...any) => any = entry[1];
Object.defineProperty(this.getters, name, {
get: func.bind(this, {
state: this.state,
getters: this.getters
})
});
this.getters[name] = payload => {
return func({ state: this.state, getters: this.getters }, payload);
}
}
}