From ba5c91bc270304c71336a54adf261687f293cdbd Mon Sep 17 00:00:00 2001 From: lzxb <1340641314@qq.com> Date: Fri, 19 Jul 2024 16:54:50 +0800 Subject: [PATCH] release: vue-class-setup@1.4.4 --- CHANGELOG.md | 4 ++++ package.json | 2 +- src/setup-reference.ts | 14 ++++++++------ src/setup.ts | 6 +++--- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eb88770..ec80216 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.4.4 + +- fix: multiple inheritance unbinding object errors + ## 1.4.3 - fix: memory leak caused by unused `@Setup` decorator diff --git a/package.json b/package.json index cb967b6..fcab8fd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vue-class-setup", - "version": "1.4.3", + "version": "1.4.4", "main": "dist/index.cjs.js", "module": "dist/index.es.js", "types": "dist/index.d.ts", diff --git a/src/setup-reference.ts b/src/setup-reference.ts index 03bb38a..54b7e0e 100644 --- a/src/setup-reference.ts +++ b/src/setup-reference.ts @@ -1,18 +1,19 @@ let count = 0; -let isOpen = false; +let isBind = false; -export function add() { - if (isOpen) { +export function addCount() { + // 如果还是处于绑定状态,说明上一次解绑的过程中程序执行报错了,需要重置 + if (isBind) { + isBind = false; count = 1; } else { - isOpen = true; count++; } } const weakMap = new WeakMap(); -export function popTarget(target: object): boolean { +export function unBindTarget(target: object): boolean { let count = weakMap.get(target); if (typeof count === 'number') { count--; @@ -21,7 +22,7 @@ export function popTarget(target: object): boolean { return false; } else { weakMap.delete(target); - isOpen = false; + isBind = false; return true; } } @@ -32,6 +33,7 @@ export function bindTarget(target: object) { if (count > 0) { weakMap.set(target, count); count = 0; + isBind = true; } else { console.warn(`The instance did not use the '@Setup' decorator`); } diff --git a/src/setup.ts b/src/setup.ts index b85c2ac..6230684 100644 --- a/src/setup.ts +++ b/src/setup.ts @@ -10,7 +10,7 @@ import { import { initComputed } from './computed'; import { getOptions, getSetupOptions } from './options'; import { initDefine } from './define'; -import { add, popTarget } from './setup-reference'; +import { addCount, unBindTarget } from './setup-reference'; import { getPropertyDescriptors } from './property-descriptors'; export type TargetConstructor = { @@ -68,9 +68,9 @@ function Setup(Target: T) { public static [SETUP_PROPERTY_DESCRIPTOR] = getPropertyDescriptors(Target); public constructor(...args: any[]) { - add(); + addCount(); super(...args); - if (popTarget(this)) { + if (unBindTarget(this)) { // Vue3 needs to return, vue2 does not need to return return initHook(reactive(this)); }