effect
effect(
effect):object
Defined in: behavior.types.action.ts:203
Performs a side effect.
Use effect for logging, analytics, async operations, or other side effects.
Note: Using effect alone (without forward) will stop event
propagation. To perform a side effect while allowing the default Behavior
to continue, combine effect with forward.
The effect callback receives a send function that can be used to send
events back to the editor asynchronously.
Parameters
Section titled “Parameters”effect
Section titled “effect”(payload) => void
Returns
Section titled “Returns”object
effect()
Section titled “effect()”effect: (
payload) =>void
Parameters
Section titled “Parameters”payload
Section titled “payload”(event) => void
Send a Behavior Event back into the Editor.
Example
defineBehavior({ on: '...', actions: [ () => [ effect(({send}) => { doSomethingAsync() .then(() => { send({ type: '...', }) }) }) ], ],})Returns
Section titled “Returns”void
type:
"effect"
Example
Section titled “Example”// Log events while preserving default BehaviordefineBehavior({ on: 'insert.text', actions: [({event}) => [effect(() => console.log(event)), forward(event)]],})
// Effect alone stops propagation (native event is cancelled)defineBehavior({ on: 'keyboard.keydown', actions: [() => [effect(() => console.log('key pressed'))]],})
// Async effect that sends an event laterdefineBehavior({ on: 'custom.save', actions: [ () => [ effect(async ({send}) => { await saveDocument() send({type: 'custom.saved'}) }), ], ],})