mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-08 01:13:27 +01:00
passing old value for stateful events
This commit is contained in:
parent
271b7dd84a
commit
d6c5a56e5f
1 changed files with 5 additions and 2 deletions
|
|
@ -75,13 +75,16 @@ export default class Bus {
|
|||
}
|
||||
|
||||
dispatch(key, data) {
|
||||
// console.log('dispatch: ' + key + ' -> ' + JSON.stringify(data));
|
||||
// console.log('dispatch: %c' + key, 'color: #0a0');
|
||||
// console.log(data);
|
||||
|
||||
if (this.lock.has(key)) {
|
||||
console.warn('recursive dispatch');
|
||||
return
|
||||
}
|
||||
let oldValue;
|
||||
if (this.keepStateFor.has(key)) {
|
||||
oldValue = this.state[key];
|
||||
this.state[key] = data;
|
||||
}
|
||||
this.lock.add(key);
|
||||
|
|
@ -91,7 +94,7 @@ export default class Bus {
|
|||
for (let i = 0; i < listenerList.length; i++) {
|
||||
const callback = listenerList[i];
|
||||
try {
|
||||
callback(data);
|
||||
callback(data, oldValue);
|
||||
} catch(e) {
|
||||
console.error(e);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue