@@ -17,7 +17,7 @@ export class Computed<
17
17
public config : ComputedConfigInterface ;
18
18
19
19
// Caches whether the compute function is async
20
- private isComuteFunctionAsync ! : boolean ;
20
+ public isComputeFunctionAsync ! : boolean ;
21
21
22
22
// Function to compute the Computed Class value
23
23
private _computeFunction ! : ComputeFunctionType < ComputedValueType > ;
@@ -29,7 +29,7 @@ export class Computed<
29
29
30
30
// Helper property to check whether an unknown instance is a Computed,
31
31
// without importing the Computed itself for using 'instanceof' (Treeshaking support)
32
- public isComputed = true ;
32
+ public readonly isComputed = true ;
33
33
34
34
/**
35
35
* A Computed is an extension of the State Class
@@ -70,7 +70,7 @@ export class Computed<
70
70
71
71
config = defineConfig ( config , {
72
72
computedDeps : [ ] ,
73
- autodetect : ! this . isComuteFunctionAsync ,
73
+ autodetect : ! this . isComputeFunctionAsync , // 'isComputeFunctionAsync' will be set by assigning 'computeFunction'
74
74
} ) ;
75
75
this . agileInstance = ( ) => agileInstance ;
76
76
this . config = {
@@ -106,12 +106,14 @@ export class Computed<
106
106
* Assigns a new compute function to the Computed State
107
107
* and checks whether it's async.
108
108
*
109
- * @public
109
+ * To update the compute function properly use 'updateComputeFunction()'!
110
+ *
111
+ * @internal
110
112
* @param value - New compute function.
111
113
*/
112
114
public set computeFunction ( value : ComputeFunctionType < ComputedValueType > ) {
113
115
this . _computeFunction = value ;
114
- this . isComuteFunctionAsync = isAsyncFunction ( value ) ;
116
+ this . isComputeFunctionAsync = isAsyncFunction ( value ) ;
115
117
}
116
118
117
119
/**
@@ -180,25 +182,25 @@ export class Computed<
180
182
public async compute (
181
183
config : ComputeConfigInterface = { }
182
184
) : Promise < ComputedValueType > {
183
- if ( config . autodetect && this . isComuteFunctionAsync ) {
184
- logCodeManager . log ( '19:00:01 ' ) ;
185
+ if ( config . autodetect && this . isComputeFunctionAsync ) {
186
+ logCodeManager . log ( '19:02:00 ' ) ;
185
187
}
186
- return this . isComuteFunctionAsync
188
+ return this . isComputeFunctionAsync
187
189
? this . computeAsync ( )
188
190
: this . computeSync ( config ) ;
189
191
}
190
192
191
193
/**
192
194
* Recomputes the value and ingests it into the runtime.
193
195
*
194
- * @public
196
+ * @internal
195
197
* @param config - Configuration object
196
198
*/
197
199
public computeAndIngest (
198
200
// https://www.reddit.com/r/learnjavascript/comments/q5rvux/pass_parent_config_object_directly_into_child/
199
201
config : StateIngestConfigInterface & ComputeConfigInterface = { }
200
202
) {
201
- if ( this . isComuteFunctionAsync ) {
203
+ if ( this . isComputeFunctionAsync ) {
202
204
this . computeAsync ( ) . then ( ( result ) => {
203
205
this . observers [ 'value' ] . ingestValue ( result , config ) ;
204
206
} ) ;
@@ -312,7 +314,7 @@ export interface CreateComputedConfigInterface<ComputedValueType = any>
312
314
*
313
315
* @default undefined
314
316
*/
315
- initialValue ?: ComputedValueType ;
317
+ initialValue ?: Awaited < ComputedValueType > ; // https://stackoverflow.com/questions/48944552/typescript-how-to-unwrap-remove-promise-from-a-type
316
318
}
317
319
318
320
export interface ComputedConfigInterface {
0 commit comments