Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function safeBuildPatches(draft) {
let changes = []
try {
finishDraft(draft, patches => changes.push(...patches))
} catch (error) {
// or (if it wasn't a draft) replace it
if (error.message !== "First argument to `finishDraft` must be a draft returned by `createDraft`") {
throw error
}
return null
}
return changes
}
protected changeState(effect: Function, state: any, action: ActionResponseHandle | ActionNormalHandle): any {
if (isDraftable(state)) {
const draft = createDraft(state);
const responseDraft = effect(draft, action);
if (responseDraft === undefined) {
state = finishDraft(draft);
} else if (isDraft(responseDraft)) {
state = finishDraft(responseDraft);
} else {
state = responseDraft;
}
} else {
state = effect(state, action);
if (state === undefined) {
throw new StateReturnRequiredError(action.type);
}
}
return state;
}
}
if (selection) {
for (const [point, key] of Range.points(selection)) {
selection[key] = Point.transform(point, op)!
}
}
break
}
}
editor.children = finishDraft(editor.children) as Node[]
if (selection) {
editor.selection = isDraft(selection)
? (finishDraft(selection) as Range)
: selection
} else {
editor.selection = null
}
},
}
}
parent.children.splice(index + 1, 0, newNode)
if (selection) {
for (const [point, key] of Range.points(selection)) {
selection[key] = Point.transform(point, op)!
}
}
break
}
}
editor.children = finishDraft(editor.children) as Node[]
if (selection) {
editor.selection = isDraft(selection)
? (finishDraft(selection) as Range)
: selection
} else {
editor.selection = null
}
},
protected changeState(effect: Function, state: any, action: ActionResponseHandle | ActionNormalHandle): any {
if (isDraftable(state)) {
const draft = createDraft(state);
const responseDraft = effect(draft, action);
if (responseDraft === undefined) {
state = finishDraft(draft);
} else if (isDraft(responseDraft)) {
state = finishDraft(responseDraft);
} else {
state = responseDraft;
}
} else {
state = effect(state, action);
if (state === undefined) {
throw new StateReturnRequiredError(action.type);
}
}
return state;
}
}
}
}
parent.children.splice(index + 1, 0, newNode)
if (selection) {
for (const [point, key] of Range.points(selection)) {
selection[key] = Point.transform(point, op)!
}
}
break
}
}
editor.children = finishDraft(editor.children) as Node[]
if (selection) {
editor.selection = isDraft(selection)
? (finishDraft(selection) as Range)
: selection
} else {
editor.selection = null
}
},
}
if (selection) {
for (const [point, key] of Range.points(selection)) {
selection[key] = Point.transform(point, op)!
}
}
break
}
}
editor.children = finishDraft(editor.children) as Node[]
if (selection) {
editor.selection = isDraft(selection)
? (finishDraft(selection) as Range)
: selection
} else {
editor.selection = null
}
},
}