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


TypeScript StateDB.save方法代码示例

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

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

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

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

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


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