@hocgin/taro-kit
Version:
66 lines (53 loc) • 2.17 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.EventKit = exports.EventKey = void 0;
var _taro = _interopRequireDefault(require("@tarojs/taro"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a 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); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
var EventKey;
exports.EventKey = EventKey;
(function (EventKey) {
EventKey["UPDATE_USER"] = "UPDATE_USER";
})(EventKey || (exports.EventKey = EventKey = {}));
var EventKit = /*#__PURE__*/function () {
function EventKit() {
_classCallCheck(this, EventKit);
}
_createClass(EventKit, null, [{
key: "trigger",
value: function trigger(eventKey) {
_taro.default.eventCenter.trigger(eventKey);
}
}, {
key: "on",
value: function on(eventKey, func) {
_taro.default.eventCenter.on(eventKey, func);
}
}, {
key: "off",
value: function off(eventKey, func) {
_taro.default.eventCenter.off(eventKey, func);
} // === [默认] ===
}, {
key: "updateUser",
value: function updateUser() {
EventKit.trigger(EventKey.UPDATE_USER);
}
}, {
key: "onUpdateUser",
value: function onUpdateUser(func) {
EventKit.on(EventKey.UPDATE_USER, func);
}
}, {
key: "offUpdateUser",
value: function offUpdateUser(func) {
EventKit.off(EventKey.UPDATE_USER, func);
}
}]);
return EventKit;
}();
exports.EventKit = EventKit;