1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- import _extends from "@babel/runtime/helpers/esm/extends";
- import Vue from 'vue';
- var inheritKey = ['ref', 'key', 'style', 'class', 'attrs', 'refInFor', 'nativeOn', 'directives', 'staticClass', 'staticStyle'];
- var mapInheritKey = {
- nativeOn: 'on'
- }; // inherit partial context, map nativeOn to on
- export function inherit(context, inheritListeners) {
- var result = inheritKey.reduce(function (obj, key) {
- if (context.data[key]) {
- obj[mapInheritKey[key] || key] = context.data[key];
- }
- return obj;
- }, {});
- if (inheritListeners) {
- result.on = result.on || {};
- _extends(result.on, context.data.on);
- }
- return result;
- } // emit event
- export function emit(context, eventName) {
- for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
- args[_key - 2] = arguments[_key];
- }
- var listeners = context.listeners[eventName];
- if (listeners) {
- if (Array.isArray(listeners)) {
- listeners.forEach(function (listener) {
- listener.apply(void 0, args);
- });
- } else {
- listeners.apply(void 0, args);
- }
- }
- } // mount functional component
- export function mount(Component, data) {
- var instance = new Vue({
- el: document.createElement('div'),
- props: Component.props,
- render: function render(h) {
- return h(Component, _extends({
- props: this.$props
- }, data));
- }
- });
- document.body.appendChild(instance.$el);
- return instance;
- }
|