Application component calling method and device, equipment, storage medium and program product

Through the subscription distribution function of the event bus, the target events are replaced and distributed, which solves the coupling problem between application components, realizes complete decoupling of application components and independent processing of event execution logic, and improves the stability and maintainability of the application sex.

CN119149012APending Publication Date: 2024-12-17MASHANG CONSUMER FINANCE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410732910.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-06
Publication Date
2024-12-17

AI Technical Summary

Technical Problem

In componentized applications, there is a degree of coupling between application components, which makes calling an application component likely to affect other application components coupled to that application component, making it difficult to achieve complete decoupling.

Method used

Through the subscription distribution function of the event bus, responds to the call request of the target event, replaces the completed event in the application event bus with the target event, and distributes the target event to the target application component that pre-subscribes to the event, and executes the target event Event execution logic to achieve decoupling between application components.

Benefits of technology

It realizes complete decoupling between application components in the application, avoids unnecessary response or logical processing of other application components, and improves the maintainability and scalability of the code.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119149012A_ABST
    Figure CN119149012A_ABST
Patent Text Reader

Abstract

The invention provides an application component calling method and device, equipment, a storage medium and a program product. The method comprises the following steps: in response to a calling request for a target event in an application program, replacing a completed event in an event bus of the application program with the target event; calling an event bus of the application program, and distributing the target event to a target application component which subscribes the target event in advance; and calling the target application component, and executing the event execution logic of the target event. Through the application, the application components in the application program can be completely decoupled.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data processing technology, and in particular to an application component calling method, device, equipment, storage medium and program product. Background Art

[0002] As one of the mainstream approaches to mobile application architecture, componentization has been the direction of active exploration and practice in the industry in recent years. With the advancement of componentization, if you want to componentize all applications and use a unified protocol for communication between components, then the final output of the application should be like factory processing. The processing process is the component combination process, and the application label is affixed when it leaves the factory. This process is the de-application process of the application, and the de-application process requires a shell engineering solution, which is responsible for the life cycle management, application configuration, and function assembly of the application through shell engineering.

[0003] However, the component codes of all application components of the application are written in a shell project. There is a certain degree of coupling between the application components in the shell project. Calling a certain application component may affect the application components coupled with the application component. Summary of the invention

[0004] The embodiments of the present application provide an application component calling method, apparatus, device, storage medium, and program product, which can completely decouple application components in an application program.

[0005] The technical solution of the embodiment of the present application is implemented as follows:

[0006] An embodiment of the present application provides an application component calling method, the method comprising: in response to a call request for a target event in an application, replacing a completed event in an event bus of the application with the target event; calling the event bus of the application to distribute the target event to a target application component that has pre-subscribed to the target event; calling the target application component to execute the event execution logic of the target event.

[0007] An embodiment of the present application provides an application component calling device, including: an event replacement module, which is used to replace a completed event in the event bus of the application with the target event in response to a call request for a target event in the application; an event distribution module, which is used to call the event bus of the application and distribute the target event to a target application component that has pre-subscribed to the target event; and an execution module, which is used to call the target application component and execute the event execution logic of the target event.

[0008] An embodiment of the present application provides an electronic device, comprising: a memory for storing computer-executable instructions; and a processor for implementing the application component calling method provided in the embodiment of the present application when executing the computer-executable instructions stored in the memory.

[0009] An embodiment of the present application provides a computer-readable storage medium storing computer-executable instructions for implementing the application component calling method provided in the embodiment of the present application when executed by a processor.

[0010] An embodiment of the present application provides a computer program product, which includes executable instructions stored in a computer-readable storage medium; wherein a processor of an electronic device reads the executable instructions from the computer-readable storage medium and executes the executable instructions to implement the application component calling method provided in the embodiment of the present application.

[0011] The embodiments of the present application have the following beneficial effects:

[0012] First, once the target event is triggered in the application, the completed event in the event bus will be replaced with the target event, that is, the completed event will be deleted from the event bus, and the target event will be added to the event bus. At this point, it can be determined that the event in the event bus is the currently triggered target event, and based on the event bus, the target application component that has subscribed to the target event in advance can also be determined. In this way, the event bus of the application is called, and the target event is distributed to the target application component that has subscribed to the target event in advance, so that the target application component can effectively execute the event execution logic of the target event when it is called later. That is, when the target event is triggered, the call of the target application component is realized by replacing the completed event in the event bus with the target event, which only involves the target application component that has subscribed to the target event in advance, and only needs to execute the event execution logic of the target event through the target application component, without calling other application components in the application, and other application components do not need to make corresponding responses or logical processing to the target event, so that the application components of different system events in the application can be completely decoupled. BRIEF DESCRIPTION OF THE DRAWINGS

[0013] Figure 1 It is a structural diagram of the application component calling system provided in an embodiment of the present application;

[0014] Figure 2 This is an optional flowchart of the application component calling method provided in the embodiment of the present application;

[0015] Figure 3 is another optional flow chart of the application component calling method provided in the embodiment of the present application;

[0016] Figure 4 It is a structural diagram of any APP project provided in the embodiment of the present application;

[0017] Figure 5 It is a structural diagram of an application component calling device provided in an embodiment of the present application;

[0018] Figure 6 It is a schematic diagram of the composition structure of the electronic device provided in the embodiment of the present application. DETAILED DESCRIPTION

[0019] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be further described in detail below in conjunction with the accompanying drawings. The described embodiments should not be regarded as limiting the present application. All other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of this application.

