Skip to content
This repository was archived by the owner on Mar 11, 2021. It is now read-only.

Commit 5283666

Browse files
bc022699bc022699
authored andcommitted
Implement
1 parent 269e7d6 commit 5283666

1 file changed

Lines changed: 30 additions & 10 deletions

File tree

src/utils/reactify-vue/react-class-creation-and-runtime/VueComponentClass.ts

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as React from 'react';
22

33
import {camelCase} from 'change-case';
44

5-
const handleStateSet = (stateObject, key, value, vueComponent, self) => {
5+
const handleStateSet = (stateObject, key, value, vueComponent, self, deleteMode) => {
66
const stateKey = Object.keys(self.state).reduce((macthingStateKey, nextKey) => {
77
if (self.state[nextKey] === stateObject) {
88
return nextKey;
@@ -11,15 +11,30 @@ const handleStateSet = (stateObject, key, value, vueComponent, self) => {
1111
}
1212
}, null);
1313

14-
const newState = {
15-
...self.state,
16-
[stateKey]: {
17-
...self.state[stateKey],
18-
[key]: value
19-
}
20-
};
14+
let newState;
15+
16+
if (deleteMode) {
17+
newState = {
18+
...self.state
19+
};
20+
21+
delete newState[stateKey][key];
22+
} else {
23+
newState = {
24+
...self.state,
25+
[stateKey]: {
26+
...self.state[stateKey],
27+
[key]: value
28+
}
29+
};
30+
}
2131

22-
vueComponent[stateKey] = newState[stateKey];
32+
if (deleteMode) {
33+
delete vueComponent[stateKey][key];
34+
} else {
35+
vueComponent[stateKey] = newState[stateKey];
36+
}
37+
2338
self.setState(newState);
2439
};
2540

@@ -95,7 +110,12 @@ export const convertVueComponentToClass = (vueComponentObject) => {
95110

96111
vueComponentClass.prototype.$set = function (stateObject, key, value) {
97112
this.reactComponentInstance.hasUnrenderedStateChanges = true;
98-
handleStateSet(stateObject, key, value, this, this.reactComponentInstance);
113+
handleStateSet(stateObject, key, value, this, this.reactComponentInstance, false);
114+
};
115+
116+
vueComponentClass.prototype.$delete = function (stateObject, key) {
117+
this.reactComponentInstance.hasUnrenderedStateChanges = true;
118+
handleStateSet(stateObject, key, null, this, this.reactComponentInstance, true);
99119
};
100120

101121
return vueComponentClass;

0 commit comments

Comments
 (0)