vue-feathers-services
Version:
Plugin to simplify FeathersJS service usage within VueJS components.
56 lines (42 loc) • 1.45 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
function plugin(Vue, feathers) {
if (plugin.installed) {
return;
}
// Define a property to grant easy acces to the feathers application from Vue component instances
Object.defineProperty(Vue.prototype, '$api', {
get: function get() {
return feathers;
}
});
Vue.mixin({
beforeCreate: function beforeCreate() {
registerServices(this);
},
init: function init() {
registerServices(this);
}
});
}
function registerServices(vm) {
var services = vm.$options.services;
if ((typeof services === 'undefined' ? 'undefined' : _typeof(services)) !== 'object') {
return;
}
var dataIsFn = typeof vm.$options.data === 'function';
var data = dataIsFn ? vm.$options.data() : vm.$options.data;
if (typeof data === 'undefined') {
data = {};
}
for (var service in services) {
data[service] = vm.$api.service(services[service]);
}
vm.$options.data = function () {
return data;
};
}
exports.default = plugin;