[0020] In the following description, reference is made to “some embodiments”, which describe a subset of all possible embodiments, but it will be understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.

[0021] Unless otherwise defined, all technical and scientific terms used in the embodiments of the present application have the same meanings as those commonly understood by those skilled in the art. The terms used in the embodiments of the present application are only for the purpose of describing the embodiments of the present application and are not intended to limit the present application.

[0022] The relevant data collection and processing in the embodiments of this application should be strictly in accordance with the requirements of relevant national laws and regulations when applied in examples, obtain the informed consent or separate consent of the personal information subject, and carry out subsequent data use and processing within the scope of authorization of laws and regulations and the personal information subject.

[0023] Before further describing the embodiments of the present application in detail, the nouns and terms involved in the embodiments of the present application are explained. The nouns and terms involved in the embodiments of the present application are subject to the following interpretations.

[0024] 1) Componentization: It is a software architecture design pattern that splits a large application into multiple independent and reusable modules, each of which is called a component. Componentization can improve the maintainability, scalability and reusability of the application, and also facilitate team collaboration and code reuse.

[0025] 2) Shell project: responsible for managing the business components of the application and packaging the application. It does not handle any business and is just an empty shell. It combines the required component modules to form a complete application.

[0026] 3) Subscription mode: It is a design mode used to handle one-to-many relationships between objects. When the state of an object changes, all objects subscribed to the object will be notified and automatically updated. The subscription mode can reduce the coupling between objects and improve the maintainability and scalability of the code. Common application scenarios include event monitoring, message push, etc.

[0027] The solution of related technologies is to first complete the application lifecycle management of the application (APP) by customizing a software development kit (SDK), and then let the shell project of the APP project inherit the class implementation in the SDK. Related technologies require appropriate modifications to the APP project. For example, 1) the AppDelegate class in the APP project must inherit the class provided by the SDK, which will cause additional modifications and make it impossible for any APP project to complete the application component call without intrusion; 2) It is impossible to subscribe to or distribute the system events and execution priority of AppDelegate; 3) For any APP project, there is no supporting cloud construction, application management and other configurations.

[0028] Based on at least one problem existing in the related art, the embodiment of the present application uses the subscription distribution function of the event bus. After the application is loaded, the application component in the application automatically subscribes to the system event that needs to be subscribed in advance, and through the replacement processing of the system event in the event bus, the system event is published to the application component that pre-subscribes to the system event through the event bus, and the application component is used to execute the event execution logic of the system event, so as to realize the decoupling between the application components in the application, so that the application component call can be completed for any application without intrusion. The application in the embodiment of the present application can be any application, and the communication between the application components is realized through routing calls, so as to realize the complete decoupling between the application components.

[0029] See also Figure 1 , Figure 1 It is a structural diagram of the application component calling system 100 architecture provided in an embodiment of the present application. To support an application component calling an application, the terminal 400 is connected to the server 200 via the network 300. The network 300 can be a wide area network or a local area network, or a combination of the two.

[0030] Terminal 400 is used to send an event call request for a target event in an application to server 200, and server 200 is used to respond to the call request for a target event in the application, replace the completed event in the event bus of the application with the target event; call the event bus of the application, distribute the target event to the target application component that has pre-subscribed to the target event; call the target application component, execute the event execution logic of the target event, obtain the target event execution result, and return the target event execution result to terminal 400, so as to output the target event execution result at terminal 400.

[0031] In some embodiments, the server 200 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDN), and big data and artificial intelligence platforms and other basic cloud computing services. The server 200 can also belong to an SRE engineer and can be operated by an SRE engineer. The terminal 400 can be a smart phone, a tablet computer, a laptop computer, a desktop computer, a smart speaker, a smart watch, a car terminal, etc. The terminal 400 can also be a seat client, but is not limited to this. The terminal 400 and the server 200 can be directly or indirectly connected by wired or wireless communication, which is not limited in the embodiments of the present application.

[0032] The application component calling method provided in each embodiment of the present application can be executed by an electronic device, wherein the electronic device can be a server or a terminal, that is, the application component calling method provided in each embodiment of the present application can be executed by a server, can be executed by a terminal, or can be executed through interaction between a server and a terminal.

[0033] See also Figure 2 , Figure 2 is an optional flow chart of the application component calling method provided in the embodiment of the present application, which will be combined with Figure 2 The steps shown are described in detail, and the execution subject of the application component calling method is taken as an example as a server. The method includes the following steps S101 to S103:

[0034] Step S101 , in response to a call request for a target event in an application, replacing a completed event in an event bus of the application with the target event.

[0035] In the embodiment of the present application, an application is a software system running in a specific environment. The application contains many different application components, and these application components interact in a specific way. The application also includes multiple system events. The target event refers to the system event that needs special attention and processing in the application at the current moment. It is a predetermined system event in the application, usually corresponding to a specific behavior or operation. For example, the target event can be the startup event, login event, privacy consent authorization event, etc. of the application. A completed event refers to a system event that has been processed or distributed in the event bus before the current moment. A call request can be a request to call a specific system event in the application, which is used to indicate event processing for a specific system event. The event bus of the application is an event management platform for managing system events in the application. The event bus allows event communication between different application components. The pre-subscription of the application component to the system event and the distribution of the system event can be completed through the event bus, so that the system event can be distributed to the application component that pre-subscribes to the system event through the event bus, and the event execution logic corresponding to the system event is completed through the application component, thereby achieving complete decoupling between application components in the application.

