@@ -6,10 +6,14 @@ import type { IRelatedPathValue } from './data-tracer'
6
6
7
7
const deepClone = rfdc ( { proto : true } )
8
8
9
+ interface BehaviorData {
10
+ '_computedWatchInit' : ComputedWatchInitStatus ;
11
+ [ k : string ] : any ;
12
+ }
9
13
10
14
interface BehaviorExtend {
11
15
// original
12
- data : Record < string , any > ;
16
+ data : BehaviorData ;
13
17
setData ( d : Record < string , any > ) : void ;
14
18
_computedWatchInfo : Record < string , ComputedWatchInfo > ;
15
19
}
@@ -26,18 +30,23 @@ interface ComputedWatchInfo {
26
30
_triggerFromComputedAttached : Record < string , boolean > ;
27
31
}
28
32
33
+ enum ComputedWatchInitStatus {
34
+ CREATED ,
35
+ ATTACHED
36
+ }
37
+
29
38
let computedWatchDefIdInc = 0
30
39
31
40
export const behavior = Behavior ( {
32
41
lifetimes : {
33
42
attached ( this : BehaviorExtend ) {
34
43
this . setData ( {
35
- _computedWatchInit : 'attached' ,
44
+ _computedWatchInit : ComputedWatchInitStatus . ATTACHED ,
36
45
} )
37
46
} ,
38
47
created ( this : BehaviorExtend ) {
39
48
this . setData ( {
40
- _computedWatchInit : 'created' ,
49
+ _computedWatchInit : ComputedWatchInitStatus . CREATED ,
41
50
} )
42
51
} ,
43
52
} ,
@@ -51,7 +60,7 @@ export const behavior = Behavior({
51
60
fields : '_computedWatchInit' ,
52
61
observer ( this : BehaviorExtend ) {
53
62
const status = this . data . _computedWatchInit
54
- if ( status === 'created' ) {
63
+ if ( status === ComputedWatchInitStatus . CREATED ) {
55
64
// init data fields
56
65
const computedWatchInfo = {
57
66
computedUpdaters : [ ] ,
@@ -74,7 +83,7 @@ export const behavior = Behavior({
74
83
computedWatchInfo . watchCurVal [ watchPath ] = curVal
75
84
} )
76
85
}
77
- } else if ( status === 'attached' ) {
86
+ } else if ( status === ComputedWatchInitStatus . ATTACHED ) {
78
87
// handling computed
79
88
// 1. push to initFuncs
80
89
// 2. push to computedUpdaters
0 commit comments