@jbrowse/plugin-config
Version:
JBrowse 2 config utilities
33 lines (32 loc) • 1.09 kB
JavaScript
import { getSession } from '@jbrowse/core/util';
import { ElementId } from '@jbrowse/core/util/types/mst';
import { addDisposer, getSnapshot, types } from '@jbrowse/mobx-state-tree';
import { autorun } from 'mobx';
export default function stateModelFactory(_pluginManager) {
return types
.model('ConfigurationEditorWidget', {
id: ElementId,
type: types.literal('ConfigurationEditorWidget'),
})
.volatile(() => ({
target: undefined,
}))
.actions(self => ({
setTarget(newTarget) {
self.target = newTarget;
},
afterCreate() {
let timeout;
addDisposer(self, autorun(() => {
if (self.target) {
const snapshot = getSnapshot(self.target);
clearTimeout(timeout);
timeout = setTimeout(() => {
const session = getSession(self);
session.jbrowse.updateTrackConf(snapshot);
}, 400);
}
}));
},
}));
}