Creating ohif:commands package
This commit is contained in:
1 parent
2f81c0e2e7
commit
dbbcbe6e67
6 files changed
+151
-48
No files matched your search
@@ -0,0 +1,60 @@
|
||||
import { ReactiveDict } from 'meteor/reactive-dict';
|
||||
import { Tracker } from 'meteor/tracker';
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
|
||||
export class CommandsManager {
|
||||
constructor() {
|
||||
this.contexts = {};
|
||||
|
||||
Tracker.autorun(() => {
|
||||
const currentContextName = OHIF.context.get();
|
||||
OHIF.log.info(currentContextName);
|
||||
// TODO: initialize hotkeys context
|
||||
});
|
||||
}
|
||||
|
||||
getContext(contextName) {
|
||||
const context = this.contexts[contextName];
|
||||
if (!context) {
|
||||
OHIF.log.warn(`No context found with name "${contextName}"`);
|
||||
}
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
getCurrentContext(contextName) {
|
||||
return this.getContext(OHIF.context.get());
|
||||
}
|
||||
|
||||
createContext(contextName) {
|
||||
if (this.contexts[contextName]) {
|
||||
return this.unsetCommands(contextName);
|
||||
}
|
||||
|
||||
this.contexts[contextName] = new ReactiveDict();
|
||||
}
|
||||
|
||||
setCommands(contextName, definitions) {
|
||||
if (typeof definitions !== 'object') return;
|
||||
const context = this.getContext(contextName);
|
||||
if (!context) return;
|
||||
|
||||
this.unsetCommands(contextName);
|
||||
Object.keys(definitions).forEach(key => context.set(key, definitions[key]));
|
||||
}
|
||||
|
||||
registerCommand(contextName, key, definition) {
|
||||
if (typeof definition !== 'object') return;
|
||||
const context = this.getContext(contextName);
|
||||
if (!context) return;
|
||||
|
||||
context.set(key, definition);
|
||||
}
|
||||
|
||||
unsetCommands(contextName) {
|
||||
const context = this.getContext(contextName);
|
||||
if (!context) return;
|
||||
|
||||
context.clear();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { ReactiveVar } from 'meteor/reactive-var';
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
import { CommandsManager } from 'meteor/ohif:commands/client/classes/CommandsManager';
|
||||
|
||||
// Create context namespace using a ReactiveVar
|
||||
const context = new ReactiveVar(null);
|
||||
|
||||
// Create commands namespace using a CommandsManager class instance
|
||||
const commands = new CommandsManager(context);
|
||||
|
||||
// Append context namespace to OHIF namespace
|
||||
OHIF.context = context;
|
||||
|
||||
// Export relevant objects
|
||||
export { context, commands };
|
||||
@@ -0,0 +1,22 @@
|
||||
Package.describe({
|
||||
name: 'ohif:commands',
|
||||
summary: 'OHIF commands management',
|
||||
version: '0.0.1'
|
||||
});
|
||||
|
||||
Package.onUse(function(api) {
|
||||
api.versionsFrom('1.4');
|
||||
|
||||
// Meteor packages
|
||||
api.use([
|
||||
'ecmascript',
|
||||
'reactive-var',
|
||||
'reactive-dict'
|
||||
]);
|
||||
|
||||
// OHIF dependencies
|
||||
api.use('ohif:core');
|
||||
|
||||
// Main module definition
|
||||
api.mainModule('main.js', 'client');
|
||||
});
|
||||
Reference in new issue
Block a user