From ae522e7bcc31c9e09c83aec8d294267a429402a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8A=9B=E7=9A=93?= Date: Tue, 11 May 2021 20:44:32 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=85=BC=E5=AE=B9=20useVariableChange?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/vision-polyfill/src/bus.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/vision-polyfill/src/bus.ts b/packages/vision-polyfill/src/bus.ts index 37432e7f0..d1003bb5b 100644 --- a/packages/vision-polyfill/src/bus.ts +++ b/packages/vision-polyfill/src/bus.ts @@ -1,6 +1,7 @@ import logger from '@ali/vu-logger'; import { EventEmitter } from 'events'; import { editor } from '@ali/lowcode-engine'; +import { isJSExpression } from '@ali/lowcode-types'; /** * Bus class as an EventEmitter @@ -76,8 +77,20 @@ editor?.on('history.forward', (data) => { bus.emit('ve.history.forward', data); }); +function triggerUseVariableChange(data: any) { + const { node, prop, oldValue, newValue } = data; + const propConfig = node.componentMeta.prototype.options.configure.find((o: any) => o.name === prop.getKey()); + if (!propConfig?.useVariableChange) return; + if (isJSExpression(oldValue) && !isJSExpression(newValue)) { + propConfig.useVariableChange.call(prop, { isUseVariable: false }); + } else if (isJSExpression(newValue) && !isJSExpression(oldValue)) { + propConfig.useVariableChange.call(prop, { isUseVariable: true }); + } +} editor?.on('node.prop.change', (data) => { bus.emit('node.prop.change', data); + + triggerUseVariableChange(data); }); export default bus;