Documentation / @zerotal/flow / index / registerSynth
Function: registerSynth()
registerSynth(
synth):void
Defined in: flow/src/synths/index.ts:58
Register a synthesizer so its type can cross the wire in snapshots. Newly registered synths are tried first, so a later registration can override an earlier (built-in) match.
Parameters
synth
The Synth to add to the registry.
Returns
void
Example
class Money { constructor(public cents: number, public currency: string) {} }
registerSynth({
key: "money",
match: (v): v is Money => v instanceof Money,
dehydrate: (v, meta) => { meta.cur = v.currency; return v.cents; },
hydrate: (data, meta) => new Money(data as number, meta.cur as string),
});