本文整理匯總了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(); });
});