@bytedance/mona
Version:
Merchant app's developing and building tools
70 lines • 3.04 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ComponentLifecycleGlobalContext = exports.AppLifecycleGlobalContext = exports.PageLifecycleGlobalContext = exports.LifecycleContext = exports.ComponentLifecycle = exports.PageLifecycle = exports.AppLifecycle = void 0;
const react_1 = __importDefault(require("react"));
var AppLifecycle;
(function (AppLifecycle) {
AppLifecycle["launch"] = "onLaunch";
AppLifecycle["show"] = "onShow";
AppLifecycle["hide"] = "onHide";
AppLifecycle["error"] = "onError";
AppLifecycle["pageNotFound"] = "onPageNotFound";
AppLifecycle["unhandledRejection"] = "onUnhandledRejection";
})(AppLifecycle || (exports.AppLifecycle = AppLifecycle = {}));
var PageLifecycle;
(function (PageLifecycle) {
PageLifecycle["load"] = "onLoad";
PageLifecycle["ready"] = "onReady";
PageLifecycle["show"] = "onShow";
PageLifecycle["hide"] = "onHide";
PageLifecycle["unload"] = "onUnload";
PageLifecycle["resize"] = "onResize";
PageLifecycle["pullDownRefresh"] = "onPullDownRefresh";
PageLifecycle["reachBottom"] = "onReachBottom";
PageLifecycle["shareAppMessage"] = "onShareAppMessage";
PageLifecycle["pageScroll"] = "onPageScroll";
})(PageLifecycle || (exports.PageLifecycle = PageLifecycle = {}));
var ComponentLifecycle;
(function (ComponentLifecycle) {
ComponentLifecycle["created"] = "onCreated";
ComponentLifecycle["attached"] = "onAttached";
ComponentLifecycle["ready"] = "onReady";
ComponentLifecycle["moved"] = "onMoved";
ComponentLifecycle["detached"] = "onDetached";
})(ComponentLifecycle || (exports.ComponentLifecycle = ComponentLifecycle = {}));
class LifecycleContext {
constructor() {
this.lifecycle = new Proxy({}, {
get: function (target, property) {
if (typeof property === 'string') {
return target[property.toLowerCase().replace(/^on/, '')];
}
return;
},
set: function (target, property, value) {
if (typeof property === 'string') {
target[property.toLowerCase().replace(/^on/, '')] = value;
}
return true;
},
});
}
registerLifecycle(name, callback) {
if (typeof callback !== 'function') {
return;
}
this.lifecycle[name] = this.lifecycle[name] || new Set([]);
this.lifecycle[name].add(callback);
return () => {
this.lifecycle[name].delete(callback);
};
}
}
exports.LifecycleContext = LifecycleContext;
exports.PageLifecycleGlobalContext = react_1.default.createContext(null);
exports.AppLifecycleGlobalContext = react_1.default.createContext(null);
exports.ComponentLifecycleGlobalContext = react_1.default.createContext(null);
//# sourceMappingURL=context.js.map