@hocgin/taro-kit
Version:
53 lines (45 loc) • 1.82 kB
JavaScript
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; }
import Taro from "@tarojs/taro";
export var EventKey;
(function (EventKey) {
EventKey["UPDATE_USER"] = "UPDATE_USER";
})(EventKey || (EventKey = {}));
export var EventKit = /*#__PURE__*/function () {
function EventKit() {
_classCallCheck(this, EventKit);
}
_createClass(EventKit, null, [{
key: "trigger",
value: function trigger(eventKey) {
Taro.eventCenter.trigger(eventKey);
}
}, {
key: "on",
value: function on(eventKey, func) {
Taro.eventCenter.on(eventKey, func);
}
}, {
key: "off",
value: function off(eventKey, func) {
Taro.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;
}();