本文整理汇总了TypeScript中@jupyterlab/coreutils.StateDB.save方法的典型用法代码示例。如果您正苦于以下问题:TypeScript StateDB.save方法的具体用法?TypeScript StateDB.save怎么用?TypeScript StateDB.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@jupyterlab/coreutils.StateDB
的用法示例。
在下文中一共展示了StateDB.save方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: 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);
});
示例2: it
it('should only clear its own namespace', async () => {
const { localStorage } = window;
const db1 = new StateDB({ namespace: 'test-namespace-1' });
const db2 = new StateDB({ namespace: 'test-namespace-2' });
expect(localStorage.length).to.equal(0);
await db1.save('foo', { bar: null });
expect(localStorage).to.have.length(1);
await db2.save('baz', { qux: null });
expect(localStorage).to.have.length(2);
await db1.clear();
expect(localStorage).to.have.length(1);
await db2.clear();
expect(localStorage.length).to.equal(0);
});
示例3: it
it('should emit changes when the database is updated', done => {
const namespace = 'test-namespace';
const db = new StateDB({ namespace });
const changes: StateDB.Change[] = [
{ id: 'foo', type: 'save' },
{ id: 'foo', type: 'remove' },
{ id: 'bar', type: 'save' },
{ id: 'bar', type: 'remove' }
];
const recorded: StateDB.Change[] = [];
db.changed.connect((sender, change) => {
recorded.push(change);
});
db
.save('foo', 0)
.then(() => db.remove('foo'))
.then(() => db.save('bar', 1))
.then(() => db.remove('bar'))
.then(() => {
expect(recorded).to.deep.equal(changes);
})
.then(() => db.clear())
.then(done)
.catch(done);
});
示例4: it
it('should restore the widgets in a tracker', done => {
let tracker = new InstanceTracker<Widget>({ namespace: 'foo-widget' });
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(() => {
ready.resolve(undefined);
return restorer.restore(tracker, {
args: () => null,
name: () => tracker.namespace,
command: tracker.namespace
});
}).catch(done);
restorer.restored
.then(() => { expect(called).to.be(true); })
.then(() => state.remove(key))
.then(() => { done(); })
.catch(done);
});
示例5: it
it('should enforce the maximum length of a stored item', done => {
let db = new StateDB({ namespace: 'test' });
let key = 'test-key';
let data = { a: (new Array<string>(db.maxLength)).join('A') };
db.save(key, data)
.then(() => { done('maxLength promise should have rejected'); })
.catch(() => { done(); });
});