How to use the array-move.mutate function in array-move

To help you get started, we’ve selected a few array-move 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 timmo001 / home-panel / src / Components / Main.tsx View on Github external
function handleUpdateConfig(path: any[], data: any) {
    let config = clone(props.config);
    if (path.length > 0) {
      // Set the new value
      const lastItem = path.pop();
      let secondLastItem = path.reduce((o, k) => (o[k] = o[k] || {}), config);
      if (Array.isArray(secondLastItem)) {
        if (data === undefined) secondLastItem.splice(lastItem, 1);
        else if (Array.isArray(data)) {
          arrayMove.mutate(secondLastItem, lastItem, lastItem + data[0]);
        } else if (isObject(data)) {
          const newValue = JSON.parse(JSON.stringify(data));
          if (!secondLastItem[lastItem]) secondLastItem[lastItem] = [];
          secondLastItem[lastItem] = newValue;
        }
      } else secondLastItem[lastItem] = data;
    } else config = data;
    props.handleConfigChange!(config);
    if (path.find((i: any) => i === 'theme'))
      props.handleSetTheme!(config.theme);
  }
github signalapp / Signal-Desktop / sticker-creator / store / ducks / stickers.ts View on Github external
handleAction(moveSticker, (state, { payload }) => {
      arrayMove.mutate(state.order, payload.oldIndex, payload.newIndex);
    }),
github timmo001 / home-panel / src / Components / Main.js View on Github external
handleMovePosition = (path, newPos) => {
    let config = clone(this.props.config);
    const lastItem = path.pop();
    let secondLastItem = path.reduce((o, k) => (o[k] = o[k] || {}), config);
    arrayMove.mutate(secondLastItem, lastItem, newPos);
    this.props.handleConfigChange(config);
    this.setState({
      editingGroup: undefined,
      editingCard: undefined
    });
  };

array-move

Move an array item to a different position

MIT
Latest version published 3 years ago

Package Health Score

56 / 100
Full package analysis

Popular array-move functions