Skip to content

Commit ba5c91b

Browse files
committed
1 parent 8d764d4 commit ba5c91b

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.4.4
2+
3+
- fix: multiple inheritance unbinding object errors
4+
15
## 1.4.3
26

37
- fix: memory leak caused by unused `@Setup` decorator

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-class-setup",
3-
"version": "1.4.3",
3+
"version": "1.4.4",
44
"main": "dist/index.cjs.js",
55
"module": "dist/index.es.js",
66
"types": "dist/index.d.ts",

src/setup-reference.ts

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
let count = 0;
2-
let isOpen = false;
2+
let isBind = false;
33

4-
export function add() {
5-
if (isOpen) {
4+
export function addCount() {
5+
// 如果还是处于绑定状态,说明上一次解绑的过程中程序执行报错了,需要重置
6+
if (isBind) {
7+
isBind = false;
68
count = 1;
79
} else {
8-
isOpen = true;
910
count++;
1011
}
1112
}
1213

1314
const weakMap = new WeakMap<object, number>();
1415

15-
export function popTarget(target: object): boolean {
16+
export function unBindTarget(target: object): boolean {
1617
let count = weakMap.get(target);
1718
if (typeof count === 'number') {
1819
count--;
@@ -21,7 +22,7 @@ export function popTarget(target: object): boolean {
2122
return false;
2223
} else {
2324
weakMap.delete(target);
24-
isOpen = false;
25+
isBind = false;
2526
return true;
2627
}
2728
}
@@ -32,6 +33,7 @@ export function bindTarget(target: object) {
3233
if (count > 0) {
3334
weakMap.set(target, count);
3435
count = 0;
36+
isBind = true;
3537
} else {
3638
console.warn(`The instance did not use the '@Setup' decorator`);
3739
}

src/setup.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
import { initComputed } from './computed';
1111
import { getOptions, getSetupOptions } from './options';
1212
import { initDefine } from './define';
13-
import { add, popTarget } from './setup-reference';
13+
import { addCount, unBindTarget } from './setup-reference';
1414
import { getPropertyDescriptors } from './property-descriptors';
1515

1616
export type TargetConstructor = {
@@ -68,9 +68,9 @@ function Setup<T extends TargetConstructor>(Target: T) {
6868
public static [SETUP_PROPERTY_DESCRIPTOR] =
6969
getPropertyDescriptors(Target);
7070
public constructor(...args: any[]) {
71-
add();
71+
addCount();
7272
super(...args);
73-
if (popTarget(this)) {
73+
if (unBindTarget(this)) {
7474
// Vue3 needs to return, vue2 does not need to return
7575
return initHook(reactive(this));
7676
}

0 commit comments

Comments
 (0)