Self-study notes on WeChat mini program development - 8. Update and iteration of the mini program basic library

Update and iteration of the mini program basic library

Mini program basic library

The running environment of a mini program is divided into a rendering layer and a logic layer. In the rendering layer, various components can be used to construct interface elements. In the logic layer, various APIs can be used to process various logics. Components and APIs are actually the basis of mini programs. Provided by the library for packaging, the responsibilities of the basic library also need to handle a series of framework logic such as data binding, component system, event system, communication system, etc., so that the entire mini program can operate in an orderly manner.

The basic library of the applet is written in JavaScript, which can be injected into the rendering layer and logic layer to run.

Basic library loading timing

In order for the mini program business code to call wx.navigateTo and other APIs and components, it is necessary to load the basic library first after starting the mini program, and then load the business code.

The rendering layer and logic layer of the applet are managed by two threads. The WebView layer injected into the rendering layer is called the WebView basic library, and the logic layer injected into the AppService basic library.

When all mini programs are opened on the WeChat client, they need to inject the same basic library.

The basic library of the mini program will be built into the WeChat client in advance. The benefits of doing this are twofold:

  1. Reduce the code package size of business applet.
  2. Bugs in the basic library can be fixed independently without modifying the code package of the business applet.
The version number of the base library

The mini program basic library version number uses the semver specification, and the format is Major.Minor.Patch, where Major, Minor, and Patch are all integers.

In the mini program, you can obtain the mini program version number through the wx.getSystemInfo() or wx.getSystemInfoSync() method.

let info = wx.getSystemInfoSync()
console.log("小程序基础库版本号为:" + info.SDKVersion)

abnormal

JS runs abnormally

For general syntax errors and runtime errors, the browser will display the corresponding error information in the Console, as well as the error file, line number, and stack information.

How to catch JS exceptions

There are two methods to catch JS exceptions in the WebView layer:

  1. try, catch scheme. You can use try and catch packaging for a certain code block. When this code block runs into errors, it can be caught in the catch block.
  2. window.onerror scheme. You can also use window.addEventListener("error", function(evt){}). This method can capture syntax errors and runtime errors. It can also know the error information, as well as the error file, line number, and column number.

The basic library of the mini program uses the window.onerror solution on the WebView side to catch exceptions, and on the logic layer AppService side, it wraps the various life cycles of App instances and Page instances in try-catch to catch exceptions. At the same time, the onError callback is provided in the App constructor. When the business code runs and an exception occurs, this callback is triggered. At the same time, the specific information of the exception can be obtained. The developer can handle the corresponding fault-tolerance logic according to the business situation.

Updates to the base library

Base library version changes

Many capabilities of mini programs require the support of the WeChat client, such as Bluetooth, live broadcast capabilities, WeChat sports, etc. It can be said that the iteration of the mini program basic library is inseparable from the release of the WeChat client.

Push basic library process

The iteration speed of the basic library of small programs is very fast, but changes in the basic library will affect the operation of all small programs. If major bugs in the basic library are not discovered in time, many small programs will not be able to use normally, so when updating the basic library Be cautious.

First of all, before officially pushing the new version of the basic library in grayscale, there must be a strict automated testing process internally to ensure that all existing test cases can pass. At the same time, high-visited tests will also be run on the test machine with the latest version library. Some small programs and detect whether they have some abnormal phenomena such as white screens.

Then perform grayscale push. Generally, the grayscale time is 12 hours. When encountering some major code changes, the grayscale time may be longer. During the push process, observe whether there are any changes in the monitoring curve, and carefully analyze whether there are fatal errors in the corresponding reporting logs.

After the grayscale push is completed, the documentation for the new capabilities will be released. At this time, you should also pay attention to the bug feedback from the WeChat developer community, and decide whether to push the patch version to fix some bugs based on the situation.

Guess you like

Origin blog.csdn.net/qq_36842789/article/details/129377610