You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The upper part is the English version, and the lower part is the Chinese version, with the same content. If there are any wrong, or you have anything hard to understand, especially in the English version(it is modifications based on Google Translate), pls feel free to let me know.many thx.
Overview
Introduction to the mini program; analysis of the underlying structure of the mini program; its life cycle, etc.
1. What is the mini program
Mini program is an application located in the host Wechat, between Web App and Native App
Web app: SPA(single page web application)
Mini program running environment: IOS webkit (Apple's open source browser kernel), Android X5 (QQ browser kernel), nw.js in WeChat developer tools
Wechat blocks the BOM object, so most of the traditional JS libraries cannot be used
The mini program is still running in the browser mode, and wechat controls the life cycle. WXML, WXSS rendering page. js parse data、transfer data (setData) Official Mini Program Document Official Mini Program Management Backstage
2. The underlying architecture of the mini program
Logic layer: A separate thread executes Javascript code. In iOS is JavaScriptCore, In Android is JsCore of Tencent x5, and in the WeChat developer tool is nmjs framework
View layer: All tasks related to page rendering are executed in the WebView thread, and the logic layer is used to control which pages are rendered. One page on one WebView, but there is only one JsCore, so you can share data through the properties in the App instance
JSBridge: Mainly to provide JavaScript with an interface to call Native functions, so the mini programs can call native functions
The view layer is separated from the logic layer. Through data-driven and event interaction, it only operates ShadowDOM, not the real DOM directly. The logic layer provides data (SetData) to the page layer, and the page layer notifies the logic layer through binding/capturing events (Event).
Cold starting: the user opens the mini program for the first time, or the mini program is opened by the user again after being destroyed, the mini program needs to be reloaded and started
Hot starting: The user has opened a small program and then opened the small program again within a certain period of time. At this time, the small program has not been destroyed, but entered the foreground state from the background state After hiding, the official reply page destroyed time refers to almost 5 minutes, the actual situation is uncertain, it may be 5 minutes, or it may be 1 day
The mini program needs to download the update package asynchronously when it is cold-started, and update it in the next cold-start Official update instructions
If you need to apply the latest version immediately, you can use wx.getUpdateManager force the update to restart the mini program, or restart after the user confirms the pop-up window
Mini programs (including cold start) will not actively clear the cached data in the local storage. Third-party software such as WeSecure(腾讯手机管家), 360 Security(360手机卫士), etc. can do so
4. Mini Program Life Cycle
There are three kinds of objects in mini programs: App, Page and Component
When you start or cold start for the first time: App.onLaunch is executed only once, then App.onShow is executed, and then enters the life cycle of displaying Page
When exiting: Page.onHide => App.onHide
At hot starting: App.onShow => Page.onShow
Initialization: Page.onLoad => Page.onShow
Page out of the stack (page is closed, such as calling redirect/reLaunch): Page.onUnload
The page does not pop out of the stack (page cached to the background, such as calling navigate): Page.onHide
Component.created => Component.attached => Component.ready (only called at the first render)
When moving on the dom: Component.moved
The component is unloaded (when conditional rendering) or the page is unloaded: Component.detached
Regarding behavior, similar to mixin in Vue, a reuse of component logic. behavior's mixin hook will be called before the component calls its own hook. Such as Component.behavior.created => Component.created. Refer to behavior in the official website
Regarding pageLifetime (the component life cycle corresponding to the page): Component.pageLifetime.show => Page.onShow when displayed; Page.onHide => Component.pageLifetime.hide Refer to pageLifetime in the official website
Conclusion: 1. When the page is loaded/displayed, the behaviors life cycle takes priority over the component life cycle, and the component/pageLifetime life cycle takes precedence over the page life cycle; 2. When the page exits the stack/hidden, it is Page.onUnload => Component.detached
4.4 Application, Page, Component Life Cycle execution sequence
mominger
changed the title
Analysis of the underlying structure of the mini program(20210119)
Analysis of the underlying structure of the mini program
Mar 22, 2022
The upper part is the English version, and the lower part is the Chinese version, with the same content. If there are any wrong, or you have anything hard to understand, especially in the English version(it is modifications based on Google Translate), pls feel free to let me know.many thx.
Overview
1. What is the mini program
2. The underlying architecture of the mini program
2.1 Architecture diagram provided by Tencent
2.2 Analysis of the official architecture diagram
2.3 The communication process of each layer of the mini program
3. Starting the mini program
4. Mini Program Life Cycle
4.1 Application Life Cycle
Application Life Cycle in the official website
4.2 Page Life Cycle
4.3 Component Life Cycle
4.4 Application, Page, Component Life Cycle execution sequence
The following is the Chinese version, the same content as above.
概述
1. 什么是小程序
2. 小程序的底层架构
2.1 腾讯提供的架构图
2.2 对官方架构图的分析
2.3 小程序的各层通信流程
3. 小程序的启动
4. 小程序的生命周期
4.1 应用生命周期
参考官网的应用生命周期
4.2 页面生命周期
4.3 组件生命周期
4.4 应用、页面、组件生命周期执行顺序
The text was updated successfully, but these errors were encountered: