Skip to main content

@novorender/web_app / modifyRenderState

Function: modifyRenderState()

function modifyRenderState(state, changes): RenderState

Create a new copy of render state with specified modifications.

Parameters

ParameterTypeDescription
stateRenderStateThe baseline render state.
changesRecursivePartial<RenderState>The changes to apply to the baseline state.

Returns

RenderState

A new render state with all the changes applied.

Remarks

This function helps you modify render state in an immutable fashion, which is key for correct and efficient render updates. More specifically, it leaves all the unchanged sub objects of the returned render state alone. This enables checking for changes using strict equality. Making unnecessary copies of unchanged sub objects will reduce render/update performance.

This function also performs some basic validation of the new state changes, at a slight performance cost. If validation fails, it will throw an error of Error objects, one per problem. To mitigate this overhead, accumulating all the changes for a frame into a single object may be beneficial. The mergeRecursive function may be useful in for this.

Defined in

@novorender/core3d/state/modify.ts:22