@mobileaction/ui-modules
Version:
Mobile Action common modules for Vue projects
43 lines (38 loc) • 1.27 kB
JavaScript
import MaLogger from './libs/MaLogger.js';
export function validateVueInstall(app, Plugin, pluginName) {
if (!Plugin.$log) { // polyfill $log if not installed
Plugin.$log = new MaLogger(app, { name: pluginName + '-logger', isDebug: () => false });
}
if (Plugin.app === app) {
Plugin.$log.warn(`${ pluginName }: already added`);
return false;
}
Plugin.app = app;
return true;
}
/**
* This method needs Vue/app instance to check which one we have
* @param app {Vue} vue or vue instance
* @returns {boolean}
*/
export function isVue3(app) {
return Number(app.version.split('.')[0]) === 3;
}
/**
* Injects plugin instance to given field as both global and instance based.
* @param app vue or vue app instance
* @param pluginInstance plugin instance to be injected
* @param pluginField field to be injected
*/
export function injectPlugin(app, pluginInstance, pluginField) {
app[pluginField] = pluginInstance;
getGlobalInstallInstance(app)[pluginField] = pluginInstance;
}
/**
* Returns the object that globally injected plugins reside
* @param app Vue or vue app
* @returns {*}
*/
export function getGlobalInstallInstance(app) {
return isVue3(app) ? app.config.globalProperties : app.prototype;
}