'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var vue = require('vue');
var props = require('./props.cjs');

var BaseMixin = {
  methods: {
    setState(state = {}, callback) {
      let newState = typeof state === "function" ? state(this.$data, this.$props) : state;
      if (this.getDerivedStateFromProps) {
        const s = this.getDerivedStateFromProps(props.getOptionProps(this), {
          ...this.$data,
          ...newState
        });
        if (s === null)
          return;
        else
          newState = { ...newState, ...s || {} };
      }
      Object.assign(this.$data, newState);
      if (this._.isMounted)
        this.$forceUpdate();
      vue.nextTick(() => {
        callback && callback();
      });
    },
    __emit() {
      const args = [].slice.call(arguments, 0);
      let eventName = args[0];
      eventName = `on${eventName[0].toUpperCase()}${eventName.substring(1)}`;
      const event = this.$props[eventName] || this.$attrs[eventName];
      if (args.length && event) {
        if (Array.isArray(event)) {
          for (let i = 0, l = event.length; i < l; i++)
            event[i](...args.slice(1));
        } else {
          event(...args.slice(1));
        }
      }
    }
  }
};

exports.default = BaseMixin;
//# sourceMappingURL=BaseMixin.cjs.map
