UNPKG

@mdsfe/mds-ui

Version:

A set of enterprise-class Vue UI components.

54 lines (41 loc) 1.47 kB
'use strict'; exports.__esModule = true; var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); var _util = require('./util'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var Soda = function () { function Soda(vm) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; (0, _classCallCheck3.default)(this, Soda); this.mutations = options.mutations; (0, _util.assert)(typeof options.state === 'function', 'Soda state must be a function.'); this.state = options.state(); this.root = vm; this.init(vm); return this; } Soda.prototype.commit = function commit(type, payload) { this.mutations[type].call(this, this.state, payload); }; Soda.prototype.init = function init() { var _this = this; var root = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.root; var map = function map(_vm) { if (!_vm.$children.length) return; _vm.$children.forEach(function (child) { inject(child); map(child); }); }; var inject = function inject(_vm) { if (typeof _vm.soda === 'undefined' || typeof _this.$soda !== 'undefined') return; _vm.$soda = _this; _vm.soda = _this.state; }; root.soda = this.state; map(root); }; return Soda; }(); exports.default = Soda;