How to use the @lumino/coreutils.JSONExt.deepCopy function in @lumino/coreutils

To help you get started, we’ve selected a few @lumino/coreutils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jupyterlab / jupyterlab / packages / coreutils / src / settingregistry.ts View on Github external
export function reifyDefault(
    schema: ISettingRegistry.IProperty,
    root?: string
  ): JSONValue | undefined {
    // If the property is at the root level, traverse its schema.
    schema = (root ? schema.properties?.[root] : schema) || {};

    // If the property has no default or is a primitive, return.
    if (!('default' in schema) || schema.type !== 'object') {
      return schema.default;
    }

    // Make a copy of the default value to populate.
    const result = JSONExt.deepCopy(schema.default);

    // Iterate through and populate each child property.
    const props = schema.properties || {};
    for (let property in props) {
      result[property] = reifyDefault(props[property]);
    }

    return result;
  }
}
github jupyterlab / jupyterlab / tests / test-services / src / kernelspec / manager.spec.ts View on Github external
it('should update list of kernel specs', async () => {
        const manager = new TestManager({ standby: 'never' });
        const specs = JSONExt.deepCopy(KERNELSPECS) as KernelSpec.ISpecModels;
        await manager.ready;
        specs.default = 'shell';
        manager.intercept = specs;
        expect(manager.specs!.default).not.to.equal('shell');
        await manager.refreshSpecs();
        expect(manager.specs!.default).to.equal('shell');
      });
    });
github jupyterlab / jupyterlab / tests / test-services / src / kernel / manager.spec.ts View on Github external
it('should update list of kernel specs', async () => {
        const manager = new TestManager({ standby: 'never' });
        const specs = JSONExt.deepCopy(KERNELSPECS) as Kernel.ISpecModels;
        await manager.ready;
        specs.default = 'shell';
        manager.intercept = specs;
        expect(manager.specs.default).not.to.equal('shell');
        await manager.refreshSpecs();
        expect(manager.specs.default).to.equal('shell');
      });
    });
github jupyterlab / jupyterlab / packages / cells / src / model.ts View on Github external
let trusted = this.modelDB.createValue('trusted');
    trusted.changed.connect(this.onTrustedChanged, this);

    if (!cell) {
      trusted.set(false);
      return;
    }
    trusted.set(!!cell.metadata['trusted']);
    delete cell.metadata['trusted'];

    if (Array.isArray(cell.source)) {
      this.value.text = (cell.source as string[]).join('');
    } else {
      this.value.text = cell.source as string;
    }
    let metadata = JSONExt.deepCopy(cell.metadata);
    if (this.type !== 'raw') {
      delete metadata['format'];
    }
    if (this.type !== 'code') {
      delete metadata['collapsed'];
      delete metadata['scrolled'];
    }

    for (let key in metadata) {
      observableMetadata.set(key, metadata[key]);
    }
  }
github jupyterlab / jupyterlab / packages / observables / src / observablejson.ts View on Github external
toJSON(): PartialJSONObject {
    const out: PartialJSONObject = Object.create(null);
    const keys = this.keys();

    for (let key of keys) {
      const value = this.get(key);

      if (value !== undefined) {
        out[key] = JSONExt.deepCopy(value) as PartialJSONObject;
      }
    }
    return out;
  }
}