• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript coreutils.StateDB类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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);
    });
开发者ID:willingc,项目名称:jupyterlab,代码行数:16,代码来源:statedb.spec.ts


示例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();
    });
开发者ID:afshin,项目名称:jupyterlab,代码行数:22,代码来源:statedb.spec.ts


示例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();
//.........这里部分代码省略.........
开发者ID:dalejung,项目名称:jupyterlab,代码行数:101,代码来源:model.spec.ts


示例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) => {
//.........这里部分代码省略.........
开发者ID:7125messi,项目名称:jupyterlab,代码行数:101,代码来源:model.spec.ts


示例5:

 .then(() => db.remove('foo'))
开发者ID:7125messi,项目名称:jupyterlab,代码行数:1,代码来源:statedb.spec.ts


示例6:

 const reset = () => state.clear().then(save);
开发者ID:cameronoelsen,项目名称:jupyterlab,代码行数:1,代码来源:index.ts


示例7:

 Object.keys(contents).map(key => db.save(key, contents[key]))
开发者ID:afshin,项目名称:jupyterlab,代码行数:1,代码来源:statedb.spec.ts



注:本文中的@jupyterlab/coreutils.StateDB类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript coreutils.Time类代码示例发布时间:2022-05-28
下一篇:
TypeScript coreutils.Poll类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap