A micro-frontend cross-application information sharing method and micro-frontend architecture system

By using the event center and the target value to deliver the relationship pool in the data center of the micro front-end architecture, the data status between sub-applications is quickly transferred, which solves the problems of low data transfer efficiency and event interference in the existing technology, and improves the efficiency of the data transfer. Communication efficiency and flexibility.

CN118394548BActive Publication Date: 2024-10-29HUNDSUN TECH
View PDF 8 Cites 0 Cited by

Patent Information

Application Number
CN202410851557.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-06-28
Publication Date
2024-10-29
Estimated Expiration
2044-06-28

AI Technical Summary

Technical Problem

In complex micro-front-end application scenarios, existing technology is difficult to achieve rapid and accurate transfer of data status between sub-applications, resulting in low efficiency of information transfer processing processes, and problems of event interference and low communication efficiency.

Method used

By confirming whether there are observers in the observer pool in the event center of the data center, and using global monitoring events and target values ​​to deliver the relationship pool, when the target value changes, only the changed value is transmitted to the corresponding sub-application or base module, leaving The listening registration constraints of the base module provide flexible data communication methods.

Benefits of technology

It improves the efficiency of data communication across application scenarios, reduces the occupation of communication resources, provides a more flexible data communication method, avoids event interference and performance problems, and reduces implementation costs and complexity.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118394548B_ABST
    Figure CN118394548B_ABST
Patent Text Reader

Abstract

This application proposes a micro-frontend cross-application information sharing method and micro-frontend architecture, which decouples the relationship between the base module and the monitoring registration. By judging whether the observer pool is zero, the communication of subsequent data is triggered. Then, by using the target value to send the relationship pool, when the target value changes, the changed value is only transmitted to the corresponding sub-application and base module in the target value sending relationship pool. While ensuring the efficiency of data transmission, a more flexible data communication method is provided.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to micro-frontend technology, and more specifically, to a micro-frontend cross-application information sharing method and a micro-frontend architecture system. Background Art

[0002] As websites and web apps become more and more complex, microservices, as a technical paradigm widely used on the server side, have been widely extended to the front-end field, namely micro-frontends. In the implementation of micro-frontends, micro-application containerization solutions often use specialized micro-frontend frameworks, such as single-spa, qiankun, etc., to manage and schedule the lifecycle of multiple micro-applications.

[0003] In some complex application scenarios, such as scenarios with main-sub-applications or cross-sub-applications, it is often necessary to ensure the fast and accurate transmission and distribution of data status between different sub-applications.

[0004] In the existing technology, it is often necessary to use the monitoring mechanism of the micro front-end to achieve this. For the above scenarios, sub-applications are usually embedded in the base application, and in the specific data status transmission process, the information transmission between sub-applications needs to be based on the situation and needs of the base application. That is, for scenarios such as master-sub-application and cross-sub-application, the transmission of information has a strong coupling relationship with the base application, resulting in low efficiency of its processing process. Summary of the invention

[0005] The purpose of this application is to provide a micro-frontend cross-application information sharing method and a micro-frontend architecture system, which are used to improve the efficiency of data communication across application scenarios.

[0006] In order to achieve the above purpose, the technical solution adopted in the embodiment of the present application is as follows:

[0007] In a first aspect, an embodiment of the present application provides a micro-frontend cross-application information sharing method, the method is applied to a micro-frontend architecture system, the micro-frontend architecture system includes: a data center, a base module and multiple sub-applications, the method includes:

[0008] The event center in the data center confirms whether there is an observer in the observer pool; the observer is registered and generated by the base module or any one of the sub-applications;

[0009] If the observer exists, the target value is monitored through the global monitoring event;

[0010] If the target value changes, the target value change value is sent to the corresponding target sub-application or base module according to the target value sending relationship pool.

[0011] Optionally, before the step of the event center in the data center confirming whether there is an observer in the observer pool, the step further includes:

[0012] The event center receives a binding request sent by the base module or any sub-application;

[0013] The event center establishes a corresponding observer in the observer pool for the corresponding base module or any sub-application according to the binding request;

[0014] The event center determines whether the global monitoring event has been established;

[0015] If not, the event center establishes the global listening event.

[0016] Optionally, the step of monitoring events for the target value includes:

