@@ -2,7 +2,6 @@ import VcTable, { INTERNAL_COL_DEFINE } from '../vc-table';
2
2
import classNames from 'classnames' ;
3
3
import shallowEqual from 'shallowequal' ;
4
4
import FilterDropdown from './filterDropdown' ;
5
- import createStore from './createStore' ;
6
5
import SelectionBox from './SelectionBox' ;
7
6
import SelectionCheckboxAll from './SelectionCheckboxAll' ;
8
7
import Column from './Column' ;
@@ -21,6 +20,7 @@ import defaultLocale from '../locale-provider/default';
21
20
import warning from '../_util/warning' ;
22
21
import scrollTo from '../_util/scrollTo' ;
23
22
import TransButton from '../_util/transButton' ;
23
+ import Vue from 'vue' ;
24
24
25
25
function noop ( ) { }
26
26
@@ -112,6 +112,14 @@ export default {
112
112
Column,
113
113
ColumnGroup,
114
114
mixins : [ BaseMixin ] ,
115
+ inject : {
116
+ configProvider : { default : ( ) => ConfigConsumerProps } ,
117
+ } ,
118
+ provide ( ) {
119
+ return {
120
+ store : this . store ,
121
+ } ;
122
+ } ,
115
123
props : initDefaultProps ( TableProps , {
116
124
dataSource : [ ] ,
117
125
useFixedHeader : false ,
@@ -127,26 +135,15 @@ export default {
127
135
childrenColumnName : 'children' ,
128
136
} ) ,
129
137
130
- inject : {
131
- configProvider : { default : ( ) => ConfigConsumerProps } ,
132
- } ,
133
- // CheckboxPropsCache: {
134
- // [key: string]: any;
135
- // };
136
- // store: Store;
137
- // columns: ColumnProps<T>[];
138
- // components: TableComponents;
139
-
140
138
data ( ) {
141
- // this.columns = props.columns || normalizeColumns(props.children)
142
139
const props = getOptionProps ( this ) ;
143
140
warning (
144
141
! props . expandedRowRender || ! ( 'scroll' in props ) || ! props . scroll . x ,
145
142
'`expandedRowRender` and `scroll` are not compatible. Please use one of them at one time.' ,
146
143
) ;
147
144
this . CheckboxPropsCache = { } ;
148
145
149
- this . store = createStore ( {
146
+ this . store = Vue . observable ( {
150
147
selectedRowKeys : getRowSelection ( this . $props ) . selectedRowKeys || [ ] ,
151
148
selectionDirty : false ,
152
149
} ) ;
@@ -179,26 +176,20 @@ export default {
179
176
rowSelection : {
180
177
handler ( val , oldVal ) {
181
178
if ( val && 'selectedRowKeys' in val ) {
182
- this . store . setState ( {
183
- selectedRowKeys : val . selectedRowKeys || [ ] ,
184
- } ) ;
179
+ this . store . selectedRowKeys = val . selectedRowKeys || [ ] ;
185
180
const { rowSelection } = this ;
186
181
if ( rowSelection && val . getCheckboxProps !== rowSelection . getCheckboxProps ) {
187
182
this . CheckboxPropsCache = { } ;
188
183
}
189
184
} else if ( oldVal && ! val ) {
190
- this . store . setState ( {
191
- selectedRowKeys : [ ] ,
192
- } ) ;
185
+ this . store . selectedRowKeys = [ ] ;
193
186
}
194
187
} ,
195
188
deep : true ,
196
189
} ,
197
190
198
191
dataSource ( ) {
199
- this . store . setState ( {
200
- selectionDirty : false ,
201
- } ) ;
192
+ this . store . selectionDirty = false ;
202
193
this . CheckboxPropsCache = { } ;
203
194
} ,
204
195
@@ -460,7 +451,7 @@ export default {
460
451
const { selectWay, record, checked, changeRowKeys, nativeEvent } = selectionInfo ;
461
452
const rowSelection = getRowSelection ( this . $props ) ;
462
453
if ( rowSelection && ! ( 'selectedRowKeys' in rowSelection ) ) {
463
- this . store . setState ( { selectedRowKeys } ) ;
454
+ this . store . selectedRowKeys = selectedRowKeys ;
464
455
}
465
456
const data = this . getFlatData ( ) ;
466
457
if ( ! rowSelection . onChange && ! rowSelection [ selectWay ] ) {
@@ -573,9 +564,7 @@ export default {
573
564
574
565
this . setState ( newState , ( ) => {
575
566
this . scrollToFirstRow ( ) ;
576
- this . store . setState ( {
577
- selectionDirty : false ,
578
- } ) ;
567
+ this . store . selectionDirty = false ;
579
568
this . $emit (
580
569
'change' ,
581
570
...this . prepareParamsArguments ( {
@@ -591,10 +580,8 @@ export default {
591
580
handleSelect ( record , rowIndex , e ) {
592
581
const checked = e . target . checked ;
593
582
const nativeEvent = e . nativeEvent ;
594
- const defaultSelection = this . store . getState ( ) . selectionDirty
595
- ? [ ]
596
- : this . getDefaultSelection ( ) ;
597
- let selectedRowKeys = this . store . getState ( ) . selectedRowKeys . concat ( defaultSelection ) ;
583
+ const defaultSelection = this . store . selectionDirty ? [ ] : this . getDefaultSelection ( ) ;
584
+ let selectedRowKeys = this . store . selectedRowKeys . concat ( defaultSelection ) ;
598
585
const key = this . getRecordKey ( record , rowIndex ) ;
599
586
const { pivot } = this . $data ;
600
587
const rows = this . getFlatCurrentPageData ( ) ;
@@ -627,9 +614,7 @@ export default {
627
614
}
628
615
629
616
this . setState ( { pivot : realIndex } ) ;
630
- this . store . setState ( {
631
- selectionDirty : true ,
632
- } ) ;
617
+ this . store . selectionDirty = true ;
633
618
this . setSelectedRowKeys ( selectedRowKeys , {
634
619
selectWay : 'onSelectMultiple' ,
635
620
record,
@@ -644,9 +629,7 @@ export default {
644
629
selectedRowKeys = selectedRowKeys . filter ( i => key !== i ) ;
645
630
}
646
631
this . setState ( { pivot : realIndex } ) ;
647
- this . store . setState ( {
648
- selectionDirty : true ,
649
- } ) ;
632
+ this . store . selectionDirty = true ;
650
633
this . setSelectedRowKeys ( selectedRowKeys , {
651
634
selectWay : 'onSelect' ,
652
635
record,
@@ -662,9 +645,7 @@ export default {
662
645
const nativeEvent = e . nativeEvent ;
663
646
const key = this . getRecordKey ( record , rowIndex ) ;
664
647
const selectedRowKeys = [ key ] ;
665
- this . store . setState ( {
666
- selectionDirty : true ,
667
- } ) ;
648
+ this . store . selectionDirty = true ;
668
649
this . setSelectedRowKeys ( selectedRowKeys , {
669
650
selectWay : 'onSelect' ,
670
651
record,
@@ -676,10 +657,8 @@ export default {
676
657
677
658
handleSelectRow ( selectionKey , index , onSelectFunc ) {
678
659
const data = this . getFlatCurrentPageData ( ) ;
679
- const defaultSelection = this . store . getState ( ) . selectionDirty
680
- ? [ ]
681
- : this . getDefaultSelection ( ) ;
682
- const selectedRowKeys = this . store . getState ( ) . selectedRowKeys . concat ( defaultSelection ) ;
660
+ const defaultSelection = this . store . selectionDirty ? [ ] : this . getDefaultSelection ( ) ;
661
+ const selectedRowKeys = this . store . selectedRowKeys . concat ( defaultSelection ) ;
683
662
const changeableRowKeys = data
684
663
. filter ( ( item , i ) => ! this . getCheckboxPropsByItem ( item , i ) . props . disabled )
685
664
. map ( ( item , i ) => this . getRecordKey ( item , i ) ) ;
@@ -724,9 +703,7 @@ export default {
724
703
break ;
725
704
}
726
705
727
- this . store . setState ( {
728
- selectionDirty : true ,
729
- } ) ;
706
+ this . store . selectionDirty = true ;
730
707
// when select custom selection, callback selections[n].onSelect
731
708
const { rowSelection } = this ;
732
709
let customSelectionStartIndex = 2 ;
@@ -769,9 +746,7 @@ export default {
769
746
}
770
747
this . setState ( newState , this . scrollToFirstRow ) ;
771
748
772
- this . store . setState ( {
773
- selectionDirty : false ,
774
- } ) ;
749
+ this . store . selectionDirty = false ;
775
750
this . $emit (
776
751
'change' ,
777
752
...this . prepareParamsArguments ( {
0 commit comments