-
Notifications
You must be signed in to change notification settings - Fork 2
/
vue3-plugin.js
55 lines (51 loc) · 1.42 KB
/
vue3-plugin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { components } from "./src/index.js";
import messages from "./src/i18n/index.js";
import service from "./src/service.js";
/**
* BCF Components library plugin for Vue 3.
* The plugin will perform the following actions in order:
* - initialize library service
* - register components translations
* - globally register BCF components
*
* @param {
* {
* apiClient: Object,
* fetchUsers?: Promise,
* i18nPlugin?: Object,
* }
* }
*/
const pluginFactory = ({
apiClient,
fetchUsers,
i18nPlugin,
} = {}) => {
return {
install(app) {
if (apiClient) {
service.setup({ apiClient, fetchUsers });
} else {
console.error(
"[BCF Components Plugin] No api client provided. " +
"You must provide an api client for the components to work properly."
);
}
if (i18nPlugin) {
Object.entries(messages).forEach(([locale, translations]) => {
i18nPlugin.global.mergeLocaleMessage(locale, translations);
});
} else {
console.warn(
"[BCF Components Plugin] No i18n instance provided. " +
"You should either provide an i18n instance or define " +
"your own translations in order have text displayed properly."
);
}
Object.entries(components).forEach(([name, component]) => {
app.component(name, component);
});
},
};
};
export default pluginFactory;