[0036] When the application wants to call the target event, the client sends a call request for the target event in the application to the server. The server responds to the call request for the target event in the application sent by the client. First, it needs to determine the target event and the completed events in the event bus of the application, and determine the system event with the completed mark in the event bus as the completed event. Then, the target event is added to the event bus by replacement. The replacement method refers to replacing the completed event in the event bus of the application with the target event, so that at the current moment, the system event in the event bus has and only has the target event, so that the target event can be accurately distributed by calling the event bus later.

[0037] Step S102: calling the event bus of the application program to distribute the target event to the target application component that has subscribed to the target event in advance.

[0038] In the embodiment of the present application, the target application component is the application component that pre-subscribes to the target event among all application components of the application. There is a subscription relationship between each application component in the application and the system event, and the subscription relationship is pre-stored in the event bus. Each application component in the application subscribes to a system event, and a system event may be subscribed by one application component, and a system event may also be subscribed by multiple application components at the same time. Therefore, the target application component can be one or more.

[0039] For example, suppose the application is an e-commerce platform. The application components in the platform may include product display components, order processing components, payment components, and user management components. These application components will subscribe to a series of system events so that they can handle the system events accordingly when they occur. For example, when a user places an order, an order creation event will be generated. The order creation event will be pre-subscribed by the order processing component so that the order processing component can immediately obtain the order information and start processing the order. At the same time, the payment component will also pre-subscribe to this event because after the order is created, the payment component needs to know the order information in order to process the payment process. In addition, the user management component may also pre-subscribe to this event in order to record the payment process of the user's order, and perform payment result analysis or loyalty rewards. Therefore, when the order creation event is added to the event bus, the event bus distributes the order creation event to the order processing component, payment component, and user management component.

[0040] After the completed event in the event bus is replaced with the target event, the target event is triggered, and the event bus will search for the application component that has a subscription relationship with the target event in the above subscription relationship, that is, the target application component that has subscribed to the target event in advance. In addition, the target event is distributed to the target application component, and the target application component that has subscribed to the target event in advance will receive the event notification, so that the subsequent target application component can perform corresponding operations based on the event notification.

[0041] In some embodiments, the replacement process can be implemented through a hook function, or through aspect-oriented programming (AOP) technology, or through pre-compilation and runtime dynamic proxy, so as to dynamically and uniformly add functions to the application without modifying the source code of the application. The implementation method of the replacement process is not specifically limited here.

[0042] Here, the target event is distributed through the event bus, so that the application component that pre-subscribes to the target event can subsequently complete the execution operation of the event execution logic of the target event. The execution operation does not involve other application components in the application, thereby achieving decoupling between application components in the application.

[0043] Step S103, calling the target application component to execute the event execution logic of the target event.

[0044] In the embodiment of the present application, the event execution logic of the target event refers to the specific operation or underlying processing logic that needs to be executed when the target event is triggered. After determining the target application component corresponding to the event execution logic, the target application component is called according to the instructions in the event notification of the event bus. The target application component determines the event execution logic of the target event according to its own component execution function and the event type of the target event, and executes the event execution logic.

[0045] Here, by calling the target application component corresponding to the target event and executing the event execution logic, for any target event in the application, there is no need to involve application components other than the target application component corresponding to the target event, thereby completely decoupling the application components in the application.

[0046] The application component calling method provided by the embodiment of the present application, first, once the target event is triggered in the application, the completed event in the event bus will be replaced with the target event of the target event, that is, the completed event is deleted from the event bus, and the target event is added to the event bus. At this time, the event in the event bus can be determined to be the target event currently triggered, and based on the event bus, the target application component that subscribes to the target event in advance can also be determined. In this way, the event bus of the application is called, and the target event is distributed to the target application component that subscribes to the target event in advance, so that the target application component can effectively execute the event execution logic of the target event when it is called later. That is, when the target event is triggered, the call of the target application component is realized by replacing the completed event with the event bus of the target event, which only involves the target application component that subscribes to the target event in advance, and only needs to execute the event execution logic of the target event through the target application component, without calling other application components in the application, and other application components do not need to make corresponding responses or logical processing to the target event, so that the application components of different system events in the application can be completely decoupled.

[0047] The following will explain the application component calling method in the embodiment of the present application in conjunction with the interaction process between the server and the terminal (i.e., the above-mentioned client) in the application component calling system. It should be noted that the application component calling method here is an application component calling method implemented by interaction between the server and the terminal, which is essentially the same as the application component calling method executed by the server in the above-mentioned embodiment. The only difference is that the embodiment of the present application also describes the actions performed by the terminal during the execution of the application component calling method, and some steps can be executed by both the terminal and the server. Therefore, for the steps in this embodiment that are the same as those in the above-mentioned embodiment but have different execution subjects, this embodiment is only an exemplary description. In the process of implementation, it can be executed by any execution subject, and the embodiment of the present application does not limit this.

[0048] See also Figure 3 , Figure 3 is another optional flow chart of the application component calling method provided in the embodiment of the present application, such as Figure 3 As shown, the method includes the following steps S201 to S214:

[0049] Step S201: The terminal receives a calling operation input by a user for a target event in an application.

[0050] In the embodiment of the present application, the user can input the call operation for the target event in the application program on the client of the application component calling application. In the application component calling application, an application component calling function can be provided, and the user (who can be an application component calling engineer or a developer of the application component calling application) can input the call operation for the target event in the application program on the application component calling function page. In some embodiments, when inputting the call operation for the target event in the application program, the target event can be input at the same time.

[0051] Step S202: The terminal generates a call request in response to a call operation for a target event in the application.

