import type { MorJSHooks, MorJSPlugin } from '@morjs/api'
export interface IRuntimePluginXXXOptions {
key: value
}
export default class RuntimePluginXXX implements MorJSPlugin {
pluginName = 'RuntimePluginXXX'
pluginOptions: IRuntimePluginXXXOptions
constructor(options?: IRuntimePluginXXXOptions) {
this.pluginOptions = {
...options
}
}
apply = (morHooks: MorJSHooks): void => {
morHooks.appOnConstruct.tap(this.pluginName, function (this, options) {
console.log('app 应用 onConstruct 生命周期,初始化前触发')
})
morHooks.appOnInit.tap(this.pluginName, function (this, options) {
console.log('app 应用 onInit 生命周期,初始化阶段触发')
})
morHooks.appOnLaunch.tap(this.pluginName, function (this, options) {
console.log('app 应用 onLaunch 生命周期,初始化阶段完成时触发')
})
morHooks.appOnError.tap(this.pluginName, function (this, options) {
console.log('app 应用 onError 生命周期,小程序发生 js 错误时触发')
})
morHooks.appOnShow.tap(this.pluginName, function (this, options) {
console.log(
'app 应用 onShow 生命周期,当小程序启动,或从后台进入前台显示时触发'
)
})
morHooks.appOnHide.tap(this.pluginName, function (this, options) {
console.log(
'app 应用 onHide 生命周期,小程序被隐藏时触发,例如跳转、按下设备 Home 键离开等'
)
})
morHooks.appOnPageNotFound.tap(this.pluginName, function (this, options) {
console.log(
'app 应用 onPageNotFound 生命周期,小程序要打开的页面不存在时触发'
)
})
morHooks.appOnUnhandledRejection.tap(
this.pluginName,
function (this, options) {
console.log(
'app 应用 onUnhandledRejection 生命周期,当 Promise 被 reject 且没有 reject 处理器时触发'
)
}
)
morHooks.pageOnConstruct.tap(this.pluginName, function (this, options) {
console.log('page 页面 onConstruct 生命周期,初始化前触发')
})
morHooks.pageOnInit.tap(this.pluginName, function (this, options) {
console.log('page 页面 onInit 生命周期,初始化阶段触发')
})
morHooks.pageOnLoad.tap(this.pluginName, function (this, options) {
console.log('page 页面 onLoad 生命周期,页面加载时触发')
})
morHooks.pageOnReady.tap(this.pluginName, function (this, options) {
console.log('page 页面 onReady 生命周期,页面初次渲染完成时触发')
})
morHooks.pageOnShow.tap(this.pluginName, function (this, options) {
console.log('page 页面 onShow 生命周期,页面显示时触发')
})
morHooks.pageOnHide.tap(this.pluginName, function (this, options) {
console.log('page 页面 onHide 生命周期,页面隐藏时触发')
})
morHooks.pageOnUnload.tap(this.pluginName, function (this, options) {
console.log('page 页面 onUnload 生命周期,页面卸载时触发')
})
morHooks.componentOnConstruct.tap(
this.pluginName,
function (this, options) {
console.log('component 组件 onConstruct 生命周期,注册阶段触发')
}
)
morHooks.componentOnInit.tap(this.pluginName, function (this, options) {
console.log('component 组件 onInit 生命周期,组件创建时触发')
})
morHooks.componentOnCreated.tap(this.pluginName, function (this, options) {
console.log('component 组件 created 生命周期,组件实例刚刚被创建时执行')
})
morHooks.componentDidMount.tap(this.pluginName, function (this, options) {
console.log('component 组件 didMount 生命周期,组件创建完毕时触发')
})
morHooks.componentOnAttached.tap(this.pluginName, function (this, options) {
console.log(
'component 组件 attached 生命周期,在组件实例进入页面节点树时执行'
)
})
morHooks.componentDidUnmount.tap(this.pluginName, function (this, options) {
console.log('component 组件 didUnmount 生命周期,组件删除时触发')
})
morHooks.componentOnDetached.tap(this.pluginName, function (this, options) {
console.log(
'component 组件 detached 生命周期,在组件实例被从页面节点树移除时执行'
)
})
morHooks.componentOnError.tap(this.pluginName, function (this, options) {
console.log('component 组件 onError 生命周期,组件 JS 代码抛出错误时触发')
})
}
}