(entries: Record<string, string>)
| 35 | * corresponding property on the owner node. |
| 36 | */ |
| 37 | export 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 | } |
no test coverage detected