[0017] The event center receives an update data status message of a registered sub-application; the update data status message includes the target value and specified identification information; the specified identification information is the identification information of the sub-application or base module that can obtain the changed value when the target value changes;

[0018] The event center maintains the target value in a global state pool;

[0019] The event center maintains the designated identification information corresponding to the target value through a filter to establish a target value delivery relationship pool;

[0020] The data center monitors events of the target value in the global state pool.

[0021] Optionally, if the target value changes, the step of sending the change value of the target value to the corresponding target sub-application according to the target value distribution relationship pool includes:

[0022] When the event center monitors a change in the target value, it obtains a change value of the target value;

[0023] The event center sends the target value to the relationship pool maintained by the filter to confirm the specified identification information corresponding to the change value;

[0024] The event center sends the change value to the sub-application and / or the base module corresponding to the designated identification information.

[0025] Optionally, it also includes:

[0026] The data center receives a data acquisition message sent by any sub-application or the base module; the data acquisition message includes an acquisition instruction of the target value;

[0027] The data center sends the target value to the sub-application base module.

[0028] Optionally, it also includes:

[0029] When the global monitoring event is destroyed, the event center deletes all corresponding observers;

[0030] When any sub-application is destroyed, the event center deletes the corresponding observer in the observer pool.

[0031] In a second aspect, an embodiment of the present application provides a micro front-end architecture system, the micro front-end architecture system comprising: a data center, a base module and a plurality of sub-applications;

[0032] The event center in the data center is used to confirm whether there is an observer in the observer pool; the observer is registered and generated by the base module or any one of the sub-applications; if the observer exists, the target value is monitored through the global monitoring event; if the target value changes, the change value of the target value is sent to the corresponding target sub-application or base module through the relationship pool according to the target value.

[0033] In a third aspect, an embodiment of the present application provides an electronic device, including:

[0034] A memory for storing one or more programs;

[0035] processor;

[0036] When the one or more programs are executed by the processor, the method as described in any one of the first aspects above is implemented.

[0037] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements a method as described in any one of the above-mentioned first aspects.

[0038] In a fifth aspect, an embodiment of the present application provides a program product, which, when executed by a processor, implements a method as described in any one of the above-mentioned first aspects.

[0039] Compared with the prior art, the micro-frontend cross-application information sharing method and micro-frontend architecture system provided by the embodiment of the present application do not restrict whether the base module initiates the monitoring registration. The communication of subsequent data is triggered only by judging whether the observer pool is zero. Furthermore, due to the use of the target value distribution relationship pool, when the target value changes, the changed value is only transmitted to the corresponding sub-application and base module. While ensuring the efficiency of data transmission, a more flexible data communication method is provided.

[0040] In order to make the above-mentioned objects, features and advantages of the present application more obvious and easy to understand, preferred embodiments are specifically cited below and described in detail with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0041] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.

[0042] Figure 1 A schematic diagram of a scenario of data interaction across sub-applications;

[0043] Figure 2 This is another schematic diagram of a cross-sub-application data interaction scenario;

[0044] Figure 3 This is a schematic diagram of a micro-application architecture;

[0045] Figure 4 A schematic diagram of a micro-frontend architecture system provided by an embodiment of the present invention;

[0046] Figure 5 A schematic diagram of a process for sharing information across micro-frontend applications provided by an embodiment of the present invention;

[0047] Figure 6 A flowchart of another micro-frontend cross-application information sharing method provided by an embodiment of the present invention;

[0048] Figure 7 A schematic diagram of another micro-frontend architecture system provided by an embodiment of the present invention;

[0049] Figure 8 A flowchart of another micro-frontend cross-application information sharing method provided by an embodiment of the present invention;

[0050] Fig. 9 A schematic diagram of another micro-frontend architecture system provided by an embodiment of the present invention;

[0051] Fig.10 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0052] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, rather than all the embodiments. The components of the embodiments of the present application described and shown in the drawings here can be arranged and designed in various different configurations.

[0053] Therefore, the following detailed description of the embodiments of the present application provided in the accompanying drawings is not intended to limit the scope of the present application for which protection is sought, but merely represents selected embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without creative work are within the scope of protection of the present application.

