App() constructor to add lifecycle hooks, event emitting, and cross-platform adapter support.
Functions
createApp
Registers a mini-program application with the MorJS runtime. Initialises lifecycle hooks, runs registered plugins, and calls the platform’s native App() constructor.
The application configuration object. Supports both Alipay (
tinyapp.IAppOptionsMethods) and WeChat (WechatMiniprogram.App.Option) option shapes, plus MorJS extensions.One or more MorJS runtime solutions (plugin bundles) to initialise before the app is registered.
createApp can only be called once per mini-program. Calling it a second time without extend.globalApp logs an error and returns immediately.Example
aApp
Alias for createApp. Use when your source DSL is Alipay mini-program.
wApp
Alias for createApp. Use when your source DSL is WeChat mini-program.
registerAppAdapters
Registers one or more cross-platform app adapters. Adapters are called during createApp and can mutate the app options before they are passed to the native App() constructor.
A single adapter object or an array of adapter objects to register.
Types
MorAppInstance
Properties injected onto every app instance created by createApp.
MorJS runtime hooks. Use these to tap into App / Page / Component lifecycles from plugins.
Global event emitter shared across the entire mini-program. Used internally to broadcast app-level events to pages and components.
App context containing the
query parameters received in onLaunch.Names of all MorJS plugins that have been loaded and initialised for the current app.
GetAppFunction
Type signature for the platform getApp function, extended to return MorAppInstance.
When
true, returns a default implementation if App has not yet been defined. Useful in standalone sub-packages.MorAppAdapter
Interface for app-level cross-platform adapters.
Called once during
createApp, before the native App() constructor runs. Receives the fully-constructed app options object.Lifecycle hooks
The following lifecycle methods are intercepted by MorJS and wrapped to fire the correspondingMorHooks entries:
| Method | MorHook |
|---|---|
onLaunch | appOnLaunch |
onShow | appOnShow |
onHide | appOnHide |
onError | appOnError |
onPageNotFound | appOnPageNotFound |
onUnhandledRejection | appOnUnhandledRejection |
appOnConstruct hook (or appOnInit for backwards compatibility) fires synchronously at the start of createApp, before any lifecycle wiring occurs.