本文整理匯總了TypeScript中@phosphor/commands.CommandRegistry類的典型用法代碼示例。如果您正苦於以下問題:TypeScript CommandRegistry類的具體用法?TypeScript CommandRegistry怎麽用?TypeScript CommandRegistry使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了CommandRegistry類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: it
it('should restore the widgets in a tracker', done => {
let tracker = new InstanceTracker<Widget>({
namespace: 'foo-widget',
shell: new ApplicationShell()
});
let registry = new CommandRegistry();
let state = new StateDB({ namespace: NAMESPACE });
let ready = new PromiseDelegate<void>();
let restorer = new LayoutRestorer({
first: ready.promise, registry, state
});
let called = false;
let key = `${tracker.namespace}:${tracker.namespace}`;
registry.addCommand(tracker.namespace, {
execute: () => { called = true; }
});
state.save(key, { data: null }).then(() => {
return restorer.restore(tracker, {
args: () => null,
name: () => tracker.namespace,
command: tracker.namespace
});
}).catch(done);
ready.resolve(void 0);
restorer.restored.then(() => { expect(called).to.be(true); })
.then(() => state.remove(key))
.then(() => { done(); })
.catch(done);
});
示例2: it
it('should connect a node to a command', () => {
let called = false;
const command = 'commandlinker:connect-node';
const commands = new CommandRegistry();
const linker = new CommandLinker({ commands });
let node: HTMLElement;
let vnode: VirtualNode;
const disposable = commands.addCommand(command, {
execute: () => {
called = true;
}
});
vnode = h.div({ dataset: linker.populateVNodeDataset(command, null) });
node = VirtualDOM.realize(vnode);
document.body.appendChild(node);
expect(called).to.equal(false);
simulate(node, 'click');
expect(called).to.equal(true);
document.body.removeChild(node);
linker.dispose();
disposable.dispose();
});
示例3: it
it('should disconnect a node from a command', () => {
let called = false;
let command = 'commandlinker:disconnect-node';
let commands =new CommandRegistry();
let linker = new CommandLinker({ commands });
let node = document.createElement('div');
let disposable = commands.addCommand(command, {
execute: () => { called = true; }
});
document.body.appendChild(node);
linker.connectNode(node, command, null);
// Make sure connection is working.
expect(called).to.be(false);
simulate(node, 'click');
expect(called).to.be(true);
// Reset flag.
called = false;
// Make sure disconnection is working.
linker.disconnectNode(node);
expect(called).to.be(false);
simulate(node, 'click');
expect(called).to.be(false);
document.body.removeChild(node);
linker.dispose();
disposable.dispose();
});
示例4: before
before(() => {
commands = new CommandRegistry();
bkoMenu = new BkoMenu({ commands });
commands.addCommand('test', { execute: () => {} });
bkoMenu.addItem({command: 'test', submenu: bkoMenu, type: 'submenu'});
});
示例5: it
it('should restore the widgets in a tracker', async () => {
const tracker = new InstanceTracker<Widget>({
namespace: 'foo-widget'
});
const registry = new CommandRegistry();
const state = new StateDB({ namespace: NAMESPACE });
const ready = new PromiseDelegate<void>();
const restorer = new LayoutRestorer({
first: ready.promise,
registry,
state
});
let called = false;
const key = `${tracker.namespace}:${tracker.namespace}`;
registry.addCommand(tracker.namespace, {
execute: () => {
called = true;
}
});
await state.save(key, { data: null });
ready.resolve(undefined);
await restorer.restore(tracker, {
args: () => null,
name: () => tracker.namespace,
command: tracker.namespace
});
await restorer.restored;
expect(called).to.equal(true);
});
示例6: it
it('should be a new array', () => {
registry.addCommand('test0', NULL_COMMAND);
registry.addCommand('test1', NULL_COMMAND);
let cmds = registry.listCommands();
cmds.push('test2');
expect(registry.listCommands()).to.deep.equal(['test0', 'test1']);
});
示例7: render
it('should update the node content on command change event', async () => {
const id = 'to-be-removed';
let iconClassValue: string | null = null;
const cmd = commands.addCommand(id, {
execute: () => {
/* no op */
},
label: 'Label-only button',
iconClass: () => iconClassValue
});
const button = new CommandToolbarButton({
commands,
id
});
await render(button);
const buttonNode = button.node.firstChild as HTMLButtonElement;
expect(buttonNode.textContent).to.equal('Label-only button');
expect(buttonNode.classList.contains(iconClassValue)).to.equal(false);
iconClassValue = 'updated-icon-class';
commands.notifyCommandChanged(id);
await render(button);
const wrapperNode = buttonNode.firstChild as HTMLElement;
const iconNode = wrapperNode.firstChild as HTMLElement;
expect(iconNode.classList.contains(iconClassValue)).to.equal(true);
cmd.dispose();
});
示例8: it
it('should stop routing if returned by a routed command', done => {
const wanted = ['a', 'b'];
const recorded: string[] = [];
commands.addCommand('a', {
execute: () => {
recorded.push('a');
}
});
commands.addCommand('b', {
execute: () => {
recorded.push('b');
}
});
commands.addCommand('c', { execute: () => router.stop });
commands.addCommand('d', {
execute: () => {
recorded.push('d');
}
});
router.register({ command: 'a', pattern: /.*/, rank: 10 });
router.register({ command: 'b', pattern: /.*/, rank: 20 });
router.register({ command: 'c', pattern: /.*/, rank: 30 });
router.register({ command: 'd', pattern: /.*/, rank: 40 });
router.routed.connect(() => {
expect(recorded).to.deep.equal(wanted);
done();
});
router.route();
});