[0054] It should be noted that similar reference numerals and letters represent similar items in the following drawings, so once an item is defined in one drawing, it does not need to be further defined and explained in subsequent drawings. At the same time, in the description of this application, the terms "first", "second", etc. are only used to distinguish the description and cannot be understood as indicating or implying relative importance.

[0055] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.

[0056] Figure 1 This is a schematic diagram of a scenario of cross-sub-application data interaction, see Figure 1 , wherein sub-application-1 is embedded in the base application. When the data state of sub-application-1 changes, it is necessary to trigger the information change of a specific page of sub-application-2.

[0057] In another possible scenario, Figure 2 This is another schematic diagram of cross-sub-application data interaction scenario, see Figure 2, where the page of sub-application-3 nests sub-application-4. When the data state of sub-application-4 changes, it triggers the change of sub-application-3. Then sub-application-4 quickly shows and hides block C in sub-application-4 according to the changes of sub-application-3 and its own changes.

[0058] Obviously, referring to the two examples above, for scenarios where the micro-frontend involves multiple sub-applications, there is a need for cross-application data communication between different sub-applications. The following uses the more mainstream qiankun architecture in the micro-application containerization solution as an example to explain the current cross-application data communication solution.

[0059] Specifically, Figure 3 This is a schematic diagram of a micro-application architecture, see Figure 3 The architecture includes: a base module corresponding to "Micro-Base", a sub-application-1 corresponding to "Micro-APP", a sub-application-2 corresponding to "Micro-APP", a global state pool and an event center.

[0060] For the Qiankun architecture, it usually uses "initGlobalState" to define the global state. After the method is executed, it will feedback a "MicroAppStateActions instance", which contains three parts:

[0061] 1. "onGlobalStateChange": Set the global state pool (GlobalState) - When setting a new target value, the architecture will perform a "shallow check" internally. If the global state pool is changed, a notification will be triggered to notify all observer functions in the event center, such as Figure 3 Shown are observer S, observer A, observer B, etc.

[0062] 2. "setGlobalState": Register an observer function - respond to changes in the global state pool. When the global state pool changes, the observer function is triggered.

[0063] 3. "offGlobalStateChange": cancel the observer function - the instance no longer responds to changes in the global state pool.

[0064] Combine the following Figure 3 The example shown here illustrates the above cross-sub-application data communication process:

[0065] Step 1. The base module registers and binds the monitoring function "initGlobalState";

[0066] Step 2: The base module sets up observer S, and the event center maintains the corresponding observer S;

[0067] Step 3, sub-application 1 and sub-application 2 use "onGlobalStateChange" to bind the monitoring function established by the base module, and set observer A and observer B respectively; then the event center maintains the corresponding observer A and observer B;

[0068] Step 4: When the sub-application or base module issues an update instruction for data, send "action" to update the data in the global state pool through "setGlobalState";

[0069] Step 5: When the global state pool changes, each sub-application or base module uses the observer of the event center to return the updated data to its own sub-application or base module.

[0070] Among them, for the base module, sub-application-1 and sub-application-2, they respectively use "onGlobalStateChange" to monitor the data changes in the global state pool, and then obtain updated data through observer S, observer A and observer B.

[0071] See Based on Figure 3 From the examples shown and their corresponding cross-application data communication solutions, we can find that:

[0072] 1. In the prior art, for the monitoring function of the global state pool, the process of registering the monitoring function must first be initiated based on the base module. For applications embedded in the third-party base, the sub-application needs to make event delivery adjustments according to the requirements of the base. Therefore, in the prior art, cross-application data communication has a strong coupling relationship with the base module, resulting in insufficient flexibility in data communication.

[0073] Second, when an application issues an update command, all observers in the event center will receive the updated data. However, in actual application scenarios, the updated data has no effect or meaning for some applications, which results in inefficient data communication and occupies communication resources.

[0074] 3. In the existing technical solutions, each sub-application or base module needs to passively obtain updated data by listening and waiting. It is necessary to make corresponding logical conversions for the return value of GlobalState in the onGlobalStateChange callback, and then dump it to the vuex / redux of the corresponding sub-application, and then combine the state management mechanism (vuex / redux) inside the sub-application to perform the corresponding display and hiding logic.

[0075] In order to solve the problem in the above technical solution that the monitoring based on the global state pool can only be initiated through the base module, resulting in poor flexibility.

