Search
Loading...
Skip to content

Function: _createTrackedProperty

function _createTrackedProperty<T, U>(
getter,
setter,
source,
options?): _ReactiveProperty<T>;

Creates a reactive property that tracks a source and updates based on a getter/setter.

This is useful for wrapping engine properties or complex state logic.

Type Parameters#

Type ParameterDefault type
T-
Uany

Parameters#

ParameterTypeDescription
getter() => TFunction to get current value
setter(value) => voidFunction to update value
source(listener) => _UnsubscribeSource to track for updates
options?Pick<_ReactivePropertyOptions<T>, "equals">Configuration options

Returns#

_ReactiveProperty<T>

A reactive property

Example#

const settings = createTrackedProperty(
// Getter
() => {
const camera = engine.block.findByType('camera')[0];
return {
width: engine.block.getFloat(camera, 'camera/resolution/width'),
height: engine.block.getFloat(camera, 'camera/resolution/height')
};
},
// Setter
({ width, height }) => {
const camera = engine.block.findByType('camera')[0];
engine.block.setFloat(camera, 'camera/resolution/width', width);
engine.block.setFloat(camera, 'camera/resolution/height', height);
},
// Source to track
onCameraUpdated,
// Options
{ equals: isEqual }
);