( target: (this: This) => Return, _: ClassGetterDecoratorContext<This, Return> )
| 27 | } |
| 28 | |
| 29 | export function derived<This, Return>( |
| 30 | target: (this: This) => Return, |
| 31 | _: ClassGetterDecoratorContext<This, Return> |
| 32 | ) { |
| 33 | const map: WeakMap<any, Signal<Return>> = new WeakMap(); |
| 34 | |
| 35 | return function (this: This): Return { |
| 36 | let result = map.get(this); |
| 37 | |
| 38 | if (!result) { |
| 39 | result = computed(target.bind(this)); |
| 40 | |
| 41 | map.set(this, result); |
| 42 | } |
| 43 | |
| 44 | return result.value; |
| 45 | }; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Make a field enumerable (or non‑enumerable) on every instance. |