[0076] The existing technology also proposes a mechanism to improve the freedom of interaction by using communication classes. The core idea is to use different communication classes to split the original global state pool into multiple pools, so that different applications can subscribe to different communication classes to conduct cross-application data communication relatively independently and freely.

[0077] However, the above method still has problems:

[0078] First, its communication mechanism is to build communication classes in different namespaces to split the global state pool. In essence, it is an event-driven mechanism. When the application scenario is more complex, once the event naming is repeated, it will cause interference and errors in events in different applications.

[0079] Second, in order to ensure that applications can be constrained in the same communication class, "EventHub.emit" and "EventHub.on" are usually used to match event monitoring, that is, when an application initiates an "EventHub.emit", each other application belonging to the communication class must initiate a matching "EventHub .on" to ensure the effective transmission of updated data. However, this method means that each data update corresponds to multiple "EventHub.emit" initiations in a communication class, and the communication efficiency is low.

[0080] 3. Each communication class must correspond to different event listeners, and the distribution and subscription of events are asynchronous. For complex scenarios, the management complexity of multiple events is high. Multiple communication classes correspond to the complex dependencies of multiple applications under the micro-application architecture, which further leads to unclear relationships between applications and events. And when there are a large number of event listeners and the communication processes triggered by them, performance problems will arise. It can be imagined that this mechanism will have unnecessary impact on the implementation cost, troubleshooting, and computing power requirements of the entire solution.

[0081] 4. When the application is destroyed, the event will not be removed automatically. Each event may be bound to multiple communication classes, and you need to manually call the relevant removal event to remove it, otherwise it will cause memory overflow.

[0082] 5. Since there is no global state pool, data is stored in the pool corresponding to a specific communication class. When data acquisition is needed, the threshold for data acquisition is raised invisibly, and the efficiency of data circulation is reduced.

[0083] In order to solve the problems caused by the above-mentioned prior art, an embodiment of the present invention provides a different implementation mechanism: by modifying the monitoring mechanism of the micro front end, it is freed from the constraints of the base module host and can be flexibly used under different base modules.

[0084] Optionally, Figure 4 A schematic diagram of a micro front-end architecture system provided by an embodiment of the present invention, see the Figure 4 The micro-frontend architecture system in this implementation builds a new "data center", which includes: event center and global state pool. All data interactions and operations between sub-applications and base modules are responded to through this data center.

[0085] Continue to see Figure 4 In this example, a base module and two sub-applications, namely, sub-application-1 and sub-application-2, are used for illustration.

[0086] exist Figure 4 On the basis of Figure 5 A schematic diagram of a micro-frontend cross-application information sharing method provided in an embodiment of the present invention, see Figure 5 , the method comprising:

[0087] Step 100: The event center in the data center confirms whether there is an observer in the observer pool.

[0088] Among them, the observer is registered and generated by the base module or any sub-application.

[0089] Step 101: If an observer exists, the target value is monitored through a global monitoring event.

[0090] Specifically, when an observer exists, the sub-application corresponding to the observer monitors the target value through the observer. Figure 4 As shown in the sub-application-2, if there is an observer in the data center, and the observer is observer B, then at this time, sub-application-2 monitors the event of the target value in the global state pool through observer B.

[0091] Step 102: If the target value changes, the target value change value is sent to the corresponding target sub-application and / or base module according to the target value distribution relationship pool.

[0092] Specifically, for this solution, a target value sending relationship pool can be maintained in the event center, and the target value sending relationship pool is used to indicate the sub-application or base module corresponding to a specific target value. That is, in this solution, by defining which sub-applications or base modules a specific target value needs to be sent to, the change value of the target value can be sent only to the sub-applications and base modules with corresponding requirements, thereby improving the efficiency of data communication.

[0093] The micro-frontend cross-application information sharing method provided by the embodiment of the present invention does not restrict whether the base module initiates the monitoring registration. The communication of subsequent data is triggered only by judging whether the observer pool is zero. Furthermore, since the target value is sent to the relationship pool, when the target value changes, the changed value is only transmitted to the corresponding sub-application and base module. While ensuring the efficiency of data transmission, a more flexible data communication method is provided.

[0094] At the same time, because it avoids splitting the global state pool using different communication classes, its implementation cost is lower and the complexity of solution maintenance is lower than the solution of using communication classes to communicate data in different namespaces.

