Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'array-move' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
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 ...
}
}
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;
}
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();
};
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);
}
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 ] });
}
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 ] });
}
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);
}
onSortEnd = ({ oldIndex, newIndex }) => {
const newValue = arrayMove(this.state.friendsData, oldIndex, newIndex)
this.setFriendsList(newValue)
}
onSortEnd = ({ oldIndex, newIndex }: { oldIndex: number; newIndex: number }) => {
const skus = arrayMove(this.props.skus, oldIndex, newIndex);
this.props.onChange(skus);
};
this.setState(({cols}) => ({
cols: arrayMove(cols, oldIndex, newIndex),
}));
};