From e2d329810f53fd4e6d72e8503c0d6f79d03d7c91 Mon Sep 17 00:00:00 2001 From: Rainer Simon Date: Sun, 21 Feb 2021 08:29:16 +0100 Subject: [PATCH] Added onUpsertBody convenience method --- src/editor/Editor.jsx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/editor/Editor.jsx b/src/editor/Editor.jsx index da365a8..c21ba68 100644 --- a/src/editor/Editor.jsx +++ b/src/editor/Editor.jsx @@ -95,6 +95,11 @@ const Editor = props => { }) ); + // Just a convenience shorthand + const onUpsertBody = (maybePrevious, updated) => maybePrevious ? + onUpdateBody(maybePrevious, updated) : + onAppendBody(updated); + const onSetProperty = (property, value) => { // A list of properties the user is NOT allowed to set const isForbidden = [ '@context', 'id', 'type', 'body', 'target' ].includes(property); @@ -152,6 +157,7 @@ const Editor = props => { onAppendBody, onUpdateBody, onRemoveBody, + onUpsertBody, onSetProperty, onSaveAndClose: onOk })