[0095] Optionally, the data center can be implemented in the form of an npm installation package. Each sub-application and base module can be used by loading the npm installation package. The data center can be installed and used as flexibly as a component.

[0096] Optionally, since a core idea provided by the embodiment of the present invention is to separate the initialization and establishment of observers and global monitoring events from the condition that they must be initiated by the base module, a possible implementation method is provided below to illustrate how to construct observers and global monitoring events. Figure 5 On the basis of Figure 6 A flowchart of another micro-frontend cross-application information sharing method provided by an embodiment of the present invention is shown in Figure 6 , before step 100, further comprising:

[0097] Step 103: The event center receives a binding request sent by the base module or any sub-application.

[0098] Specifically, the binding request can be initiated by the base module or sub-application through "onGlobalStateChange", but the difference between "onGlobalStateChange" and the prior art is that the binding request initiated by it also contains identification information for characterizing the base module or sub-application, so that in the subsequent process of sending the target value, the identification information can be used to achieve targeted information sending.

[0099] In addition, in this solution, both the base module and the sub-application can directly initiate the process of establishing the observer. Unlike the existing technology, the base module does not need to initiate the process of registering the monitoring function through "initGlobalState", such as initiating registration and monitoring tasks, establishing global monitoring events, defining the global state pool, etc., thereby achieving cross-application data communication and decoupling from the base module.

[0100] Step 104: The event center establishes a corresponding observer in the observer pool for the corresponding base module or any sub-application according to the binding request.

[0101] Step 105: The event center determines whether the global monitoring event has been established.

[0102] Specifically, when there is an observer in the observer pool, that is, when step 104 has completed the establishment of the observer, it is necessary to confirm whether the global listening event in the data center has completed initialization, that is, whether it has been established. If not established, execute step 106. If established, based on the observer established in steps 103 and 104, the existing global listening event can be used to Figure 5 Step 100 and subsequent steps are shown to perform operations related to target value monitoring and change value delivery.

[0103] Step 106: The event center establishes a global monitoring event.

[0104] Specifically, if the global listening event is not established, for example, when the first observer is established, or the global listening event is not initialized, step 106 needs to be executed.

[0105] It should be noted that see Figure 6 After the establishment of the global listening event is completed in step 106, the sub-application may be destroyed, the global listening event may be destroyed, and the observer may be deleted. Therefore, when monitoring the target value, it is necessary to first determine whether there is an observer in the observer pool, that is, the above step 100. If there is no observer in the observer pool at the current moment, it is necessary to return to step 106.

[0106] Specifically, in Figure 4 On the basis of Figure 7 A schematic diagram of another micro-frontend architecture system provided in an embodiment of the present invention, which is relative to Figure 4 , provides a specific implementation method for combining "MicroAppStateActions" instances with Figure 3 Compared with the prior art shown in the figure, Figure 7 It can be found that the base module in the embodiment of the present invention abandons "initGlobalState". For the base module or any sub-application, it only needs to establish an observer through "onGlobalStateChange".

[0107] Then, the event center executes the original "initGlobalState" logic, that is, completes the registration and monitoring tasks, defines the global state, and establishes global monitoring events. Therefore, for the third-party base module, this solution does not need to adapt the base module to realize the registration and initiation of the corresponding monitoring solution. In this solution, since the third-party base does not bear the above-mentioned "initGlobalState" logic, it and other sub-applications complete the establishment of observers through "onGlobalStateChange", thereby improving the applicability of this solution on different third-party base modules.

[0108] For details, see Figure 7 The base module establishes observer S in the event center through "onGlobalStateChange"; similarly, the sub-application-1 establishes observer A in the event center through "onGlobalStateChange"; the sub-application-2 establishes observer B in the event center through "onGlobalStateChange".

[0109] Optionally, in Figure 5 On the basis of Figure 8 A flowchart of another micro-frontend cross-application information sharing method provided by an embodiment of the present invention is shown in Figure 8 , step 101, comprising:

[0110] Step 101 - 1 : The event center receives an update data status message of a registered sub-application.

[0111] The registered sub-application refers to a sub-application that has established an observer; the updated data status message includes a target value and specified identification information; the specified identification information is the identification information of the sub-application or base module that can obtain the changed value when the target value changes. Optionally, the registered sub-application can also be a base module.

