molstar
Version:
A comprehensive macromolecular library.
30 lines (29 loc) • 1.22 kB
JavaScript
/**
* Copyright (c) 2025 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author David Sehnal <david.sehnal@gmail.com>
*/
import { BehaviorSubject } from 'rxjs';
export class MVSStoriesContext {
dispatch(command) {
this.commands.next(command);
}
constructor(name) {
this.name = name;
this.commands = new BehaviorSubject(undefined);
this.state = {
viewers: new BehaviorSubject([]),
isLoading: new BehaviorSubject(false),
};
}
}
export function getMVSStoriesContext(options) {
var _a, _b, _c;
const container = (_a = options === null || options === void 0 ? void 0 : options.container) !== null && _a !== void 0 ? _a : window;
(_b = container.componentContexts) !== null && _b !== void 0 ? _b : (container.componentContexts = {});
const name = (_c = options === null || options === void 0 ? void 0 : options.name) !== null && _c !== void 0 ? _c : '<default>';
if (!container.componentContexts[name]) {
container.componentContexts[name] = new MVSStoriesContext(options === null || options === void 0 ? void 0 : options.name);
}
return container.componentContexts[name];
}