Skip to content

Commit 64aca06

Browse files
author
utkace
committed
support: add plugin to instantiate Vue in SDK
1 parent 4bd38c8 commit 64aca06

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/plugin.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
export function install(Vue, options = {}) {
2+
if(Vue.IkInstalled) {
3+
throw new Error("Imagekit plugin already installed");
4+
}
5+
6+
Vue.IkInstalled = true;
7+
8+
initComponents(Vue, options);
9+
}
10+
11+
function registerComponents( Vue, components = {}, defaultConfigurations = {}) {
12+
if( !components) { throw new Error("No component found. ") }
13+
14+
for ( let key in component ) {
15+
const component = components[key];
16+
17+
if (component) {
18+
Vue.component(key, {
19+
...component,
20+
data() {
21+
return {
22+
...(component.data ? component.data() : {}),
23+
defaultConfigurations
24+
}
25+
}
26+
27+
})
28+
}
29+
}
30+
}
31+
32+
function initComponents(Vue) {
33+
const components = Array.isArray(options.components) ? options.components.reduce((obj, component) => ({
34+
...obj,
35+
[component.name] : component
36+
}), {}) : options.components;
37+
38+
registerComponents( Vue, components);
39+
}

0 commit comments

Comments
 (0)