[0112] Step 101-2: The event center maintains the target value in the global state pool.

[0113] Step 101 - 3 : The event center maintains the designated identification information corresponding to the target value through the filter to establish a target value delivery relationship pool.

[0114] Specifically, the target value delivery relationship pool is used to indicate which sub-applications and / or base modules the changed value can be shared with when a specific target value changes.

[0115] Step 101-4: The data center monitors events of the target value in the global state pool.

[0116] Continue to see Figure 8, step 102 specifically includes:

[0117] Step 102-1: When the event center monitors that the target value changes, the change value of the target value is obtained.

[0118] Step 102-2: The event center sends the target value maintained by the filter to the relationship pool to confirm the designated identification information corresponding to the change value.

[0119] Optionally, if the target value is sent to the relationship pool and a specific target value does not specify clear identification information, the event center can send the change value to all base modules and sub-applications corresponding to the identification information in the form of broadcast.

[0120] Step 102-3: The event center sends the change value to the sub-application and / or base module corresponding to the specified identification information.

[0121] For details, see Figure 7 , taking sub-application-1 as an example, after sub-application-1 completes the establishment of observer A through "onGlobalStateChange", it can initiate a data status update message to the data center based on "SetGlobalState", which may include: target value and specified identification information. For example, the target value is "A=1", and the specified identification information is the identification information "002" of sub-application-2. Corresponding to the previous step 101-2, the event center in the data center will maintain the specified identification information corresponding to the target value through a filter. And the data center monitors events for the target value that has been maintained in the global state pool. Specifically, the above event monitoring can be implemented using the observer in the event center.

[0122] Optionally, referring to the foregoing, the target value sending relationship pool can obtain the correspondence between the observer and the identification information through "onGlobalStateChange", and then obtain the correspondence between the target value and the specified identification information based on "SetGlobalState". Thus, a complete correspondence of "observer-specified identification information-target value" is formed, and its function is: when A changes, the filter in the event center first determines which sub-applications or base modules the change of the target value needs to be returned to. In this example, since the target value "A=1" corresponds to the specified identification information "002", at this time, when the target value changes, the filter determines that the sub-application-2 in the target value sending relationship pool has a corresponding relationship, and then the observer B corresponding to the sub-application-2 will obtain the change value from the global state pool and return the change value, that is, update the state.

[0123] It should be noted that the above only takes the identification information of sub-application-2 and the target value "A=1" as an example of having a specified relationship. Obviously, it can also have a similar specified relationship with other sub-applications or base modules, so that when the target value changes, the changed value is sent to the target value relationship pool and flexibly returned to the corresponding one or more sub-applications, the combination of sub-applications and base modules, or only the base module.

[0124] In addition, it should be noted that in the above Figure 5 and Figure 8 In the example shown, when it is determined in step 100 that there is no observer in the observer pool, Figure 6 The mechanism shown returns to executing step 106 to establish a "global listening event".

[0125] In summary, for the embodiment of the present invention, since the data status message is updated by using "SetGlobalState" feedback in each sub-application, the specified identification information is fed back while clarifying the target value. Thus, the target value in the global state pool is flexibly associated with all or part of the sub-applications and base modules. When the target value changes, the data interaction can be global or local. While ensuring the efficiency of data communication, the flexibility of data communication is improved.

[0126] Optionally, for the prior art, whether it is a cross-application data communication scheme based on data broadcasting in the global state initiated by the base module, or splitting the global state pool to perform data communication in a communication class. Its data communication method is passive, that is, only when the data changes, the application passively obtains the change value of the data by listening. However, in the actual scenario of micro-applications, for some applications, for certain data in the global state pool, if the data can be actively obtained, the efficiency and flexibility of data communication can be improved. Below, an embodiment of the present invention provides a possible implementation method to achieve flexible acquisition of data in the global state pool. Specifically, the method includes:

[0127] The data center receives a data acquisition message sent by any sub-application or base module.

[0128] Specifically, the data acquisition message includes an acquisition instruction of the target value.

[0129] In turn, the data center sends the target value to the sub-application or base module.

