UNPKG

mobx-roof

Version:

Simple React data management by mobx.

48 lines (39 loc) 1.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var SimpleEvent = function () { function SimpleEvent() { _classCallCheck(this, SimpleEvent); this._listeners = []; } _createClass(SimpleEvent, [{ key: "subscribe", value: function subscribe(listener) { var _listeners = this._listeners; _listeners.push(listener); return this.unSubscribe.bind(this, listener); } }, { key: "unSubscribe", value: function unSubscribe(listener) { var index = this._listeners.indexOf(listener); this._listeners.splice(index, 1); } }, { key: "dispatch", value: function dispatch() { for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } this._listeners.forEach(function (listener) { return listener.apply(undefined, args); }); } }]); return SimpleEvent; }(); exports.default = SimpleEvent; module.exports = exports['default'];