fn
createGenericProjection
v0.0.15testeddemoCreate a reusable projection between two arbitrary (non-numeric) domains using a custom projector. The returned factory turns a reactive input into a `ComputedRef` of the projected value, so the same projection can be applied to many inputs without re-resolving the domains each time.
Example
ts
const project = createGenericProjection(
[0, 10],
['a', 'z'],
(n, from, to) => to[0] + Math.round((n - from[0]) / (from[1] - from[0]) * (to[1].charCodeAt(0) - to[0].charCodeAt(0))),
);Demo
Loading demo…
Signature
ts
export function createGenericProjection<F = number, T = number>(
fromDomain: MaybeRefOrGetter<readonly [F, F]>,
toDomain: MaybeRefOrGetter<readonly [T, T]>,
projector: ProjectorFunction<F, T>,
): UseProjection<F, T>{ ... }Type Parameters
F= numberT= numberParameters
| Parameter | Type | Description |
|---|---|---|
fromDomain | MaybeRefOrGetter<readonly [F, F]> | The source domain `[start, end]` |
toDomain | MaybeRefOrGetter<readonly [T, T]> | The target domain `[start, end]` |
projector | ProjectorFunction<F, T> | The pure mapping function |
Returns
UseProjection<F, T>A factory that projects a reactive input into a `ComputedRef`