[0130] Specifically, in Figure 7 On the basis of Fig. 9 A schematic diagram of another micro-frontend architecture system provided by an embodiment of the present invention. Fig. 9 , relative to Figure 7, the embodiment of the present invention introduces a new sub-application-3, which can have similar functions to sub-application-1 or sub-application-2, such as using "onGlobalStateChange" to establish an observer to monitor data changes; using "SetGlobalState" to specify a target value and specify identification information, etc.

[0131] In the embodiment of the present invention, the sub-application-3 can also use "GetGlobalState" to implement the data acquisition function, that is, use "GetGlobalState" to send a data acquisition message to the global state pool. Correspondingly, the global state pool can expose the data to the sub-application-3 through the "expose Getter" method.

[0132] It should be noted that Fig. 9 The sub-application-3 shown is a registered sub-application that has completed the establishment of relevant observers. In another possible implementation, a sub-application can also directly obtain the data maintained by the "exposed Getter" method in the global state pool through the above data acquisition message without performing the observer-related establishment process.

[0133] In addition, compared with the method of splitting the global state pool by using the communication class, even if the data can be shared, it can only be realized in the sub-data pool corresponding to the same communication class, and it is impossible to actively obtain data globally. In the above example of this application, the data of the global state pool can be obtained by any sub-application or base module, and the data communication efficiency is significantly improved.

[0134] In another possible implementation, the observers maintained in the data center observer pool in the above example can be deleted when the corresponding sub-application is destroyed. This ensures a flexible and accurate correspondence between observers and sub-applications and base modules. Specifically, the following situations exist:

[0135] Case 1: When the global monitoring event is destroyed, the event center deletes all corresponding observers.

[0136] Specifically, each time the target value corresponding to the global listening event is issued, a "hasEventListener" judgment can be performed to confirm whether the global listening event is destroyed. In addition, as mentioned above, when the observer pool is empty and no new observer is established, the global listening event can also be destroyed. At this time, since there is no observer, it does not involve the deletion of related observers.

[0137] Case 2: When a specific sub-application is destroyed, the event center deletes the observer corresponding to the sub-application.

[0138] Specifically, when the sub-application is destroyed, the corresponding observer state is "inactive state", and the event center can delete the observer in the "inactive state" based on the confirmed observer state.

[0139] In this solution, there is no need to set up different communication classes, but data changes are monitored based on a global monitoring event. This avoids the need to manually remove the corresponding event monitoring for different communication classes when the application is destroyed in the event-driven data communication method, ensuring the communication efficiency of data communication and reducing the implementation cost.

[0140] Optionally, see above, the embodiment of the present invention also provides a micro front-end architecture system, see above Figure 4 , Figure 7 as well as Fig. 9 As shown, the micro front-end architecture system includes: a data center, a base module and multiple sub-applications.

[0141] The event center in the data center is used to confirm whether there is an observer in the observer pool; the observer is registered and generated by the base module or any sub-application; if there is an observer, the target value is monitored through the global monitoring event; if the target value changes, the target value change value is sent to the corresponding target sub-application or base module according to the target value distribution relationship pool.

[0142] The micro-frontend architecture system can be used to execute each process step in the above example to achieve the corresponding technical effects.

[0143] The embodiment of the present invention further provides an electronic device, which can execute all the steps of the above examples of the embodiment of the present invention to achieve the corresponding technical effects. Specifically, Fig.10 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention, see Fig.10 , the electronic device 20, comprises: a memory 201, a processor 200;

[0144] Memory 201, used to store one or more programs;

[0145] Processor 200;

[0146] When one or more programs are executed by the processor, when the electronic device 20 is used to execute the steps shown in the above-mentioned method examples, it can achieve each step and corresponding technical effects.

[0147] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can also be implemented in other ways. The device embodiments described above are merely schematic. For example, the flowcharts and block diagrams in the accompanying drawings show the possible architecture, functions and operations of the devices, methods and program products according to the multiple embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of the code, and a part of the module, program segment or code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of boxes in the block diagram and / or flowchart can be implemented with a dedicated hardware-based system that performs a specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions.

[0148] In addition, the functional modules in the various embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.

[0149] If the function is implemented in the form of a software function module and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application can be essentially or partly embodied in the form of a software product that contributes to the prior art. The program product is stored in a computer-readable storage medium and includes several instructions for a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, and other media that can store program codes.

[0150] The above are only preferred embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.

