UNPKG

@zeppos/zml

Version:

A Mini Library of ZeppOS MiniApp

2 lines (1 loc) 2.06 kB
const e=Object.prototype.hasOwnProperty;function t(t,n){return Object.getOwnPropertyNames(n).forEach((function(r){if(!e.call(t,r)){var o=Object.getOwnPropertyDescriptor(n,r);Object.defineProperty(t,r,o)}})),t}const n={init(){this.plugins=[],this.settings={},this.mixins=[]},set(e,t){if(1===arguments.length)return this.settings[e];this.settings[e]=t},use(e,...t){return"function"==typeof e?this.plugins.push({handler:e,args:t}):"object"==typeof e&&this.mixins.push({handler:e,args:t}),this},handle(e){this.plugins.forEach((t=>{if(t&&"function"==typeof t.handler)try{const n=t.handler.call(this,e,...t.args);"object"==typeof n&&this.mixins.push({handler:n,args:[]})}catch(e){}})),this.mixins.forEach((({handler:{onInit:t,onPause:n,build:r,onResume:o,onDestroy:i,onCreate:s,...g},args:h})=>{Object.assign(e,g)}))}};function r(){return"undefined"!=typeof hmApp}function o(){return"undefined"!=typeof __$$R$$__}function i(){return r()||o()}let s=null;s="undefined"!=typeof __$$R$$__?__$$R$$__:()=>({});let g=null;function h({globalData:e={},onCreate:t,onDestroy:n,...r}={}){const o={globalData:e,...r,onCreate(...e){for(let t=0;t<=h.mixins.length-1;t++){const n=h.mixins[t];n&&n.handler.onCreate?.apply(this,e)}t?.apply(this,e)},onDestroy(...e){n?.apply(this,e);for(let t=h.mixins.length-1;t>=0;t--){const n=h.mixins[t];n&&n.handler.onDestroy?.apply(this,e)}}};return h.handle(o),o}i()&&r()?g=DeviceRuntimeCore.HmLogger:i()&&o()?g=s("@zos/utils").log:"undefined"!=typeof messaging&&"undefined"!=typeof Logger&&(g=Logger),t(h,n),h.init(),h.use((function(){return{onInit(){this.logger=g.getLogger(this.name||"Page"),this.log=(...e)=>{this.logger.log(...e)},this.error=(...e)=>{e[0]instanceof Error?this.logger.error(...e):this.logger.error({},...e)},this.debug=(...e)=>{this.logger.debug(...e)}},onCreate(){this.logger=g.getLogger(this.name||"app.js"),this.log=(...e)=>{this.logger.log(...e)},this.error=(...e)=>{e[0]instanceof Error?this.logger.error(...e):this.logger.error({},...e)},this.debug=(...e)=>{this.logger.debug(...e)}}}}));export{h as BaseApp,t as merge};