How to use clone-deep - 10 common examples

To help you get started, we’ve selected a few clone-deep 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 containerum / ui / src / actions / deploymentActions / updateDeployment.js View on Github external
): ThunkAction => async (dispatch: Dispatch) => {
  const browser = cookie.load('browser');
  const accessToken = cookie.load('accessToken');

  dispatch(updateDeploymentRequest());
  const splitContainers = cloneDeep(dataObj.containers);
  splitContainers.map(item => {
    delete item.id;
    // item.resources.requests = Object.assign({}, item.resources);
    // delete item.resources.cpu;
    // delete item.resources.memory;
    if (item.ports[0].containerPort) {
      item.ports.map(includePorts => {
        delete includePorts.id;
        delete includePorts.index;
        return null;
      });
    } else {
      item.ports = [];
    }
    if (item.env[0].value) {
      item.env.map(includeEnvs => {
github digidem / react-mapfilter / src / lib / data_analysis / statistics.js View on Github external
return function getStats(data: Array): Statistics {
    if (data === dataMemo) return stats
    const { added, removed } = diffArrays(dataMemo, data)
    if (!added.length && !removed.length) return cloneDeep(stats)
    if (removed.length) {
      // Anything removed, calculate all the stats
      // TODO: more efficient stats on removal
      stats = {}
      data.forEach(item => addItemStats(item, stats))
    } else {
      // Only added items -> only need to process new items
      added.forEach(item => addItemStats(item, stats))
    }
    dataMemo = data
    return cloneDeep(stats)
  }
}
github frontity / frontity / packages / wp-source / src / libraries / handlers / __tests__ / post-type.tests.ts View on Github external
beforeEach(() => {
  store = createStore(clone(wpSource()));
  store.actions.source.init();
  api = store.libraries.source.api as jest.Mocked;
});
github frontity / frontity / packages / wp-source / src / libraries / __tests__ / populate.tests.ts View on Github external
const initStore = (): InitializedStore => {
  const config = clone(wpSource());
  return createStore(config);
};
github vuegg / vuegg / client / src / mixins / redoundo.js View on Github external
undo () {
      if (this.canUndo) {
        this.undone.push(this.done.pop())
        let undoState = this.done[this.done.length - 1]
        this.$store.replaceState(cloneDeep(undoState))
        this.$root.$emit('rebaseState')
        this.updateCanRedoUndo()
      }
    },
github ianstormtaylor / superstruct / src / schemas.js View on Github external
default(value) {
    if (value !== undefined) return value
    const { defaults } = this
    return typeof defaults === 'function' ? defaults() : cloneDeep(defaults)
  }
github vuegg / vuegg / client / src / components / editor / drawer / settings / SettingsMenu.vue View on Github external
'selectedItem': function (val) {
      if (val !== null) {
        if (Array.isArray(val)) {
          this.text = this.height = this.width = this.top = this.left = this.bottom = this.right = null
          this.attrs = this.styles = this.classes = {}
          this.zIndex = 'auto'
        } else {
          this.text = (val.text) ? val.text : null
          this.height = (typeof val.height !== 'undefined') ? val.height.toString() : null
          this.width = (typeof val.width !== 'undefined') ? val.width.toString() : null
          this.top = (typeof val.top !== 'undefined') ? val.top.toString() : null
          this.left = (typeof val.left !== 'undefined') ? val.left.toString() : null
          this.bottom = (typeof val.bottom !== 'undefined') ? val.bottom.toString() : null
          this.right = (typeof val.right !== 'undefined') ? val.right.toString() : null
          this.zIndex = (typeof val.zIndex !== 'undefined') ? val.zIndex : 'auto'
          this.attrs = (val.attrs) ? cloneDeep(val.attrs) : {}
          this.styles = (val.styles) ? cloneDeep(val.styles) : {}
          this.classes = (val.classes) ? cloneDeep(val.classes) : {}
        }
      }
    }
  }
github carlos-kelly / publications / src / components / documents / editor-actions.ts View on Github external
if (!selectedObject || !currentDocument) {
    return {};
  }

  const updatedState: { [key: string]: PubDocument | PubShape } = {};

  if (action === ClipboardAction.Copy) {
    updatedState.clipboardContents = duplicateObj(selectedObject);
  } else if (action === ClipboardAction.Cut) {
    return {
      clipboardContents: duplicateObj(selectedObject),
      ...updatedDocumentStateForDeleteAction(selectedObject, currentDocument),
    };
  } else if (action === ClipboardAction.Paste && clipboardContents) {
    const z = currentDocument.pages[0].shapes.length + 1;
    const newObject = cloneDeep(clipboardContents);
    newObject.z = z;
    newObject.id = shortid.generate();

    if (newObject.type === "text") {
      addEditorStateToObject(newObject);
    }

    updatedState.currentDocument = {
      ...currentDocument,
      pages: [
        {
          ...currentDocument.pages[0],
          shapes: [...currentDocument.pages[0].shapes, newObject],
        },
      ],
    };

clone-deep

Recursively (deep) clone JavaScript native types, like Object, Array, RegExp, Date as well as primitives.

MIT
Latest version published 5 years ago

Package Health Score

71 / 100
Full package analysis

Popular clone-deep functions