|
@@ -9,13 +9,20 @@ import { StateObject, StateObjectCell } from '../object';
|
|
|
import { StateTransformer } from '../transformer';
|
|
|
import { UUID } from '../../mol-util';
|
|
|
import { arraySetRemove } from '../../mol-util/array';
|
|
|
+import { RxEventHelper } from '../../mol-util/rx-event-helper';
|
|
|
|
|
|
export { StateActionManager };
|
|
|
|
|
|
class StateActionManager {
|
|
|
+ private ev = RxEventHelper.create();
|
|
|
private actions: Map<StateAction['id'], StateAction> = new Map();
|
|
|
private fromTypeIndex = new Map<StateObject.Type, StateAction[]>();
|
|
|
|
|
|
+ readonly events = {
|
|
|
+ added: this.ev<undefined>(),
|
|
|
+ removed: this.ev<undefined>(),
|
|
|
+ }
|
|
|
+
|
|
|
add(actionOrTransformer: StateAction | StateTransformer) {
|
|
|
const action = StateTransformer.is(actionOrTransformer) ? actionOrTransformer.toAction() : actionOrTransformer;
|
|
|
|
|
@@ -31,6 +38,8 @@ class StateActionManager {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ this.events.added.next();
|
|
|
+
|
|
|
return this;
|
|
|
}
|
|
|
|
|
@@ -53,6 +62,8 @@ class StateActionManager {
|
|
|
if (xs.length === 0) this.fromTypeIndex.delete(t.type);
|
|
|
}
|
|
|
|
|
|
+ this.events.removed.next();
|
|
|
+
|
|
|
return this;
|
|
|
}
|
|
|
|
|
@@ -83,4 +94,8 @@ class StateActionManager {
|
|
|
}
|
|
|
return ret;
|
|
|
}
|
|
|
+
|
|
|
+ dispose() {
|
|
|
+ this.ev.dispose();
|
|
|
+ }
|
|
|
}
|