@@ -5,7 +5,7 @@ import Menu from '../menu';
55import classNames from '../_util/classNames' ;
66import { SelectionCheckboxAllProps } from './interface' ;
77import BaseMixin from '../_util/BaseMixin' ;
8- import { defineComponent } from 'vue' ;
8+ import { computed , defineComponent } from 'vue' ;
99
1010function checkSelection ( {
1111 store,
@@ -17,7 +17,7 @@ function checkSelection({
1717} ) {
1818 return byDefaultChecked
1919 ? 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 ) ;
2121}
2222
2323function getIndeterminateState ( props ) {
@@ -53,7 +53,7 @@ function getIndeterminateState(props) {
5353 byDefaultChecked : true ,
5454 } ) ;
5555
56- if ( store . getState ( ) . selectionDirty ) {
56+ if ( store . selectionDirty ) {
5757 return someCheckedNotByDefaultChecked ;
5858 }
5959 return someCheckedNotByDefaultChecked || someCheckedByDefaultChecked ;
@@ -64,7 +64,7 @@ function getCheckState(props) {
6464 if ( ! data . length ) {
6565 return false ;
6666 }
67- if ( store . getState ( ) . selectionDirty ) {
67+ if ( store . selectionDirty ) {
6868 return checkSelection ( {
6969 ...props ,
7070 data,
@@ -94,29 +94,18 @@ export default defineComponent({
9494 inheritAttrs : false ,
9595 props : SelectionCheckboxAllProps ,
9696
97- setup ( ) {
97+ setup ( props ) {
9898 return {
9999 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+ } ) ,
109106 } ;
110107 } ,
111108
112- watch : {
113- propsSymbol : {
114- handler ( ) {
115- this . setCheckState ( this . $props ) ;
116- } ,
117- } ,
118- } ,
119-
120109 created ( ) {
121110 const { $props : props } = this ;
122111 this . defaultSelections = props . hideDefaultSelections
@@ -132,55 +121,11 @@ export default defineComponent({
132121 } ,
133122 ] ;
134123 } ,
135-
136- mounted ( ) {
137- this . subscribe ( ) ;
138- } ,
139-
140- beforeUnmount ( ) {
141- if ( this . unsubscribe ) {
142- this . unsubscribe ( ) ;
143- }
144- } ,
145124 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-
174125 handleSelectAllChange ( e ) {
175126 const { checked } = e . target ;
176127 this . $emit ( 'select' , checked ? 'all' : 'removeAll' , 0 , null ) ;
177128 } ,
178- subscribe ( ) {
179- const { store } = this ;
180- this . unsubscribe = store . subscribe ( ( ) => {
181- this . setCheckState ( this . $props ) ;
182- } ) ;
183- } ,
184129
185130 renderMenus ( selections ) {
186131 return selections . map ( ( selection , index ) => {
0 commit comments