[0052] In the embodiment of the present application, the data input by the user can be encapsulated into the call request. For example, the target event input by the user can be encapsulated into the call request.

[0053] Step S203: the terminal sends a call request for a target event in the application to the server.

[0054] Step S204: In response to the call request for the target event in the application, the server determines the system event carrying the completed flag in the event bus of the application as a completed event.

[0055] In an embodiment of the present application, an application includes a plurality of system events, each of which corresponds to an event execution logic, and the event execution logic is stored in a preset logic library. The event bus is used to be responsible for the subscription and distribution of system events in the application. When the event bus completes the distribution of a certain system event, a completed mark is added to the system event, or the event state of the system event is converted from the event distribution state to the completed state, and the mark of the event state is converted from the event distribution mark to the completed mark. Therefore, when a call request for a target event is received at the current moment, the event bus has completed the distribution of the system event at the previous moment, and the system event in the event bus is a completed system event, that is, a completed event, and the completed event now carries a completed mark. The system event carrying a completed mark in the event bus can be directly determined as a completed event.

[0056] Step S205: The server determines the event address of the completed event in the event bus.

[0057] In the embodiment of the present application, the event address of the completed event in the event bus is usually determined by the configuration and definition of the event bus, and the event address is used to locate and access specific events in the event bus. In the event bus, the event address may include an identifier, a timestamp, and other related attributes of the event, and the event address of the published event can be obtained by querying the storage of the event bus. After determining that the event has been completed, the event address of the completed event in the event bus can be determined, so that the subsequent event address can be used to quickly and accurately replace the completed event.

[0058] Step S206: The server replaces the completed event with the target event based on the event address.

[0059] In an embodiment of the present application, when the server receives a call request for a target event sent by a terminal, if the call request encapsulates a target event, the call request can be parsed to obtain the target event in the event call request.

[0060] After obtaining the event address of the completed event in the event bus, the completed event in the event bus is deleted, and the target event is added to the event address, that is, the completed event in the event bus is replaced with the target event. Here, by replacing the completed event in the event bus, the event to be distributed in the event bus has only the target event, so that the target event can be accurately distributed by calling the event bus later.

[0061] Step S207: the server determines the execution priority of each target application component.

[0062] In the embodiment of the present application, the target application component is an application component that pre-subscribes to the target event among all application components of the application, and the number of target application components can be one or more. The subscription relationship between the target application component and the target event can be determined by the event bus of the application, and the event bus of the application includes a preset application component subscription library.

[0063] For each system event in the application, determine the second component identifier and execution priority of the application component that pre-subscribes to the system event; build an application component subscription library based on the event identifier of the system event, the second component identifier and execution priority of the application component that pre-subscribes to the system event; store the application component subscription library in the event bus.

[0064] Among them, the execution priority refers to the different priorities corresponding to the application components that pre-subscribe to the same system event. When a system event is distributed through the event bus, among the application components that pre-subscribe to the system event, the application components with high priority can respond to the system event first and execute the corresponding processing logic; the application components with low priority need to wait for the application components with high priority to execute the corresponding processing logic before they can respond to the system event. Each system event corresponds to an event identifier. For each system event, the component identifier of the application component that pre-subscribes to the system event is determined as the second component identifier. The preset application component subscription library is a preset database in the event bus for determining the subscription relationship between system events and application components in the application. The application component subscription library stores the event identifier of each system event, the second component identifier of the application component that pre-subscribes to the system event, and the execution priority of each application component when there are multiple application components that pre-subscribe to the system event.

[0065] That is to say, the target application component that pre-subscribes to the target event can be determined in the following way: first, obtain the component subscription array corresponding to the event identifier of the target event from the application component subscription library; then, obtain the first component identifier from the component subscription array; finally, determine the application component corresponding to the first component identifier as the target application component.

[0066] The first component identifier is the component identifier of the application component that pre-subscribes to the target event. The component subscription array corresponding to the event identifier of the target event can be directly extracted from the application component subscription library, and the component subscription array includes the component identifier of the application component that pre-subscribes to the target event, that is, the first component identifier. The application component corresponding to the first component identifier is the target application component that pre-subscribes to the target event.

[0067] When there are multiple target application components that pre-subscribe to the target event, the component subscription array includes the execution priority of each application component that pre-subscribes to the target event, that is, the execution priority of each target application component. Therefore, the execution priority of each target application component can be determined based on the preset application component subscription library.

[0068] For example, following the example in step S102 above, when the target event is an order creation event, for the order processing component, payment component, and user management component that subscribe to the order creation event together, according to the actual order placement process, the execution priority of the order processing component should be higher than the execution priority of the payment component, and the execution priority of the payment component should be higher than the execution priority of the user management component. Therefore, in the preset application component subscription library, the execution priority of the order processing component is the highest, and the execution priority of the user management component is the lowest.

[0069] Step S208: The server determines the event distribution order of the event bus when distributing the target event based on the execution priority.

[0070] In an embodiment of the present application, the event distribution order refers to the distribution order when the target event is distributed through the event bus. The event distribution order is proportional to the execution priority of the target application component, that is, the higher the execution priority of the target application component, the higher the priority of the event distribution order corresponding to the target application component.

[0071] After determining the execution priority of each target application component, the event distribution order of distributing the target event to each target application component is determined according to the execution priority of each target application component, so as to achieve accurate event distribution of the target event based on the event distribution order.

[0072] Step S209: the server calls the event bus of the application program and distributes the target event to each target application component according to the event distribution order.

