createEffectImplementation()v4.0.540
Types the state of one backend implementation for createEffect(). Each implementation can have a different state type.
my-effect.tsimport {createEffect ,createEffectImplementation } from 'remotion'; typeParams = {amount ?: number}; constcanvas2d =createEffectImplementation <Params ,CanvasRenderingContext2D >({setup : (target ) => { constcontext =target .getContext ('2d'); if (!context ) throw newError ('2D canvas is unavailable'); returncontext ; },apply : ({source ,state ,width ,height ,params }) => {state .clearRect (0, 0,width ,height );state .globalAlpha =params .amount ?? 1;state .drawImage (source , 0, 0,width ,height ); },cleanup : () => {}, }); export constopacity =createEffect <Params >({type : 'example/opacity',label : 'Opacity',documentationLink : null,schema : {},validateParams : () => {},calculateKey : (params ) =>String (params .amount ?? 1),implementations : { '2d':canvas2d }, });
Arguments
setup
Receives the target canvas and returns the implementation's state.
apply
Transforms the source into the target using the state returned by setup. See apply parameters.
cleanup
Releases resources owned by this implementation. Do not destroy the shared WebGPU device.
Return value
An implementation accepted by the implementations field of createEffect().