Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async _handleSortEnd(results: {
oldIndex: number,
newIndex: number,
collection: Array,
}) {
const { oldIndex, newIndex } = results;
if (newIndex === oldIndex) {
return;
}
const { subEnvironments } = this.state;
const newSubEnvironments = arrayMove(subEnvironments, oldIndex, newIndex);
this.setState({ subEnvironments: newSubEnvironments });
// Do this last so we don't block the sorting
db.bufferChanges();
for (let i = 0; i < newSubEnvironments.length; i++) {
const environment = newSubEnvironments[i];
await this._updateEnvironment(environment, { metaSortKey: i }, false);
}
db.flushChanges();
}