Skip to content
Snippets Groups Projects
Commit 6fba929a authored by David Sehnal's avatar David Sehnal
Browse files

mol-plugin: pass ref to Behavior.register

parent 4ad37d11
No related branches found
No related tags found
No related merge requests found
......@@ -5,7 +5,7 @@
*/
import { PluginStateTransform, PluginStateObject } from '../state/objects';
import { Transformer } from 'mol-state';
import { Transformer, Transform } from 'mol-state';
import { Task } from 'mol-task';
import { PluginContext } from 'mol-plugin/context';
import { PluginCommand } from '../command';
......@@ -16,7 +16,7 @@ import { shallowEqual } from 'mol-util';
export { PluginBehavior }
interface PluginBehavior<P = unknown> {
register(): void,
register(ref: Transform.Ref): void,
unregister(): void,
/** Update params in place. Optionally return a promise if it depends on an async action. */
......
......@@ -28,7 +28,7 @@ export function registerDefault(ctx: PluginContext) {
export function SyncBehaviors(ctx: PluginContext) {
ctx.events.state.object.created.subscribe(o => {
if (!SO.isBehavior(o.obj)) return;
o.obj.data.register();
o.obj.data.register(o.ref);
});
ctx.events.state.object.removed.subscribe(o => {
......@@ -39,7 +39,7 @@ export function SyncBehaviors(ctx: PluginContext) {
ctx.events.state.object.updated.subscribe(o => {
if (o.action === 'recreate') {
if (o.oldObj && SO.isBehavior(o.oldObj)) o.oldObj.data.unregister();
if (o.obj && SO.isBehavior(o.obj)) o.obj.data.register();
if (o.obj && SO.isBehavior(o.obj)) o.obj.data.register(o.ref);
}
});
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment