本文整理匯總了TypeScript中@jupyterlab/coreutils.StateDB類的典型用法代碼示例。如果您正苦於以下問題:TypeScript StateDB類的具體用法?TypeScript StateDB怎麽用?TypeScript StateDB使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了StateDB類的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: 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);
});
示例2: it
it('should emit changes when the database is updated', async () => {
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);
});
await db.save('foo', 0);
await db.remove('foo');
await db.save('bar', 1);
await db.remove('bar');
expect(recorded).to.deep.equal(changes);
await db.clear();
});
示例3: describe
describe('filebrowser/model', () => {
let manager: IDocumentManager;
let serviceManager: ServiceManager.IManager;
let registry: DocumentRegistry;
let model: FileBrowserModel;
let name: string;
let state: StateDB;
before(() => {
let opener: DocumentManager.IWidgetOpener = {
open: widget => {
/* no op */
}
};
registry = new DocumentRegistry({
textModelFactory: new TextModelFactory()
});
serviceManager = new ServiceManager();
manager = new DocumentManager({
registry,
opener,
manager: serviceManager
});
state = new StateDB({ namespace: 'filebrowser/model' });
});
beforeEach(() => {
state.clear();
model = new FileBrowserModel({ manager, state });
return manager.newUntitled({ type: 'file' }).then(contents => {
name = contents.name;
return model.cd();
});
});
afterEach(() => {
model.dispose();
});
describe('FileBrowserModel', () => {
describe('#constructor()', () => {
it('should construct a new file browser model', () => {
model = new FileBrowserModel({ manager });
expect(model).to.be.a(FileBrowserModel);
});
});
describe('#pathChanged', () => {
it('should be emitted when the path changes', done => {
model.pathChanged.connect((sender, args) => {
expect(sender).to.be(model);
expect(args.name).to.be('path');
expect(args.oldValue).to.be('');
expect(args.newValue).to.be('src');
done();
});
model.cd('src').catch(done);
});
});
describe('#refreshed', () => {
it('should be emitted after a refresh', done => {
model.refreshed.connect((sender, arg) => {
expect(sender).to.be(model);
expect(arg).to.be(void 0);
done();
});
model.cd().catch(done);
});
it('should be emitted when the path changes', done => {
model.refreshed.connect((sender, arg) => {
expect(sender).to.be(model);
expect(arg).to.be(void 0);
done();
});
model.cd('src').catch(done);
});
});
describe('#fileChanged', () => {
it('should be emitted when a file is created', done => {
model.fileChanged.connect((sender, args) => {
expect(sender).to.be(model);
expect(args.type).to.be('new');
expect(args.oldValue).to.be(null);
expect(args.newValue.type).to.be('file');
done();
});
manager.newUntitled({ type: 'file' }).catch(done);
});
it('should be emitted when a file is renamed', done => {
model.fileChanged.connect((sender, args) => {
expect(sender).to.be(model);
expect(args.type).to.be('rename');
expect(args.oldValue.path).to.be(name);
expect(args.newValue.path).to.be(name + '.bak');
done();
//.........這裏部分代碼省略.........
示例4: describe
describe('filebrowser/model', () => {
let manager: IDocumentManager;
let serviceManager: ServiceManager.IManager;
let registry: DocumentRegistry;
let model: FileBrowserModel;
let name: string;
let state: StateDB;
before(() => {
let opener: DocumentManager.IWidgetOpener = {
open: widget => { /* no op */ }
};
registry = new DocumentRegistry({
textModelFactory: new TextModelFactory()
});
serviceManager = new ServiceManager();
manager = new DocumentManager({
registry, opener,
manager: serviceManager
});
state = new StateDB({ namespace: 'filebrowser/model' });
});
beforeEach(() => {
state.clear();
model = new FileBrowserModel({ manager, state });
return manager.newUntitled({ type: 'file' }).then(contents => {
name = contents.name;
return model.cd();
});
});
afterEach(() => {
model.dispose();
});
describe('FileBrowserModel', () => {
describe('#constructor()', () => {
it('should construct a new file browser model', () => {
model = new FileBrowserModel({ manager });
expect(model).to.be.a(FileBrowserModel);
});
});
describe('#pathChanged', () => {
it('should be emitted when the path changes', (done) => {
model.pathChanged.connect((sender, args) => {
expect(sender).to.be(model);
expect(args.name).to.be('path');
expect(args.oldValue).to.be('');
expect(args.newValue).to.be('src');
done();
});
model.cd('src').catch(done);
});
});
describe('#refreshed', () => {
it('should be emitted after a refresh', (done) => {
model.refreshed.connect((sender, arg) => {
expect(sender).to.be(model);
expect(arg).to.be(void 0);
done();
});
model.cd().catch(done);
});
it('should be emitted when the path changes', (done) => {
model.refreshed.connect((sender, arg) => {
expect(sender).to.be(model);
expect(arg).to.be(void 0);
done();
});
model.cd('src').catch(done);
});
});
describe('#fileChanged', () => {
it('should be emitted when a file is created', (done) => {
model.fileChanged.connect((sender, args) => {
expect(sender).to.be(model);
expect(args.type).to.be('new');
expect(args.oldValue).to.be(null);
expect(args.newValue.type).to.be('file');
done();
});
manager.newUntitled({ type: 'file' }).catch(done);
});
it('should be emitted when a file is renamed', (done) => {
//.........這裏部分代碼省略.........
示例6:
const reset = () => state.clear().then(save);
示例7:
Object.keys(contents).map(key => db.save(key, contents[key]))