[0073] In the embodiment of the present application, after determining the event distribution order of each target application component, the event bus can be directly called to distribute the target event to each target application component in sequence according to the event distribution order. So that after the subsequent target application component receives the event notification of the target event from the event bus, it will respond to the target event in sequence and execute the corresponding event execution logic, without involving other application components in the application except the target application component, so that the application components in the application are completely decoupled.

[0074] For example, continuing with the example in step S207 above, since the order processing component has the highest execution priority and the user management component has the lowest execution priority, when the event bus of the application is called to distribute the order creation event, the order creation event will be distributed to the order processing component first. After the order processing component executes the corresponding processing logic, the order creation event will be distributed to the payment component and the user management component in sequence.

[0075] Step S210: the server determines a target component execution function that matches the event type of the target event from the component execution functions of the target application component.

[0076] In the embodiment of the present application, the component execution function of the target application component refers to the functions and operations that can be realized by the target application component in the application. Each target application component can have one component execution function, or it can have multiple component execution functions at the same time. Each system event has a certain event type. For example, when the target event is an order creation event, the event type of the order creation event is an event of adding an order type.

[0077] After determining the component execution function of the target application component, determine the target component execution function that matches the event type of the target event among all the component execution functions of the target application component. The target component execution function is the function to be implemented by the target application component for the target event. For example, the component execution function of the order processing component can be a delete order function and an add order function. The add order type corresponding to the order creation event does not match the delete order function of the order processing component, but matches the add order function of the order processing component. Then, the add order function of the order processing component is determined as the target component execution function that matches the event type of the order creation event.

[0078] Step S211: The server generates event execution logic for the target event based on the target component execution function.

[0079] In the embodiment of the present application, the event execution logic of the target event refers to the specific operation or underlying processing logic that needs to be executed when the target event is triggered. After determining the target component execution function that matches the event type of the target event, the event execution logic of the target component execution function corresponding to the target event is generated according to the target component execution function of the target application component. The event execution logic can be determined from the preset logic library corresponding to the target application component, and the preset logic library stores the execution logic of all component execution functions of the target application component. The event execution logic of the target event can be determined from the preset logic library based on the identifier of the target component execution function.

[0080] Step S212: the server calls the target application component, executes the event execution logic of the target event, and obtains the target event execution result.

[0081] In an embodiment of the present application, after the target event is distributed to the target application component through the event bus and the event execution logic of the target event is determined, the target application component can respond to the target event according to the event execution logic to obtain a response result, that is, the target application component obtains the target event execution result by executing the event execution logic of the target event.

[0082] In some embodiments, after determining the execution priority of each target application component, it is not necessary to determine the event distribution order of the event bus when distributing the target event, and distribute the target event to each target application component according to the event distribution order. Instead, after determining the execution priority of each target application component and distributing the event through the event bus, each target application component can be called in sequence according to the execution priority corresponding to each target application component, and the event execution logic of the target event can be executed to obtain the target event execution result. For example, the application components to be executed are three application components A, B, and C, and the execution priority of application component B is greater than the execution priority of application component A, and the execution priority of application component A is greater than the execution priority of application component C. Then, application component B is first called to execute the event execution logic of the target event, and then application component A is called to execute the event execution logic of the target event, and finally application component C is called to execute the event execution logic of the target event, and the target event execution results of the three application components are obtained in sequence.

[0083] Here, once a target event is triggered in the application, the completed event in the event bus will be replaced with the target event, and the target event will be distributed through the event bus, so that the target event is distributed to the target application component that has subscribed to the target event in advance, and the event execution logic of the target event is executed through the target application component. That is, when the target event is triggered, only the application component that has subscribed to the target event in advance is involved, and other application components in the application do not need to participate, so that the application components in the application are completely decoupled.

[0084] Step S213: the server sends the target event execution result to the terminal.

[0085] Step S214: the terminal outputs the target event execution result.

[0086] In the embodiment of the present application, once a target event is triggered in the application, the completed event in the event bus will be replaced with the target event, and the execution priority of each target application component that pre-subscribes to the target event will be determined, and the target event will be distributed through the event bus in an event distribution order that is proportional to the execution priority, so that the target event is preferentially distributed to the target application component that pre-subscribes to the target event with a high execution priority. And the event execution logic that the target application component needs to execute is determined by the event type of the target event, and the event execution logic of the target event is preferentially executed by the target application component. That is, in the case of the triggering of the target event, only the application component that pre-subscribes to the target event is involved, and the participation of other application components in the application is not required, so that the application components in the application are completely decoupled. And according to the execution priority of each target application component and the event type of the target event, the accurate execution of the event execution logic by the target application component can be achieved.

[0087] The following is an explanation of an exemplary application of an embodiment of the present application in a practical application scenario.

[0088] The embodiment of the present application provides an application component calling method, which uses the subscription distribution function of the event bus. After the application is loaded, the application component in the application automatically subscribes to the pre-subscribed system event, and through the replacement processing of the event execution logic in the event bus, the system event is published to the application component that pre-subscribes to the system event through the event bus, and the application component is used to execute the event execution logic of the system event, so as to realize non-intrusive component development of the application. The application in the embodiment of the present application can be any application, and the communication between the application components is called by routing to realize complete decoupling between the application components.

[0089] This method supports components to subscribe to system events without intrusive annotations and decouple component communication. The SDK design process of this method is as follows:

[0090] 1) Create an application event distribution and component decoupling SDK.