[0151] It will be apparent to those skilled in the art that the present application is not limited to the details of the exemplary embodiments described above, and that the present application can be implemented in other specific forms without departing from the spirit or essential features of the present application. Therefore, the embodiments should be considered exemplary and non-limiting in all respects, and the scope of the present application is defined by the appended claims rather than the above description, and it is intended that all changes falling within the meaning and scope of the equivalent elements of the claims be included in the present application. Any reference numeral in a claim should not be considered as limiting the claim to which it relates.

Claims

1. A micro-frontend cross-application information sharing method, characterized in that: The method is applied to a micro front-end architecture system, the micro front-end architecture system comprising: a data center, a base module and a plurality of sub-applications, the method comprising: The event center in the data center confirms whether there is an observer in the observer pool; the observer is registered and generated by the base module or any one of the sub-applications; If the observer exists, the event center receives the updated data status message of the registered sub-application; the updated data status message includes the target value and the specified identification information; the specified identification information is the identification information of the sub-application or base module that can obtain the changed value when the target value changes; The event center maintains the target value in a global state pool; The event center maintains the designated identification information corresponding to the target value through a filter to establish a target value delivery relationship pool; The data center monitors events of the target value in the global state pool; If the target value changes, the target value change value is sent to the corresponding target sub-application or base module according to the target value sending relationship pool; the target value sending relationship pool is used to indicate the sub-application or the base module corresponding to the target value.

2. The method according to claim 1, characterized in that Before the step of the event center in the data center confirming whether there is an observer in the observer pool, the step further includes: The event center receives a binding request sent by the base module or any sub-application; The event center establishes a corresponding observer in the observer pool for the corresponding base module or any sub-application according to the binding request; The event center determines whether the global monitoring event has been established; If not, the event center establishes the global listening event.

3. The method according to claim 1, characterized in that If the target value changes, the step of sending the change value of the target value to the corresponding target sub-application according to the target value distribution relationship pool includes: When the event center monitors a change in the target value, it obtains a change value of the target value; The event center sends the target value to the relationship pool maintained by the filter to confirm the specified identification information corresponding to the change value; The event center sends the change value to the sub-application and / or the base module corresponding to the designated identification information.

4. The method according to claim 1, characterized in that Also includes: The data center receives a data acquisition message sent by any sub-application or the base module; the data acquisition message includes an acquisition instruction of the target value; The data center sends the target value to the sub-application base module.

5. The method according to claim 1, characterized in that Also includes: When the global monitoring event is destroyed, the event center deletes all corresponding observers; When any sub-application is destroyed, the event center deletes the corresponding observer in the observer pool.

6. A micro front-end architecture system, characterized in that: The micro front-end architecture system includes: a data center, a base module and multiple sub-applications; The event center in the data center is used to confirm whether there is an observer in the observer pool; the observer is registered and generated by the base module or any one of the sub-applications; if the observer exists, the event center receives the updated data status message of the registered sub-application; the updated data status message contains a target value and specified identification information; the specified identification information is the identification information of the sub-application or base module that can obtain the changed value when the target value changes; the event center maintains the target value in the global status pool; the event center maintains the specified identification information corresponding to the target value through a filter to establish a target value sending relationship pool; the data center monitors events for the target value in the global status pool; if the target value changes, the change value of the target value is sent to the corresponding target sub-application or base module according to the target value sending relationship pool; the target value sending relationship pool is used to indicate the sub-application or base module corresponding to the target value.

7. An electronic device, characterized in that: include: A memory for storing one or more programs; processor; When the one or more programs are executed by the processor, the method according to any one of claims 1 to 5 is implemented.

8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 5 is implemented.

9. A program product, characterized in that When the program product is executed by a processor, the method according to any one of claims 1 to 5 is implemented.

Citation Information

Patent Citations

  • Application system of micro-front-end architecture, synchronization method, storage medium and equipment

    CN112363857A

  • Construction method and device of sub-application in micro-front-end mode, equipment and storage medium

    CN114327687A

  • Micro-front-end management method and device, electronic equipment and storage medium

    CN115390897A

  • Method for dynamically loading master and sub applications based on micro-front-end architecture

    CN115827105A

  • Sub-application dynamic registration and exception monitoring method based on micro front end

    CN116992182A