当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript apputils.StateDB类代码示例

本文整理汇总了TypeScript中@jupyterlab/apputils.StateDB的典型用法代码示例。如果您正苦于以下问题:TypeScript StateDB类的具体用法?TypeScript StateDB怎么用?TypeScript StateDB使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了StateDB类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
      });
开发者ID:charnpreetsingh185,项目名称:jupyterlab,代码行数:30,代码来源:layoutrestorer.spec.ts

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

示例3: StateDB

  activate: (app: JupyterLab) => {
    let state = new StateDB({ namespace: app.info.namespace });
    let version = app.info.version;
    let key = 'statedb:version';
    let fetch = state.fetch(key);
    let save = () => state.save(key, { version });
    let reset = () => state.clear().then(save);
    let check = (value: JSONObject) => {
      let old = value && value['version'];
      if (!old || old !== version) {
        console.log(`Upgraded: ${old || 'unknown'} to ${version}; Resetting DB.`);
        return reset();
      }
    };

    app.commands.addCommand(CommandIDs.clearStateDB, {
      label: 'Clear Application Restore State',
      execute: () => state.clear()
    });

    return fetch.then(check, reset).then(() => state);
  }
开发者ID:charnpreetsingh185,项目名称:jupyterlab,代码行数:22,代码来源:index.ts

示例4: describe

describe('filebrowser/model', () => {

  let manager: IDocumentManager;
  let serviceManager: ServiceManager.IManager;
  let registry: IDocumentRegistry;
  let model: FileBrowserModel;
  let name: string;
  let state: StateDB;

  before(() => {
    let opener: DocumentManager.IWidgetOpener = {
      open: widget => { /* no op */ }
    };

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

示例5: beforeEach

 beforeEach(() => {
   state.clear();
   model = new FileBrowserModel({ manager, state });
   return manager.newUntitled({ type: 'file' }).then(contents => {
     name = contents.name;
     return model.cd();
   });
 });
开发者ID:charnpreetsingh185,项目名称:jupyterlab,代码行数:8,代码来源:model.spec.ts


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