[0091] 2) Create an AppDelegate hook class in the SDK, use __attribute__ to declare a constructor in the class, and hook the setDelegate method of the UIApplication class in the function.

[0092] 3) In the AppDelegate hook class, use C functions to define a series of methods and implement them (that is, the above event execution logic. For example, the function bool didFinishLaunching(id self,SEL_cmd,UIApplication*application,NSDictionary*launchOptions) corresponds to the startup completion method in UIApplicationDelegate. The compiled code of the startup completion method is: (BOOL)application:(UIApplication*)applicationdidFinishLaunchingWithOptions:(NSDictionary*)launchOptions; the function voidregisterToken(id self,SEL_cmd,UIApplication*application,NSData*token) corresponds to the registration notification authentication (Token) method in UIApplicationDelegate. The compiled code of the authentication method is: (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken), the method parameters of a series of methods are the same as the corresponding method selectors (SEL) in the UIApplicationDelegate protocol, so as to provide the required IMP function for the implementation class of the UIApplicationDelegate protocol when performing AOP processing. The series of methods defined by the C function mainly provide IMP pointers for the class_addMethod function to add methods to the UIApplicationDelegate implementation class. The embodiment of the present application uses an event bus architecture to process system events and message transmission. The event bus can publish system events to the event bus through publishers, and then the event bus sends system events to corresponding subscribers according to the event type of the system event, and the IMP pointer mainly sends system events to the event bus so that the event bus processes the system events. At the same time, the respondsToSelector method is used to determine whether the implementation class of the UIApplicationDelegate protocol can respond to the current SEL. If it can respond, the NSInvocation method signature is used to call the original class method. The UIApplicationDelegate implementation class may have implemented this method in the original project, so it is necessary to call the method in the project again to avoid loss of business logic.

[0093] 4) Get the method parameters of the setDelegate method, get the AppDelegate runtime class, and use respondsToSelector to determine whether the AppDelegate runtime class implements all methods defined in the UIApplicationDelegate protocol.

[0094] 5) If it is determined that all methods defined in the UIApplicationDelegate protocol have been implemented, use class_addMethod to add implementations for the appDelegate runtime class and SEL. The parameters are the class to which the method is to be added, the SEL method selector, the implementation function corresponding to the method selector, the Types return value encoding type, and the IMP pointer corresponds to a series of methods defined by the above C function. Then use method exchange (method_exchangeImplementations) to replace the original method (that is, the completed event execution logic mentioned above) (by getting the instance method of the class (method_getInstanceMethod) to obtain the method structure of the current SEL in the AppDelegate hook class, which describes the method name SEL, return code type, method implementation IMP) and the newly added SEL to achieve the AOP effect. The SEL is newly added and its corresponding implementation is a series of methods defined by the above C function. In order to distinguish it from the SEL in the UIApplicationDelegate protocol, the SEL name will be prefixed with "mdp_"; if it is determined that all methods defined in the UIApplicationDelegate protocol are not implemented, use class_addMethod to add implementation for the class and this SEL, and the IMP pointer corresponds to a series of methods defined by the above C function.

[0095] 6) Use #define to define a macro that accepts two parameters, namely the class name and the priority. This part of the function is mainly to realize the annotation function of the event bus. In order to simplify the use of the registration after compilation, the macro can be defined as #define MDPAppModuleRegister(_class_,_priority_). The macro can define a group of code snippets as an identifier and expand them into corresponding codes during compilation or preprocessing. Here, the OC annotation capability is realized through the macro. After the macro is expanded, it is a structure modified by __attribute__((used))static. The structure name is MDPAppModule##className and it is placed in the specific section of __DATA,__MDPEventBus (that is, the above-mentioned preset application component subscription library). The structure stores the class name (that is, the above-mentioned component identification) and the priority (that is, the above-mentioned execution priority). The priority mainly refers to the priority of processing events. For example, multiple modules (that is, the above-mentioned application components to be executed) subscribe to the startup event (that is, the above-mentioned target event) at the same time. If the processing priority of these modules has a clear higher priority, such as initializing some network configurations, the module with a high priority will be executed first. After the macro code is compiled, the replaced content is to define a structure according to the class name, and the class name (className) is used as the first parameter and the priority (priority) is used as the second parameter, which is saved as a dictionary in the Mach-o specific __DATA segment (that is, the above-mentioned preset application component subscription library), providing annotation capabilities. Other components can be automatically registered in the __DATA segment of the event bus through this macro.

[0096] 7) Define a __attribute__((constructor)) compiler attribute method so that the function (__attribute__((constructor))void registerDyldCallback()) is automatically executed when the program starts according to the functions provided by the GCC and Clang compilers. This function reads the __DATA segment, parses the className and priority and saves them into an array for the subscriber (i.e., the above-mentioned application component to be executed) to call. The calling process is to traverse the subscriber array and execute the subscriber initialization method. Through this step, the subscriber subscribes to the system events that the module needs to process, and accepts the MDPEvent event callback. The logic processing is completed in the callback, realizing the communication from the publisher to the event bus and then to the subscriber, thus achieving decoupling.

[0097] 8) The event bus defines events that match the system life cycle, and inherits MDPEvent for publishers to call and distribute system events.

[0098] 9) Add routing capabilities to the SDK created above to provide support for decoupled communication between application components.

[0099] In addition, the embodiment of the present application may also include an application management platform, and the design process of the application management platform is as follows: 1) Create an application; 2) Configure the application warehouse address. If the project is not fully shell configured, that is, the project still has code, then configure the corresponding project warehouse address. If the project has been fully shell configured, multiple projects can share an empty template project to build the project; 3) Upload the application build certificate file: the p12 file and description file (Profiles) corresponding to the certificate; 4) Configure the application name and picture; 5) Select components from the component market according to the application function and generate an application component configuration table; 6) Generate service configuration according to the application function, for example, the interface service address, the contact system, the application identification (App ID) of the observable system, and other configurations.

[0100] The embodiment of the present application may also include cloud construction, and the design process of cloud construction is as follows: 1) Select the application to start building; 2) Fill in the application version number and build version number, build type; 3) Clone the warehouse address project; 4) Download the application build configuration file, use the script to modify the application identifier (identifier) ​​and configuration file according to the configuration certificate file, and download the p12 file at the same time and copy it to the system keychain; 5) Download the application configuration information, use the script to modify the application name, and complete the application icon configuration; 6) Pull the application component configuration table configuration file and execute the pod installation to pull the corresponding component code; 7) Download the service configuration file for the business code to read; 8) Use the execution build command (xcodebuild) to package and export the IPA installation package; 9) Publish the IPA installation package to cloud storage. Furthermore, the three parts of the component market, cloud construction and application management platform composed of the application component calling method can together constitute any APP project. The structural diagram of any APP project is as shown in the figure. Figure 4 shown.

[0101] When performing shell engineering transformation of multiple applications, the technical solution of this application is as follows: 1) According to the process, first complete the development of the middleware SDK supporting the shell engineering, which is responsible for the distribution of AppDelegate events and communication processing between components. 2) Business extraction components, such as splash screen components, message components, and login components. 3) The splash screen component macro definition annotation subscribes to the startup (didFinishLaunchingWithOptions) event. At this time, the message module subscribes to the privacy consent event and the remote notification (didRegisterForRemoteNotificationsWithDeviceToken) event using the device token. 4) Create an application in the application management and configure the application warehouse. 5) Select component dependencies according to the functions required by the application and generate a component configuration table. 6) Configure the application build certificate, name, icon, etc. 7) Generate service configurations such as server address, SDK App ID, etc. 8) Start building: fill in the version for building. 9) Pull the configuration in the application warehouse, component configuration table, and service configuration, and modify the application-related configuration through the script tool. 10) Use the execution build command (xcodebuild) to build and export the IPA installation package. 11) The application is started after installation. 12) If the system calls the startup event, the splash screen component will receive the subscribed startup event message and execute the splash screen logic processing. 13) The user clicks on the privacy authorization consent. 14) The message component receives the subscribed privacy consent event message and executes the logic of registering APNs and pulling the station. 15) After the message component registers the notification, it will receive the subscribed event message of registering remote notifications with device token (didRegisterForRemoteNotificationsWithDeviceToken), obtain the server address, and call the interface to report the token. 16) The user opens the message page to view it. Clicking on the message content can jump to the corresponding details through the route, or call the login component through the route to log in when logging in. 17) The above steps complete the extraction of the business components of the splash screen component, message component, and login component. If the business is componentized, there can be no code in the shell project of the application. After multiple applications complete the shell project, only one empty project is needed to complete the configuration and construction of all applications.

[0102] The technical solution of this application can meet the needs of 95% of applications. These applications do not need to build separate projects. They only need to complete the application function assembly through configuration, and the application can be produced through configuration and cloud construction.

[0103] The following further describes the exemplary structure of the application component calling device 455 provided in the embodiment of the present application implemented as a software module. In some embodiments, for example Figure 5As shown, the software modules stored in the application component calling device 455 in the memory may include: an event replacement module 4551, which is used to replace the completed event in the event bus of the application with the target event in response to a call request for the target event in the application; an event distribution module 4552, which is used to call the event bus of the application and distribute the target event to the target application component that has pre-subscribed to the target event; and an execution module 4553, which is used to call the target application component and execute the event execution logic of the target event.

[0104] In some embodiments, the event replacement module 4551 is also used to: determine a system event carrying a completed flag in the event bus of the application as a completed event; determine an event address of the completed event in the event bus; and based on the event address, replace the completed event with the target event.

[0105] In some embodiments, the event bus of the application includes a preset application component subscription library; the device 455 also includes a target application component determination module, and the target application component determination module is used to: obtain a component subscription array corresponding to the event identifier of the target event from the application component subscription library; obtain a first component identifier from the component subscription array; the first component identifier is the component identifier of the application component that has pre-subscribed to the target event; and determine the application component corresponding to the first component identifier as the target application component.

[0106] In some embodiments, there are multiple target application components, and the event distribution module 4552 is also used to: determine the execution priority of each target application component; based on the execution priority, determine the event distribution order of the event bus when distributing the target event; call the event bus of the application to distribute the target event to each target application component according to the event distribution order.

[0107] In some embodiments, the device 455 also includes a storage module, which is further used to: determine, for each system event in the application, a second component identifier and an execution priority of an application component that has pre-subscribed to the system event; build the application component subscription library based on the event identifier of the system event, the second component identifier and the execution priority of the application component that has pre-subscribed to the system event; and store the application component subscription library in the event bus.

[0108] In some embodiments, the execution module 4553 is also used to: determine the target component execution function that matches the event type of the target event from the component execution function of the target application component; generate the event execution logic of the target event based on the target component execution function; and call the target application component to execute the event execution logic of the target event.

[0109] It should be noted that the description of the device of the embodiment of the present application is similar to the description of the above method embodiment, and has similar beneficial effects as the method embodiment, so it is not repeated. For technical details not disclosed in the embodiment of the device, please refer to the description of the method embodiment of the present application for understanding.

