From f62f378f42644f87b9ef2fe151db937d3aa93175 Mon Sep 17 00:00:00 2001
From: Leo Caan (陈栋) <leocaan@icloud.com>
Date: Tue, 8 Jun 2021 14:28:19 +0800
Subject: [PATCH] chore: add util for install component (#707)

---
 src/components/CodeEditor/index.ts | 15 +++------------
 src/components/FlowChart/index.ts  |  8 ++------
 src/utils/install.ts               | 12 ++++++++++++
 3 files changed, 17 insertions(+), 18 deletions(-)
 create mode 100644 src/utils/install.ts

diff --git a/src/components/CodeEditor/index.ts b/src/components/CodeEditor/index.ts
index 89aa8a0..faefea5 100644
--- a/src/components/CodeEditor/index.ts
+++ b/src/components/CodeEditor/index.ts
@@ -1,15 +1,6 @@
-import type { App } from 'vue';
+import { install } from '/@/utils/install';
 import codeEditor from './src/CodeEditor.vue';
 import jsonPreview from './src/json-preview/JsonPreview.vue';
 
-export const CodeEditor = Object.assign(codeEditor, {
-  install(app: App) {
-    app.component(codeEditor.name, codeEditor);
-  },
-});
-
-export const JsonPreview = Object.assign(jsonPreview, {
-  install(app: App) {
-    app.component(jsonPreview.name, jsonPreview);
-  },
-});
+export const CodeEditor = install(codeEditor);
+export const JsonPreview = install(jsonPreview);
diff --git a/src/components/FlowChart/index.ts b/src/components/FlowChart/index.ts
index f4446a7..3068835 100644
--- a/src/components/FlowChart/index.ts
+++ b/src/components/FlowChart/index.ts
@@ -1,8 +1,4 @@
-import type { App } from 'vue';
+import { install } from '/@/utils/install';
 import flowChart from './src/FlowChart.vue';
 
-export const FlowChart = Object.assign(flowChart, {
-  install(app: App) {
-    app.component(flowChart.name, flowChart);
-  },
-});
+export const FlowChart = install(flowChart);
diff --git a/src/utils/install.ts b/src/utils/install.ts
new file mode 100644
index 0000000..f2687b2
--- /dev/null
+++ b/src/utils/install.ts
@@ -0,0 +1,12 @@
+import { App, Plugin } from 'vue';
+
+export const install = <T>(component: T, alias?: string) => {
+  const C = component as any;
+  C.install = (app: App) => {
+    app.component(C.name, component);
+    if (alias) {
+      app.config.globalProperties[alias] = component;
+    }
+  };
+  return component as T & Plugin;
+};
--
libgit2 0.23.3