@@ -40,6 +40,9 @@ export function create(
40
40
defineReadOnly ( this , '$store' , store ) ;
41
41
defineReadOnly ( this , '$update' , storeUpdate ) ;
42
42
defineReadOnly ( this , '$useAll' , ! ! opts . $useAll ) ;
43
+ defineReadOnly ( this , '$watchStoreChange' , function ( this : any , cb : any ) {
44
+ store . onChange ( cb , this ) ;
45
+ } ) ;
43
46
44
47
store . addInstance ( this ) ;
45
48
globalStore . update = this . $update ;
@@ -59,23 +62,25 @@ export function create(
59
62
}
60
63
61
64
if ( type === 'Component' ) {
65
+ hook ( opts , 'created' , function ( this : IPageExtenstion ) {
66
+ defineReadOnly ( this , '$store' , store ) ;
67
+ defineReadOnly ( this , '$update' , storeUpdate ) ;
68
+ defineReadOnly ( this , '$useAll' , ! ! opts . $useAll ) ;
69
+ defineReadOnly ( this , '$watchStoreChange' , function ( this : any , cb : any ) {
70
+ store . onChange ( cb , this ) ;
71
+ } ) ;
72
+ } ) ;
62
73
// Component.attached -> Page.onLoad -> Component.ready
63
- // 要在ready注册
74
+ // 获取当前页面路径要在ready注册
64
75
hook ( opts , 'ready' , function ( this : IPageExtenstion ) {
65
76
const curPage : IPageExtenstion = getPage ( ) as any ;
66
77
// @ts -ignore
67
78
this [ page ] = curPage ;
68
- if ( curPage . $store ) {
69
- this . globalStore = curPage . globalStore ;
70
- defineReadOnly ( this , '$store' , store ) ;
71
- defineReadOnly ( this , '$update' , storeUpdate ) ;
72
- defineReadOnly ( this , '$useAll' , ! ! opts . $useAll ) ;
73
-
74
- this . route = curPage . route ;
75
- store . addInstance ( this ) ;
76
- getInitState ( $store . data , opts . data , opts . $useAll ) ;
77
- this . setData ( opts . data ) ;
78
- }
79
+ this . globalStore = curPage . globalStore ;
80
+ this . route = curPage . route ;
81
+ store . addInstance ( this ) ;
82
+ getInitState ( $store . data , opts . data , opts . $useAll ) ;
83
+ this . setData ( opts . data ) ;
79
84
} ) ;
80
85
81
86
hook ( opts , 'detached' , function ( this : IPageExtenstion ) {
0 commit comments