Skip to content

Commit d0c0cca

Browse files
authored
Drop support Vue 2 (#453)
* Drop support Vue 2 * update * fix * fix
1 parent 02b5445 commit d0c0cca

20 files changed

+1031
-664
lines changed

packages/vue-cheetah-grid/README.md

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
[![npm](https://img.shields.io/npm/dt/vue-cheetah-grid.svg)](http://www.npmtrends.com/vue-cheetah-grid)
99
[![Build Status](https://github.com/future-architect/cheetah-grid/workflows/CI/badge.svg?branch=master)](https://github.com/future-architect/cheetah-grid/actions?query=workflow%3ACI)
1010

11-
It supports Vue 2 and Vue 3.
11+
It supports Vue 3.
1212

1313
## Install using npm
1414

@@ -44,8 +44,6 @@ npm install -S vue-cheetah-grid
4444

4545
### Use Components Globally
4646

47-
Vue3:
48-
4947
```js
5048
import { createApp } from "vue";
5149
import CGrid from "vue-cheetah-grid";
@@ -55,15 +53,6 @@ const app = createApp(App);
5553
app.use(CGrid);
5654
```
5755

58-
Vue2:
59-
60-
```js
61-
import Vue from "vue";
62-
import CGrid from "vue-cheetah-grid";
63-
64-
Vue.use(CGrid);
65-
```
66-
6756
### Use Components Locally
6857

6958
```vue

packages/vue-cheetah-grid/karma.conf.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,10 @@ module.exports = function (config) {
2727
]
2828
},
2929
browserNoActivityTimeout: 90000,
30-
browsers: ['Chrome'
31-
// 'IE_no_addons'
30+
browsers: [
31+
'Chrome'
3232
],
3333
customLaunchers: {
34-
IE_no_addons: {
35-
base: 'IE',
36-
flags: ['-extoff']
37-
},
3834
Chrome_travis_ci: {
3935
base: 'ChromeHeadless',
4036
flags: ['--no-sandbox']

packages/vue-cheetah-grid/lib/CGrid.vue

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ import {
3939
cheetahGrid,
4040
gridUpdateWatcher,
4141
extend,
42-
vue3Emits,
43-
getSlotChildren,
44-
hackVue3
42+
emits,
43+
getSlotChildren
4544
} from './c-grid/utils'
4645
import { slotElementsToHeaderOptions, slotElementsToHeaderProps } from './c-grid/header-utils'
4746
@@ -271,10 +270,6 @@ let seq = 0
271270
*/
272271
export default {
273272
name: 'CGrid',
274-
get mixins () {
275-
hackVue3(this)
276-
return undefined
277-
},
278273
provide () {
279274
return {
280275
$_CGridInstance: this
@@ -415,7 +410,7 @@ export default {
415410
'paste-cell': null,
416411
'changed-value': null,
417412
'changed-header-value': null,
418-
...vue3Emits
413+
...emits
419414
},
420415
data () {
421416
return {
@@ -536,14 +531,17 @@ export default {
536531
}
537532
_initGrid(this)
538533
},
539-
// for Vue 3
540534
unmounted () {
541-
destroyed(this)
542-
},
543-
// for Vue 2
544-
// eslint-disable-next-line vue/no-deprecated-destroyed-lifecycle
545-
destroyed () {
546-
destroyed(this)
535+
const vm = this
536+
vm.$_CGrid_cancelNextTickUpdate()
537+
if (vm.rawGrid) {
538+
vm.rawGrid.dispose()
539+
vm.rawGrid = null
540+
}
541+
if (vm._dataSources) {
542+
vm._dataSources.forEach(dc => dc.dispose())
543+
}
544+
vm.$_CGrid_defineColumns = []
547545
},
548546
updated () {
549547
this.$_CGrid_nextTickUpdate()
@@ -743,17 +741,6 @@ export default {
743741
}
744742
}
745743
}
746-
function destroyed (vm) {
747-
vm.$_CGrid_cancelNextTickUpdate()
748-
if (vm.rawGrid) {
749-
vm.rawGrid.dispose()
750-
vm.rawGrid = null
751-
}
752-
if (vm._dataSources) {
753-
vm._dataSources.forEach(dc => dc.dispose())
754-
}
755-
vm.$_CGrid_defineColumns = []
756-
}
757744
</script>
758745

759746
<style scoped>

packages/vue-cheetah-grid/lib/CGridLayoutRow.vue

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
<script>
1212
import { slotElementsToHeaderOptions, slotElementsToHeaderProps } from './c-grid/header-utils'
13-
import { getSlotChildren, hackVue3 } from './c-grid/utils'
13+
import { getSlotChildren } from './c-grid/utils'
1414
import { storeElement, removeElement } from './c-grid/elements'
1515
1616
/**
@@ -19,10 +19,6 @@ import { storeElement, removeElement } from './c-grid/elements'
1919
*/
2020
export default {
2121
name: 'CGridLayoutRow',
22-
get mixins () {
23-
hackVue3(this)
24-
return undefined
25-
},
2622
inject: ['$_CGridInstance'],
2723
mounted () {
2824
storeElement(this)
@@ -32,14 +28,10 @@ export default {
3228
updated () {
3329
this.$_CGrid_nextTickUpdate()
3430
},
35-
// for Vue 3
3631
beforeUnmount () {
37-
beforeDestroy(this)
38-
},
39-
// for Vue 2
40-
// eslint-disable-next-line vue/no-deprecated-destroyed-lifecycle
41-
beforeDestroy () {
42-
beforeDestroy(this)
32+
const vm = this
33+
removeElement(vm)
34+
vm.$_CGridInstance.$_CGrid_removeColumnDefine(vm)
4335
},
4436
methods: {
4537
/**
@@ -64,11 +56,6 @@ export default {
6456
}
6557
}
6658
}
67-
68-
function beforeDestroy (vm) {
69-
removeElement(vm)
70-
vm.$_CGridInstance.$_CGrid_removeColumnDefine(vm)
71-
}
7259
</script>
7360

7461
<style scoped>

packages/vue-cheetah-grid/lib/c-grid/ColumnMixin.vue

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
<script>
2-
import { gridUpdateWatcher, resolveProxyComputedProps, resolveProxyPropsMethod, vue3Emits, hackVue3 } from './utils'
2+
import { gridUpdateWatcher, resolveProxyComputedProps, resolveProxyPropsMethod, emits } from './utils'
33
import { storeElement, removeElement } from './elements'
44
55
/**
66
* The Mixin for `<c-grid-column>` components.
77
*/
88
export default {
9-
get mixins () {
10-
hackVue3(this)
11-
return undefined
12-
},
139
inject: ['$_CGridInstance'],
1410
props: {
1511
/**
@@ -62,7 +58,7 @@ export default {
6258
default: undefined
6359
}
6460
},
65-
emits: { ...vue3Emits },
61+
emits: { ...emits },
6662
computed: {
6763
resolvedCaption () {
6864
const vm = this
@@ -90,14 +86,10 @@ export default {
9086
updated () {
9187
this.$_CGrid_nextTickUpdate()
9288
},
93-
// for Vue 3
9489
beforeUnmount () {
95-
beforeDestroy(this)
96-
},
97-
// for Vue 2
98-
// eslint-disable-next-line vue/no-deprecated-destroyed-lifecycle
99-
beforeDestroy () {
100-
beforeDestroy(this)
90+
const vm = this
91+
removeElement(vm)
92+
vm.$_CGridInstance.$_CGrid_removeColumnDefine(vm)
10193
},
10294
methods: {
10395
/**
@@ -193,9 +185,4 @@ export default {
193185
$_CGridColumn_headerActionProxy: resolveProxyPropsMethod('headerAction')
194186
}
195187
}
196-
197-
function beforeDestroy (vm) {
198-
removeElement(vm)
199-
vm.$_CGridInstance.$_CGrid_removeColumnDefine(vm)
200-
}
201188
</script>

packages/vue-cheetah-grid/lib/c-grid/utils.js

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -50,29 +50,8 @@ export function filterToFn (instance, field, filter) {
5050
set: field.set
5151
}
5252
}
53-
if (typeof filter === 'function') {
54-
return (rec) => applyFilter(getField(rec, field), filter)
55-
}
56-
const Vue = instance.constructor
57-
const maybeV2 = Vue && Vue.filter
58-
if (!maybeV2) {
59-
return (rec) => applyFilter(getField(rec, field), filter)
60-
}
61-
// maybe Vue v2
62-
filter = filter.trim()
63-
const i = filter.indexOf('(')
64-
if (i < 0) {
65-
return (rec) => {
66-
return applyFilter(getField(rec, field), Vue.filter(filter))
67-
}
68-
} else {
69-
const name = filter.slice(0, i)
70-
const args = filter.slice(i + 1, filter.length - 1)
71-
const props = Function(`with(this){return [${args}]}`).call(instance.$vnode.context) // eslint-disable-line no-new-func
72-
return (rec) => {
73-
return applyFilter(getField(rec, field), (v) => Vue.filter(name)(v, ...props))
74-
}
75-
}
53+
54+
return (rec) => applyFilter(getField(rec, field), filter)
7655
}
7756

7857
export function normalizeColumnType (columnType) {
@@ -147,19 +126,10 @@ export function getSlotChildren (vm, name = 'defaultSlotContainer') {
147126

148127
// for compatibility
149128
const { EVENT_TYPE } = cheetahGrid.ListGrid
150-
export const vue3Emits = Object.keys(EVENT_TYPE)
129+
/** @type {Record<keyof typeof EVENT_TYPE, null>} */
130+
export const emits = Object.keys(EVENT_TYPE)
151131
.map(k => EVENT_TYPE[k].replace(/_/g, '-').toLowerCase())
152132
.reduce((r, v) => {
153133
r[v] = null
154134
return r
155135
}, {})
156-
157-
export function hackVue3 (options) {
158-
// eslint-disable-next-line no-undef
159-
if ((typeof __VUE_OPTIONS_API__ !== 'undefined' && __VUE_OPTIONS_API__) ||
160-
// eslint-disable-next-line no-undef
161-
(typeof Vue !== 'undefined' && `${Vue.version}`.startsWith('3'))) {
162-
delete options.beforeDestroy
163-
delete options.destroyed
164-
}
165-
}

0 commit comments

Comments
 (0)