()
| 111 | * ``` |
| 112 | */ |
| 113 | export function signal<T>(): PropertyDecorator { |
| 114 | return (target: any, key) => { |
| 115 | // FIXME property metadata is not inherited |
| 116 | // Consider retrieving it inside the initializer using the instance and not |
| 117 | // the class. |
| 118 | const meta = getPropertyMetaOrCreate<T>(target, key); |
| 119 | addInitializer(target, (instance: any) => { |
| 120 | let initial: SignalValue<T> = meta.default!; |
| 121 | const defaultMethod = instance[`getDefault${capitalize(key as string)}`]; |
| 122 | if (defaultMethod) { |
| 123 | initial = () => defaultMethod.call(instance, meta.default); |
| 124 | } |
| 125 | |
| 126 | const signal = new SignalContext<T, T, any>( |
| 127 | initial, |
| 128 | meta.interpolationFunction ?? deepLerp, |
| 129 | instance, |
| 130 | meta.parser?.bind(instance), |
| 131 | makeSignalExtensions(meta, instance, <string>key), |
| 132 | ); |
| 133 | instance[key] = signal.toSignal(); |
| 134 | }); |
| 135 | }; |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * Create an initial signal value decorator. |
no test coverage detected