MCPcopy
hub / github.com/midrender/revideo / compound

Function compound

packages/2d/src/lib/decorators/compound.ts:37–72  ·  view source on GitHub ↗
(entries: Record<string, string>)

Source from the content-addressed store, hash-verified

35 * corresponding property on the owner node.
36 */
37export function compound(entries: Record<string, string>): PropertyDecorator {
38 return (target, key) => {
39 const meta = getPropertyMetaOrCreate<any>(target, key);
40 meta.compound = true;
41 meta.compoundEntries = Object.entries(entries);
42
43 addInitializer(target, (instance: any) => {
44 if (!meta.parser) {
45 useLogger().error(`Missing parser decorator for "${key.toString()}"`);
46 return;
47 }
48
49 const initial = meta.default;
50 const parser = meta.parser.bind(instance);
51 const signalContext = new CompoundSignalContext(
52 meta.compoundEntries.map(([key, property]) => {
53 const signal = new SignalContext(
54 modify(initial, value => parser(value)[key]),
55 <any>map,
56 instance,
57 undefined,
58 makeSignalExtensions(undefined, instance, property),
59 ).toSignal();
60 return [key, signal];
61 }),
62 parser,
63 initial,
64 meta.interpolationFunction ?? deepLerp,
65 instance,
66 makeSignalExtensions(meta, instance, <string>key),
67 );
68
69 instance[key] = signalContext.toSignal();
70 });
71 };
72}

Callers 3

KnotClass · 0.90
spacingSignalFunction · 0.90
vector2SignalFunction · 0.90

Calls 10

toSignalMethod · 0.95
getPropertyMetaOrCreateFunction · 0.90
addInitializerFunction · 0.90
useLoggerFunction · 0.90
modifyFunction · 0.90
makeSignalExtensionsFunction · 0.90
parserFunction · 0.85
errorMethod · 0.45
toStringMethod · 0.45
toSignalMethod · 0.45

Tested by

no test coverage detected