Skip to content

Commit

Permalink
feat(vue-runtime-help): 只有dsl中的组件才触发生命周期hook
Browse files Browse the repository at this point in the history
  • Loading branch information
roymondchen committed Aug 2, 2024
1 parent 831cdfb commit 69f3cb2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 70 deletions.
68 changes: 10 additions & 58 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions runtime/vue-runtime-help/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.0.7",
"version": "0.1.0",
"name": "@tmagic/vue-runtime-help",
"type": "module",
"sideEffects": false,
Expand Down Expand Up @@ -32,11 +32,11 @@
"vue-demi": "^0.14.7"
},
"peerDependencies": {
"@tmagic/core": ">=1.4.8",
"@tmagic/data-source": ">=1.4.8",
"@tmagic/schema": ">=1.4.8",
"@tmagic/stage": ">=1.4.8",
"@tmagic/utils": ">=1.4.8",
"@tmagic/core": ">=1.4.16",
"@tmagic/data-source": ">=1.4.16",
"@tmagic/schema": ">=1.4.16",
"@tmagic/stage": ">=1.4.16",
"@tmagic/utils": ">=1.4.16",
"@vue/composition-api": ">=1.7.2",
"typescript": "*",
"vue": ">=2.0.0 || >=3.0.0"
Expand Down
12 changes: 6 additions & 6 deletions runtime/vue-runtime-help/src/useApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
* limitations under the License.
*/

import { computed, inject, onBeforeUnmount, onMounted } from 'vue-demi';
import { inject, onBeforeUnmount, onMounted } from 'vue-demi';

import type Core from '@tmagic/core';
import type { MNode } from '@tmagic/schema';
import { IS_DSL_NODE_KEY } from '@tmagic/utils';

interface UseAppOptions<T extends MNode = MNode> {
config: T;
Expand All @@ -28,13 +29,11 @@ interface UseAppOptions<T extends MNode = MNode> {
};
}

const isDslNode = (config: MNode) => typeof config[IS_DSL_NODE_KEY] === 'undefined' || config[IS_DSL_NODE_KEY] === true;

export default ({ methods, config }: UseAppOptions) => {
const app: Core | undefined = inject('app');

const node = app?.page?.getNode(config.id || '');

const style = computed(() => (app ? app.transformStyle(config.style || {}) : config.style));

const emitData = {
config,
...methods,
Expand All @@ -53,6 +52,8 @@ export default ({ methods, config }: UseAppOptions) => {
return displayCfg !== false;
};

const node = isDslNode(config) ? app?.page?.getNode(config.id || '') : undefined;

if (node) {
node.emit('created', emitData);

Expand All @@ -68,7 +69,6 @@ export default ({ methods, config }: UseAppOptions) => {
return {
app,
node,
style,

display,
};
Expand Down

0 comments on commit 69f3cb2

Please sign in to comment.