[0110] Correspondingly, an embodiment of the present application provides an electronic device, Figure 6 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application is shown in FIG. Figure 6 As shown, the electronic device 1200 includes at least: a processor 1201 , a communication interface 1202 , and a storage medium 1203 configured to store executable instructions, wherein: the processor 1201 generally controls the overall operation of the electronic device 1200 .

[0111] The communication interface 1202 enables the electronic device to communicate with other terminals or servers through a network.

[0112] The storage medium 1203 is configured to store instructions and applications executable by the processor 1201, and can also cache data to be processed or processed by the processor 1201 and each module in the electronic device 1200, which can be implemented through flash memory (FLASH) or random access memory (Random Access Memory, RAM).

[0113] The present application embodiment provides a computer-readable storage medium in which computer-executable instructions are stored. When the computer-executable instructions are executed by a processor, the processor will execute the application component calling method provided by the present application embodiment, for example, Figure 2 The application component shown calls the method.

[0114] The embodiment of the present application provides a computer program product, which includes computer executable instructions, which are stored in a computer-readable storage medium. A processor of an electronic device reads the computer executable instructions from the computer-readable storage medium, and the processor executes the computer executable instructions, so that the electronic device executes the application component calling method described above in the embodiment of the present application.

[0115] In some embodiments, the computer-readable storage medium may be a memory such as RAM, ROM, flash memory, magnetic surface memory, optical disk, or CD-ROM; or may be various devices including one or any combination of the above memories.

[0116] In some embodiments, computer executable instructions may be in the form of a program, software, software module, script or code, written in any form of programming language (including compiled or interpreted languages, or declarative or procedural languages), and may be deployed in any form, including as a stand-alone program or as a module, component, subroutine or other unit suitable for use in a computing environment.

[0117] As an example, computer-executable instructions may, but need not, correspond to a file in a file system, may be stored as part of a file that stores other programs or data, such as in one or more scripts in a HyperText Markup Language (HTML) document, in a single file dedicated to the program in question, or in multiple coordinated files (e.g., files storing one or more modules, subroutines, or code portions).

[0118] As an example, computer executable instructions may be deployed to be executed on one electronic device, or on multiple electronic devices located at one site, or on multiple electronic devices distributed at multiple sites and interconnected by a communication network.

[0119] The above is only an embodiment of the present application and is not intended to limit the protection scope of the present application. Any modifications, equivalent substitutions and improvements made within the spirit and scope of the present application are included in the protection scope of the present application.

Claims

1. A method for calling an application component, characterized in that: The method comprises: In response to a call request for a target event in an application, replacing a completed event in an event bus of the application with the target event; Calling the event bus of the application program to distribute the target event to the target application component that has subscribed to the target event in advance; The target application component is called to execute the event execution logic of the target event.

2. The method according to claim 1, characterized in that The step of replacing the completed event in the event bus of the application with the target event comprises: Determine a system event carrying a completed flag in the event bus of the application as a completed event; Determine the event address of the completed event in the event bus; Based on the event address, the completed event is replaced with the target event.

3. The method according to claim 1, characterized in that The event bus of the application program includes a preset application component subscription library; the method further includes: Obtaining, from the application component subscription library, a component subscription array corresponding to the event identifier of the target event; Obtaining a first component identifier from the component subscription array; the first component identifier is a component identifier of an application component that pre-subscribes to the target event; The application component corresponding to the first component identifier is determined as the target application component.

4. The method according to claim 1, characterized in that: There are multiple target application components, and the event bus of calling the application program distributes the target event to the target application components that have subscribed to the target event in advance, including: Determining an execution priority of each of the target application components; Based on the execution priority, determining an event distribution order of the event bus when distributing the target event; The event bus of the application is called to distribute the target event to each of the target application components according to the event distribution order.

5. The method according to claim 3, characterized in that: The method further comprises: For each system event in the application, determining a second component identifier and an execution priority of an application component that pre-subscribes to the system event; Building the application component subscription library based on the event identifier of the system event, the second component identifier of the application component that pre-subscribes to the system event, and the execution priority; The application component subscription library is stored in the event bus.

6. The method according to claim 5, characterized in that The calling of the target application component to execute the event execution logic of the target event includes: Determining a target component execution function that matches the event type of the target event from the component execution functions of the target application component; Based on the target component execution function, generate event execution logic of the target event; The target application component is called to execute the event execution logic of the target event.

7. An application component calling device, characterized in that: The device comprises: An event replacement module, configured to replace a completed event in an event bus of the application with the target event in response to a call request for a target event in the application; An event distribution module, used for calling the event bus of the application program to distribute the target event to a target application component that has subscribed to the target event in advance; The execution module is used to call the target application component and execute the event execution logic of the target event.

8. An electronic device, characterized in that: include: A memory for storing computer executable instructions; The processor is used to implement the application component calling method described in any one of claims 1 to 6 when executing the computer executable instructions stored in the memory.

9. A computer-readable storage medium, characterized in that: Computer executable instructions are stored, and when the computer executable instructions are executed by a processor, the application component calling method according to any one of claims 1 to 6 is implemented.

10. A computer program product, characterized in that The computer program product includes computer executable instructions stored in a computer readable storage medium; Wherein, when the processor of the electronic device reads the computer executable instructions from the computer readable storage medium and executes the computer executable instructions, the application component calling method described in any one of claims 1 to 6 is implemented.