@@ -5,7 +5,7 @@ import Menu from '../menu';
5
5
import classNames from '../_util/classNames' ;
6
6
import { SelectionCheckboxAllProps } from './interface' ;
7
7
import BaseMixin from '../_util/BaseMixin' ;
8
- import { defineComponent } from 'vue' ;
8
+ import { computed , defineComponent } from 'vue' ;
9
9
10
10
function checkSelection ( {
11
11
store,
@@ -17,7 +17,7 @@ function checkSelection({
17
17
} ) {
18
18
return byDefaultChecked
19
19
? data [ type ] ( ( item , i ) => getCheckboxPropsByItem ( item , i ) . defaultChecked )
20
- : data [ type ] ( ( item , i ) => store . getState ( ) . selectedRowKeys . indexOf ( getRecordKey ( item , i ) ) >= 0 ) ;
20
+ : data [ type ] ( ( item , i ) => store . selectedRowKeys . indexOf ( getRecordKey ( item , i ) ) >= 0 ) ;
21
21
}
22
22
23
23
function getIndeterminateState ( props ) {
@@ -53,7 +53,7 @@ function getIndeterminateState(props) {
53
53
byDefaultChecked : true ,
54
54
} ) ;
55
55
56
- if ( store . getState ( ) . selectionDirty ) {
56
+ if ( store . selectionDirty ) {
57
57
return someCheckedNotByDefaultChecked ;
58
58
}
59
59
return someCheckedNotByDefaultChecked || someCheckedByDefaultChecked ;
@@ -64,7 +64,7 @@ function getCheckState(props) {
64
64
if ( ! data . length ) {
65
65
return false ;
66
66
}
67
- if ( store . getState ( ) . selectionDirty ) {
67
+ if ( store . selectionDirty ) {
68
68
return checkSelection ( {
69
69
...props ,
70
70
data,
@@ -94,29 +94,18 @@ export default defineComponent({
94
94
inheritAttrs : false ,
95
95
props : SelectionCheckboxAllProps ,
96
96
97
- setup ( ) {
97
+ setup ( props ) {
98
98
return {
99
99
defaultSelections : [ ] ,
100
- unsubscribe : null ,
101
- } ;
102
- } ,
103
- data ( ) {
104
- const { $props : props } = this ;
105
-
106
- return {
107
- checked : getCheckState ( props ) ,
108
- indeterminate : getIndeterminateState ( props ) ,
100
+ checked : computed ( ( ) => {
101
+ return getCheckState ( props ) ;
102
+ } ) ,
103
+ indeterminate : computed ( ( ) => {
104
+ return getIndeterminateState ( props ) ;
105
+ } ) ,
109
106
} ;
110
107
} ,
111
108
112
- watch : {
113
- propsSymbol : {
114
- handler ( ) {
115
- this . setCheckState ( this . $props ) ;
116
- } ,
117
- } ,
118
- } ,
119
-
120
109
created ( ) {
121
110
const { $props : props } = this ;
122
111
this . defaultSelections = props . hideDefaultSelections
@@ -132,55 +121,11 @@ export default defineComponent({
132
121
} ,
133
122
] ;
134
123
} ,
135
-
136
- mounted ( ) {
137
- this . subscribe ( ) ;
138
- } ,
139
-
140
- beforeUnmount ( ) {
141
- if ( this . unsubscribe ) {
142
- this . unsubscribe ( ) ;
143
- }
144
- } ,
145
124
methods : {
146
- checkSelection ( props , data , type , byDefaultChecked ) {
147
- const { store, getCheckboxPropsByItem, getRecordKey } = props || this . $props ;
148
- // type should be 'every' | 'some'
149
- if ( type === 'every' || type === 'some' ) {
150
- return byDefaultChecked
151
- ? data [ type ] ( ( item , i ) => getCheckboxPropsByItem ( item , i ) . defaultChecked )
152
- : data [ type ] (
153
- ( item , i ) => store . getState ( ) . selectedRowKeys . indexOf ( getRecordKey ( item , i ) ) >= 0 ,
154
- ) ;
155
- }
156
- return false ;
157
- } ,
158
-
159
- setCheckState ( props ) {
160
- const checked = getCheckState ( props ) ;
161
- const indeterminate = getIndeterminateState ( props ) ;
162
- this . setState ( prevState => {
163
- const newState : any = { } ;
164
- if ( indeterminate !== prevState . indeterminate ) {
165
- newState . indeterminate = indeterminate ;
166
- }
167
- if ( checked !== prevState . checked ) {
168
- newState . checked = checked ;
169
- }
170
- return newState ;
171
- } ) ;
172
- } ,
173
-
174
125
handleSelectAllChange ( e ) {
175
126
const { checked } = e . target ;
176
127
this . $emit ( 'select' , checked ? 'all' : 'removeAll' , 0 , null ) ;
177
128
} ,
178
- subscribe ( ) {
179
- const { store } = this ;
180
- this . unsubscribe = store . subscribe ( ( ) => {
181
- this . setCheckState ( this . $props ) ;
182
- } ) ;
183
- } ,
184
129
185
130
renderMenus ( selections ) {
186
131
return selections . map ( ( selection , index ) => {
0 commit comments