How to use array-move - 10 common examples

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 thiagodp / concordialang / modules / testscenario / StepUtil.ts View on Github external
if ( NodeTypes.STEP_GIVEN === step.nodeType
                || ( NodeTypes.STEP_AND == step.nodeType && true === lastWasGiven ) ) {

                const hasPrecondition = isDefined( step.nlpResult )
                    && nlpUtil.hasEntityNamed( Entities.STATE, step.nlpResult );

                if ( hasPrecondition ) {

                    // Does not have prior GIVEN ? -> Make it a GIVEN
                    if ( preconditionCount < 1 ) {
                        newSteps[ index ].nodeType = NodeTypes.STEP_GIVEN;
                    }

                    if ( preconditionCount != index ) {
                        arrayMove.mut( newSteps, index, preconditionCount );
                    }

                    // Is the next step an AND step ?
                    if ( index + 1 < stepCount && newSteps[ index + 1 ].nodeType === NodeTypes.STEP_AND ) {
                        let nextStep = newSteps[ index + 1 ];
                        // Make it a GIVEN step
                        nextStep.nodeType = NodeTypes.STEP_GIVEN;
                        // Change the sentence content!
                        if ( !! nextStep.content ) {
                            const stepAndKeyword: string = ( keywords.stepAnd || [ 'and' ] )[ 0 ];
                            const stepGivenKeyword: string = ( keywords.stepGiven || [ 'given' ] )[ 0 ];
                            const regex = new RegExp( stepAndKeyword, 'i' );
                            nextStep.content = nextStep.content.replace( regex, convertCase( stepGivenKeyword, CaseType.PASCAL ) ); // Given ...
                        }
                    }
github thiagodp / concordialang / dist / modules / testscenario / StepUtil.js View on Github external
let lastWasGiven = null;
        let index = 0, preconditionCount = 0;
        const stepCount = steps.length;
        let newSteps = deepcopy(steps); // << important
        for (let step of steps) {
            if (NodeTypes_1.NodeTypes.STEP_GIVEN === step.nodeType
                || (NodeTypes_1.NodeTypes.STEP_AND == step.nodeType && true === lastWasGiven)) {
                const hasPrecondition = TypeChecking_1.isDefined(step.nlpResult)
                    && nlpUtil.hasEntityNamed(nlp_1.Entities.STATE, step.nlpResult);
                if (hasPrecondition) {
                    // Does not have prior GIVEN ? -> Make it a GIVEN
                    if (preconditionCount < 1) {
                        newSteps[index].nodeType = NodeTypes_1.NodeTypes.STEP_GIVEN;
                    }
                    if (preconditionCount != index) {
                        arrayMove.mut(newSteps, index, preconditionCount);
                    }
                    // Is the next step an AND step ?
                    if (index + 1 < stepCount && newSteps[index + 1].nodeType === NodeTypes_1.NodeTypes.STEP_AND) {
                        let nextStep = newSteps[index + 1];
                        // Make it a GIVEN step
                        nextStep.nodeType = NodeTypes_1.NodeTypes.STEP_GIVEN;
                        // Change the sentence content!
                        if (!!nextStep.content) {
                            const stepAndKeyword = (keywords.stepAnd || ['and'])[0];
                            const stepGivenKeyword = (keywords.stepGiven || ['given'])[0];
                            const regex = new RegExp(stepAndKeyword, 'i');
                            nextStep.content = nextStep.content.replace(regex, CaseConversor_1.convertCase(stepGivenKeyword, CaseType_1.CaseType.PASCAL)); // Given ...
                        }
                    }
                    ++preconditionCount;
                }
github clauderic / react-sortable-hoc / examples / react-virtualized.js View on Github external
onSortEnd = ({oldIndex, newIndex}) => {
    if (oldIndex === newIndex) {
      return;
    }

    const {items} = this.state;

    this.setState({
      items: arrayMove(items, oldIndex, newIndex),
    });

    // We need to inform React Virtualized that the items have changed heights
    // This can either be done by imperatively calling the recomputeRowHeights and
    // forceUpdate instance methods on the `List` ref, or by passing an additional prop
    // to List that changes whenever the order changes to force it to re-render
    this.List.recomputeRowHeights();
    this.List.forceUpdate();
  };
github breuerfelix / instapy-gui / src / sites / configuration / cards / jobs.jsx View on Github external
moveJob = async (job, direction) => {
		// TODO only move job if ALL jobs are valid !!
		// TODO otherwise some garbage data might be saved into those variables
		// TODO or make a new endpoint which only moves the job, and does only change the pos

		const { jobs } = this.state;
		const idx = jobs.findIndex(x => x._id.$oid == job._id.$oid);

		if (idx == -1) raiseError('could not locate job: ' + job);

		arrayMove.mut(jobs, idx, idx + direction);
		this.setState({ jobs });

		// update all jobs since positioning changed
		const updated_jobs = await ConfigService.updateJobs(jobs);
		this.setJobs(updated_jobs);
	}
github breuerfelix / king-bot-api / frontend / features / building_queue.jsx View on Github external
move_down = building => {
		const queues = this.state.queue;
		var idx = queues.indexOf(building);
		if (idx != -1) {
			arrayMove.mut(queues, idx, idx + 1); // The second parameter is the number of elements to remove.
		}

		this.setState({ queue: [ ...queues ] });
	}
github breuerfelix / king-bot-api / frontend / features / building_queue.jsx View on Github external
move_up = building => {
		const queues = this.state.queue;
		var idx = queues.indexOf(building);
		if (idx != -1) {
			arrayMove.mut(queues, idx, idx - 1); // The second parameter is the number of elements to remove.
		}

		this.setState({ queue: [ ...queues ] });
	}
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 fanfoujs / space-fanfou / src / features / favorite-fanfouers / home@page.js View on Github external
onSortEnd = ({ oldIndex, newIndex }) => {
      const newValue = arrayMove(this.state.friendsData, oldIndex, newIndex)

      this.setFriendsList(newValue)
    }
github contentful / extensions / lib / shared-sku-app / src / Editor / SortableComponent.tsx View on Github external
onSortEnd = ({ oldIndex, newIndex }: { oldIndex: number; newIndex: number }) => {
    const skus = arrayMove(this.props.skus, oldIndex, newIndex);
    this.props.onChange(skus);
  };
github clauderic / react-sortable-hoc / examples / react-virtualized-table-columns.js View on Github external
this.setState(({cols}) => ({
      cols: arrayMove(cols, oldIndex, newIndex),
    }));
  };

array-move

Move an array item to a different position

MIT
Latest version published 1 year ago

Package Health Score

62 / 100
Full package analysis

Popular array-move functions