1
1
import { isDestroyed , isDestroying } from '@ember/destroyable' ;
2
+ import { get as consume , notifyPropertyChange as dirty } from '@ember/object' ;
2
3
import { waitForPromise } from '@ember/test-waiters' ;
3
4
4
5
import { LifecycleResource } from './lifecycle' ;
@@ -7,6 +8,8 @@ import type { ArgsWrapper } from '../types';
7
8
8
9
export const FUNCTION_TO_RUN = Symbol ( 'FUNCTION TO RUN' ) ;
9
10
11
+ const SECRET_VALUE = '___ Secret Value ___' ;
12
+
10
13
// type UnwrapAsync<T> = T extends Promise<infer U> ? U : T;
11
14
// type GetReturn<T extends () => unknown> = UnwrapAsync<ReturnType<T>>;
12
15
export type ResourceFn < Return = unknown , Args extends unknown [ ] = unknown [ ] > = (
@@ -24,9 +27,15 @@ export class FunctionRunner<
24
27
Fn extends ResourceFn < Return , Args > = ResourceFn < Return , Args >
25
28
> extends LifecycleResource < BaseArgs < Args > > {
26
29
// Set when using useResource
27
- declare [ FUNCTION_TO_RUN ] : Fn ;
30
+ protected declare [ FUNCTION_TO_RUN ] : Fn ;
31
+ private declare [ SECRET_VALUE ] : Return | undefined ;
32
+
33
+ get value ( ) : Return | undefined {
34
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
35
+ consume ( this , SECRET_VALUE as any ) ;
28
36
29
- declare value : Return | undefined ;
37
+ return this [ SECRET_VALUE ] ;
38
+ }
30
39
31
40
get funArgs ( ) {
32
41
return this . args . positional ;
@@ -49,7 +58,8 @@ export class FunctionRunner<
49
58
return ;
50
59
}
51
60
52
- this . value = value ;
61
+ this [ SECRET_VALUE ] = value ;
62
+ dirty ( this , SECRET_VALUE ) ;
53
63
} ;
54
64
55
65
waitForPromise ( result ) ;
@@ -60,6 +70,6 @@ export class FunctionRunner<
60
70
}
61
71
}
62
72
63
- this . value = result ;
73
+ this [ SECRET_VALUE ] = result ;
64
74
}
65
75
}
0 commit comments