CN117435262A - Component dynamic loading method and device, electronic equipment and storage medium - Google Patents

Component dynamic loading method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN117435262A
CN117435262A CN202311218833.0A CN202311218833A CN117435262A CN 117435262 A CN117435262 A CN 117435262A CN 202311218833 A CN202311218833 A CN 202311218833A CN 117435262 A CN117435262 A CN 117435262A
Authority
CN
China
Prior art keywords
component
alternative
container
target
components
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202311218833.0A
Other languages
Chinese (zh)
Inventor
黄方明
王颖奇
冯斌
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shenzhen Fulin Technology Co Ltd
Original Assignee
Shenzhen Fulin Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shenzhen Fulin Technology Co Ltd filed Critical Shenzhen Fulin Technology Co Ltd
Priority to CN202311218833.0A priority Critical patent/CN117435262A/en
Publication of CN117435262A publication Critical patent/CN117435262A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/445Program loading or initiating
    • G06F9/44521Dynamic linking or loading; Link editing at or after load time, e.g. Java class loading
    • G06F9/44526Plug-ins; Add-ons
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/36Software reuse
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/38Creation or generation of source code for implementing user interfaces
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/445Program loading or initiating
    • G06F9/44505Configuring for program initiating, e.g. using registry, configuration files
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/451Execution arrangements for user interfaces

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Human Computer Interaction (AREA)
  • Stored Programmes (AREA)

Abstract

The application provides a dynamic loading method and device for components, electronic equipment and a storage medium, and belongs to the technical field of software development. The method comprises the following steps: acquiring a container component and an alternative component, wherein the container component is used for managing the loading and running of the alternative component, and one container component corresponds to a plurality of alternative components; acquiring a component registry of the container component, and storing the mapping relation between each alternative component and the related information thereof into the component registry; querying an alternative component corresponding to the user demand based on the component registry, and determining the alternative component corresponding to the user demand as a target component; and acquiring a resource file corresponding to the target component, and loading the target component according to the resource file. The method and the device can realize dynamic loading of the components and improve flexibility and expandability of front-end application.

Description

Component dynamic loading method and device, electronic equipment and storage medium
Technical Field
The present invention relates to the field of software development technologies, and in particular, to a method and apparatus for dynamically loading a component, an electronic device, and a storage medium.
Background
Traditional front-end applications are typically static, requiring loading all components and resources at once at application initialization. However, for large complex applications, or where it is necessary to dynamically load different components according to user behavior, this approach is computationally intensive and inflexible.
Disclosure of Invention
In order to solve the technical problems, the embodiments of the present application provide a method, an apparatus, an electronic device, and a storage medium for dynamically loading components.
In a first aspect, an embodiment of the present application provides a method for dynamically loading a component, where the method includes:
acquiring a container component and an alternative component, wherein the container component is used for managing the loading and running of the alternative component, and one container component corresponds to a plurality of alternative components;
acquiring a component registry of the container component, and storing the mapping relation between each alternative component and related information thereof into the component registry, wherein the related information at least comprises registered component names, component paths and component dependencies of each alternative component;
acquiring a user demand, inquiring an alternative component corresponding to the user demand based on the component registry, and determining the alternative component corresponding to the user demand as a target component, wherein the user demand at least comprises user input, page configuration and program logic;
and acquiring a resource file corresponding to the target component, and loading the target component according to the resource file.
In one embodiment, the access container assembly further comprises:
a plurality of interfaces of the container component are obtained, each of the interfaces for implementing at least one of registration component, loading component, unloading component, replacement component, component lifecycle management, and component communication.
In an embodiment, the obtaining the component registry of the container component, storing the mapping relation between each candidate component and the related information thereof in the component registry includes:
initializing the component registry;
mapping each alternative component with the related information one by one to obtain a mapping relation between each alternative component and the related information;
and storing the mapping relation into an initialized component registry.
In one embodiment, the method further comprises:
constructing a global state storage object based on the container component;
and storing the state data of each target component into the global state storage object.
In one embodiment, storing the state data of each of the target components into the global state storage object includes:
when the user needs to update, acquiring updated content;
unloading or replacing the target component based on the updated content;
updating state data of the target component when the target component is replaced;
and deleting the state data of the target component when the target component is unloaded.
In one embodiment, the method further comprises:
constructing a communication mechanism, wherein the communication mechanism is used for transmitting events and messages between the target components;
and the container component reads the user interaction behavior of the front end, and controls each target component to respond based on the communication mechanism according to the user interaction behavior.
In one embodiment, said controlling each of said target components to respond comprises:
acquiring a target component and an event corresponding to user interaction behavior;
and controlling the target component to respond to the event.
In a second aspect, an embodiment of the present application provides a device for dynamically loading a component, where the device includes:
the first acquisition module is used for acquiring a container assembly and an alternative assembly, wherein the container assembly is used for managing the loading and running of the alternative assembly, and one container assembly corresponds to a plurality of alternative assemblies;
the second acquisition module is used for acquiring a component registry of the container component and storing the mapping relation between each alternative component and related information thereof into the component registry, wherein the related information at least comprises registered component names, component paths and component dependencies of each alternative component;
the determining module is used for acquiring the user demand, inquiring an alternative component corresponding to the user demand based on the component registry, and determining the alternative component corresponding to the user demand as a target component, wherein the user demand at least comprises user input, page configuration and program logic;
and the loading module is used for acquiring the resource file corresponding to the target component and loading the target component according to the resource file.
In a third aspect, an embodiment of the present application provides an electronic device, including a memory and a processor, where the memory is configured to store a computer program, and the computer program executes the method for providing dynamic loading of components according to the first aspect when the processor is running.
In a fourth aspect, embodiments of the present application provide a computer readable storage medium storing a computer program which, when run on a processor, performs the component dynamic loading method provided in the first aspect.
The dynamic loading method of the components can realize dynamic loading of the components and improve flexibility and expandability of front-end application.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings that are needed in the embodiments will be briefly described below, it being understood that the following drawings only illustrate some embodiments of the present invention and therefore should not be considered as limiting the scope, and other related drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
FIG. 1 is a flow chart of a method for dynamically loading components provided in the present application;
FIG. 2 is a schematic structural diagram of a dynamic component loading device provided in the present application;
fig. 3 is a schematic structural diagram of an electronic device provided in the present application.
Detailed Description
For the purpose of making the objects, technical solutions and advantages of the embodiments of the present invention more apparent, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention, and it is apparent that the described embodiments are some embodiments of the present invention, but not all embodiments of the present invention. The components of the embodiments of the present invention generally described and illustrated in the figures herein may be arranged and designed in a wide variety of different configurations.
Thus, the following detailed description of the embodiments of the invention, as presented in the figures, is not intended to limit the scope of the invention, as claimed, but is merely representative of selected embodiments of the invention. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
It should be noted that: like reference numerals and letters denote like items in the following figures, and thus once an item is defined in one figure, no further definition or explanation thereof is necessary in the following figures.
In the description of the present invention, it should be noted that, if the terms "upper", "lower", "inner", "outer", and the like indicate an azimuth or a positional relationship based on the azimuth or the positional relationship shown in the drawings, or the azimuth or the positional relationship in which the inventive product is conventionally put in use, it is merely for convenience of describing the present invention and simplifying the description, and it is not indicated or implied that the apparatus or element referred to must have a specific azimuth, be configured and operated in a specific azimuth, and thus it should not be construed as limiting the present invention.
Furthermore, the terms "first," "second," and the like, if any, are used merely for distinguishing between descriptions and not for indicating or implying a relative importance.
It should be noted that the features of the embodiments of the present invention may be combined with each other without conflict.
Example 1
Traditional front-end applications are typically static, requiring that all components and resources be loaded at once at the time of application initialization. This approach presents inconveniences in some scenarios, especially for large complex applications or situations where it is necessary to dynamically load different components according to user behavior.
Based on the above, the embodiment of the application provides a component dynamic loading method. By introducing the container component into the front-end application, the capability of dynamically loading, unloading and replacing the component is realized, and the flexibility and expandability of the front-end application are improved.
Specifically, referring to fig. 1, the component dynamic loading method includes:
step S110, obtaining a container component and an alternative component, wherein the container component is used for managing the loading and running of the alternative component, and one container component corresponds to a plurality of alternative components;
in front-end web page development, a front-end framework may be used for complex front-end construction. For example, a compact framework is taken as an example. The act framework is a JavaScript library for constructing a user interface, adopts a componentized development mode, splits the user interface into independent components, and constructs a complex application interface through multiplexing and combination of the components.
The most basic component of an image user page is a component, which is an object that is graphically displayed on a screen and can interact with a user.
The container component, as a core component of the front-end application, is used for managing and carrying the loading and running of other alternative components. In the practice of reacti, one higher-order component is used as a component responsible for managing the lifecycle and rendering logic of the other components. The container component can pass data and methods to other components through tips. The container component can create a container for other multiple alternative components on the page, the container component being responsible for delivering data to the alternative components, handling user interactions, and delivering the state and events of the alternative components to the upper layer components.
In one embodiment, the access container assembly further comprises:
a plurality of interfaces of the container component are obtained, each of the interfaces for implementing at least one of registration component, loading component, unloading component, replacement component, component lifecycle management, and component communication.
The container component provides a series of interfaces to manage and carry the loading and operation of other components. These interfaces include the following functions: registration component, loading component, unloading component, replacement component, component lifecycle management, component communication.
Step S120, a component registry of the container component is obtained, and mapping relations between each candidate component and related information thereof are stored in the component registry, wherein the related information at least comprises registered component names, component paths and component dependencies of each candidate component;
inside the container component, a mechanism is provided for the developer to register components that need to be loaded and used. In particular, this may be achieved by maintaining a registry of components in the container. Upon registration, related information such as component names, component paths or modules, component dependencies, etc. of the alternative components may be included.
The component registry is a data structure storing component information for managing and looking up components. It can record all available components and provide each component with a unique identifier or name to dynamically load and render the components as needed in the application.
In an embodiment, the obtaining the component registry of the container component, storing the mapping relation between each candidate component and the related information thereof in the component registry includes:
initializing the component registry; mapping each alternative component with the related information one by one to obtain a mapping relation between each alternative component and the related information; and storing the mapping relation into an initialized component registry.
A component registry is created, using a hash table or mapping data structure, to store the mapping relationship of component names/paths to components. The registry may also include dependency information for components to be dynamically loaded when needed.
In one embodiment, the method further comprises: constructing a global state storage object based on the container component; and storing the state data of each target component into the global state storage object.
The global state storage object provides a centralized location for storing data shared between various components in the front end of a web page or application. By storing data in this object, the component can access, read, and modify the data.
The global state storage object can simplify data sharing and communication among components, and reduce the coupling degree among components. In addition, by centrally managing the state of the application, data changes can be more easily tracked and debugged, and data can be conveniently accessed and updated anywhere throughout the application.
The global state of an application is managed using a Context API such as a state management library of reduce (state management library for JavaScript applications) or act. By creating a global state storage object, the state data of each component is managed in the manner of component name/path. Vuex and MobX, etc. may also be included. The global state storage object provides a mechanism to manage and update global state data and provides corresponding APIs and tools to help developers better organize and manage the state of applications.
In one embodiment, storing the state data of each of the target components into the global state storage object includes: when the user needs to update, acquiring updated content; unloading or replacing the target component based on the updated content; updating state data of the target component when the target component is replaced; and deleting the state data of the target component when the target component is unloaded.
The container assembly allows unloading of components that are no longer needed at run-time. The developer may specify the components that need to be offloaded by invoking an interface provided by the container, or trigger the offloading of the components depending on specific conditions. Prior to unloading the components, the container may perform associated cleanup operations to ensure resource release and state reset. The container component supports replacing the loaded component with a new component at runtime. The developer may specify the components to be replaced and the components after replacement, and then trigger the replacement through the interface provided by the container. When a component is replaced, the container unloads the current component and loads and instantiates a new component to achieve the effect of dynamically updating the page content.
The container component enables dynamic page content updates through offloading and replacement of components. When the content displayed on the page needs to be updated, the container component can dynamically load a new component or unload a component which is not needed any more according to the instruction of a developer, so that the new component is displayed on the page, and the dynamic switching and updating of the page content are realized. Upon unloading and replacement of a component, the container may provide a way to manage the state of the component. For example, the container may temporarily store the status of the unloaded component in preparation for restoring the status of the component when it is later reloaded. This maintains the continuity and good user experience of the user when replacing components.
Step S130, obtaining a user demand, inquiring an alternative component corresponding to the user demand based on the component registry, and determining the alternative component corresponding to the user demand as a target component, wherein the user demand at least comprises user input, page configuration and program logic;
the component registry may record all available alternative components and provide each alternative component with a unique identifier or name to dynamically load and render the components as needed in the application. Upon registration, related information such as component names, component paths or modules, component dependencies, etc. of the alternative components may be included.
The application or browser may provide an interface allowing the user to enter the name or identifier of the component and then look up the corresponding alternative component from the component registry and make a call based on the name or identifier; the page configuration can also be used, the configuration file comprises the related information of the components to be called, and the application program or the browser reads the configuration file when being started, finds the corresponding alternative components from the component registry according to the information in the configuration file, and calls the components.
Regardless of the manner of the user's requirements, corresponding program logic needs to be implemented to parse the user's input and page configuration, and find the alternative components to be invoked from the component registry for processing according to the parsing result.
The container component internally defines a loading mechanism that enables dynamic loading of specific components as needed based on registered component information. This loading mechanism may be triggered according to configuration, user input, or program logic.
Step S140, obtaining a resource file corresponding to the target component, and loading the target component according to the resource file.
Component loading is done asynchronously to avoid blocking other parts of the application. Asynchronous loading of components may be accomplished using dynamic script loading, modular loaders (e.g., weback), etc. techniques.
When loading a component, it may be necessary to load resource files required by the component, such as style sheets, pictures, data, and the like. The container component can manage and load these resources, ensuring that they are available after the component loading is complete.
To further improve performance, a lazy loading mechanism may be employed. Lazy loading allows components to be loaded when actually needed, rather than loading all components at once at application initialization. This may be accomplished by operating, route navigation, or other event triggers based on the user. To better manage component loading and resource utilization, the container component may provide a caching mechanism. In this way, after the component is unloaded, it can also be cached for future reloading and use.
It should be noted that the component registry also needs to be updated synchronously when the target component is uninstalled or replaced.
In one embodiment, the method further comprises: constructing a communication mechanism, wherein the communication mechanism is used for transmitting events and messages between the target components; and the container component reads the user interaction behavior of the front end, and controls each target component to respond based on the communication mechanism according to the user interaction behavior.
Communication between components is achieved using an event subscription-publish mode or messaging mechanism. Existing event bus libraries, such as EventEmitter (for implementing event driven programming), or custom solutions may be used. A component may subscribe to events of interest and interact with other components through an event bus or messaging mechanism.
In one embodiment, said controlling each of said target components to respond comprises: acquiring a target component and an event corresponding to user interaction behavior; and controlling the target component to respond to the event. When the component monitors for an event, it responds to the event.
The container component provides a flexible way of setting properties that allows a user to set the properties of the component, such as display, hiding, size, and location. This may be achieved by the interface provided by the container or by the configuration of the properties of the component itself. The user can dynamically modify these properties as needed to adjust the way components are presented on the page.
The container component allows a user to trigger the interactive behavior of the component, which can be accomplished through a messaging mechanism between event systems or components provided by the container. The user may trigger a behavior or state change in response to the component by interaction with the component, such as clicking, dragging, entering, etc. The container component provides a global state management mechanism for managing data and states shared between components. In this way, a user can uniformly control and adjust the plurality of components by modifying the global state. The modification of the global state may trigger the corresponding component update and re-rendering.
According to the component dynamic loading method provided by the embodiment, all available components can be easily found and managed by utilizing the component registry, and the working efficiency of developers is improved. The system supports dynamic registration and updating of the components, so that the introduction, modification and expansion of the components are more flexible and convenient. Communication and collaboration among components is simplified and optimized through a communication mechanism and a registry, and implementation of system functions is improved. Component registries and container components provide a mechanism for centralized management, making maintenance and expansion of the system more convenient and controllable. In summary, the method and the device have the advantages of more convenient discovery and management of the components, dynamic management, good flexibility, promotion of component communication and collaboration, maintenance and expandability improvement and the like.
Example 2
In addition, the embodiment of the disclosure provides a dynamic component loading device.
Specifically, as shown in fig. 2, the component dynamic loading device 200 includes:
a first obtaining module 210, configured to obtain a container component and an alternative component, where the container component is configured to manage loading and running of the alternative component, and one container component corresponds to a plurality of the alternative components;
a second obtaining module 220, configured to obtain a component registry of the container component, and store a mapping relationship between each candidate component and related information thereof in the component registry, where the related information includes at least a registered component name, a component path, and a component dependency of each candidate component;
a determining module 230, configured to obtain a user requirement, query an alternative component corresponding to the user requirement based on the component registry, and determine the alternative component corresponding to the user requirement as a target component, where the user requirement at least includes user input, page configuration, and program logic;
and the loading module 240 is configured to obtain a resource file corresponding to the target component, and load the target component according to the resource file.
In an embodiment, the first obtaining module 210 is further configured to:
a plurality of interfaces of the container component are obtained, each of the interfaces for implementing at least one of registration component, loading component, unloading component, replacement component, component lifecycle management, and component communication.
In an embodiment, the second obtaining module 220 is further configured to:
initializing the component registry;
mapping each alternative component with the related information one by one to obtain a mapping relation between each alternative component and the related information;
and storing the mapping relation into an initialized component registry.
In one embodiment, the component dynamic loading device 200 further includes:
a building module for building a global state storage object based on the container component;
and storing the state data of each target component into the global state storage object.
In an embodiment, the building block is further configured to:
when the user needs to update, acquiring updated content;
unloading or replacing the target component based on the updated content;
updating state data of the target component when the target component is replaced;
and deleting the state data of the target component when the target component is unloaded.
In one embodiment, the component dynamic loading device 200 further includes:
the communication module is used for constructing a communication mechanism, and the communication mechanism is used for transmitting events and messages between the target components;
and the container component reads the user interaction behavior of the front end, and controls each target component to respond based on the communication mechanism according to the user interaction behavior.
In an embodiment, the communication module is further configured to:
acquiring a target component and an event corresponding to user interaction behavior;
and controlling the target component to respond to the event.
The component dynamic loading device 200 provided in this embodiment can implement the component dynamic loading method provided in embodiment 1, and in order to avoid repetition, a detailed description is omitted here.
The dynamic component loading device provided by the embodiment can easily discover and manage all available components by utilizing the component registry, and improves the working efficiency of developers. The system supports dynamic registration and updating of the components, so that the introduction, modification and expansion of the components are more flexible and convenient. Communication and collaboration among components is simplified and optimized through a communication mechanism and a registry, and implementation of system functions is improved. Component registries and container components provide a mechanism for centralized management, making maintenance and expansion of the system more convenient and controllable. In summary, the method and the device have the advantages of more convenient discovery and management of the components, dynamic management, good flexibility, promotion of component communication and collaboration, maintenance and expandability improvement and the like.
Example 3
Furthermore, an embodiment of the present disclosure provides an electronic device, including a memory and a processor, where the memory stores a computer program that, when run on the processor, performs the component dynamic loading method provided in embodiment 1.
Specifically, referring to fig. 3, the electronic device 300 includes: a transceiver 301, a bus interface and a processor 302, the processor 302 being configured to:
acquiring a container component and an alternative component, wherein the container component is used for managing the loading and running of the alternative component, and one container component corresponds to a plurality of alternative components;
acquiring a component registry of the container component, and storing the mapping relation between each alternative component and related information thereof into the component registry, wherein the related information at least comprises registered component names, component paths and component dependencies of each alternative component;
acquiring a user demand, inquiring an alternative component corresponding to the user demand based on the component registry, and determining the alternative component corresponding to the user demand as a target component, wherein the user demand at least comprises user input, page configuration and program logic;
and acquiring a resource file corresponding to the target component, and loading the target component according to the resource file.
In one embodiment, the processor 302 is further configured to:
a plurality of interfaces of the container component are obtained, each of the interfaces for implementing at least one of registration component, loading component, unloading component, replacement component, component lifecycle management, and component communication.
In one embodiment, the processor 302 is further configured to:
initializing the component registry;
mapping each alternative component with the related information one by one to obtain a mapping relation between each alternative component and the related information;
and storing the mapping relation into an initialized component registry.
In one embodiment, the processor 302 is further configured to:
constructing a global state storage object based on the container component;
and storing the state data of each target component into the global state storage object.
In one embodiment, the processor 302 is further configured to: when the user needs to update, acquiring updated content;
unloading or replacing the target component based on the updated content;
updating state data of the target component when the target component is replaced;
and deleting the state data of the target component when the target component is unloaded.
In one embodiment, the processor 302 is further configured to:
constructing a communication mechanism, wherein the communication mechanism is used for transmitting events and messages between the target components;
and the container component reads the user interaction behavior of the front end, and controls each target component to respond based on the communication mechanism according to the user interaction behavior.
In one embodiment, the processor 302 is further configured to:
acquiring a target component and an event corresponding to user interaction behavior;
and controlling the target component to respond to the event.
In an embodiment of the present invention, the electronic device 300 further includes: a memory 303. In fig. 3, a bus architecture may comprise any number of interconnected buses and bridges, with one or more processors, represented in particular by processor 302, and various circuits of memory, represented in memory 303, linked together. The bus architecture may also link together various other circuits such as peripheral devices, voltage regulators, power management circuits, etc., which are well known in the art and, therefore, will not be described further herein. The bus interface provides an interface. The transceiver 301 may be a number of elements, i.e. comprising a transmitter and a receiver, providing a means for communicating with various other apparatus over a transmission medium. The processor 302 is responsible for managing the bus architecture and general processing, and the memory 303 may store data used by the processor 302 in performing operations.
The electronic device provided by the embodiment of the present invention may implement the method for dynamically loading components provided by embodiment 1, and in order to avoid repetition, details are not repeated here.
The electronic device provided by the embodiment can easily discover and manage all available components by utilizing the component registry, and improves the working efficiency of developers. The system supports dynamic registration and updating of the components, so that the introduction, modification and expansion of the components are more flexible and convenient. Communication and collaboration among components is simplified and optimized through a communication mechanism and a registry, and implementation of system functions is improved. Component registries and container components provide a mechanism for centralized management, making maintenance and expansion of the system more convenient and controllable. In summary, the method and the device have the advantages of more convenient discovery and management of the components, dynamic management, good flexibility, promotion of component communication and collaboration, maintenance and expandability improvement and the like.
Example 4
The present application also provides a computer-readable storage medium having stored thereon a computer program which, when executed by a processor, implements the component dynamic loading method provided in embodiment 1.
In the present embodiment, the computer readable storage medium may be a volatile storage medium or a nonvolatile storage medium, such as Read-Only Memory (ROM), random access Memory (Random Access Memory RAM), magnetic disk or optical disk, or the like.
The computer readable storage medium provided in this embodiment may implement the method for dynamically loading components provided in embodiment 1, and in order to avoid repetition, a detailed description is omitted here.
It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or terminal that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or terminal. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article or terminal comprising the element.
From the above description of the embodiments, it will be clear to those skilled in the art that the above-described embodiment method may be implemented by means of software plus a necessary general hardware platform, but of course may also be implemented by means of hardware, but in many cases the former is a preferred embodiment. Based on such understanding, the technical solution of the present application may be embodied essentially or in a part contributing to the prior art in the form of a software product stored in a storage medium (such as ROM/RAM, magnetic disk, optical disk), including several instructions for causing a terminal (which may be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.) to perform the method described in the embodiments of the present application.
The embodiments of the present application have been described above with reference to the accompanying drawings, but the present application is not limited to the above-described embodiments, which are merely illustrative and not restrictive, and many forms may be made by those of ordinary skill in the art without departing from the spirit of the present application and the scope of the claims, which are also within the protection of the present application.

Claims (10)

1. A method for dynamically loading components, the method comprising:
acquiring a container component and an alternative component, wherein the container component is used for managing the loading and running of the alternative component, and one container component corresponds to a plurality of alternative components;
acquiring a component registry of the container component, and storing the mapping relation between each alternative component and related information thereof into the component registry, wherein the related information at least comprises registered component names, component paths and component dependencies of each alternative component;
acquiring a user demand, inquiring an alternative component corresponding to the user demand based on the component registry, and determining the alternative component corresponding to the user demand as a target component, wherein the user demand at least comprises user input, page configuration and program logic;
and acquiring a resource file corresponding to the target component, and loading the target component according to the resource file.
2. The component dynamic loading method of claim 1, wherein the acquisition container component further comprises:
a plurality of interfaces of the container component are obtained, each of the interfaces for implementing at least one of registration component, loading component, unloading component, replacement component, component lifecycle management, and component communication.
3. The method for dynamically loading components according to claim 1, wherein the obtaining the component registry of the container component, and storing the mapping relation between each candidate component and the related information thereof in the component registry, comprises:
initializing the component registry;
mapping each alternative component with the related information one by one to obtain a mapping relation between each alternative component and the related information;
and storing the mapping relation into an initialized component registry.
4. The component dynamic loading method of claim 1, wherein the method further comprises:
constructing a global state storage object based on the container component;
and storing the state data of each target component into the global state storage object.
5. The method of dynamic loading of components of claim 4, wherein storing state data of each of the target components into the global state storage object comprises:
when the user needs to update, acquiring updated content;
unloading or replacing the target component based on the updated content;
updating state data of the target component when the target component is replaced;
and deleting the state data of the target component when the target component is unloaded.
6. The component dynamic loading method of claim 1, wherein the method further comprises:
constructing a communication mechanism, wherein the communication mechanism is used for transmitting events and messages between the target components;
and the container component reads the user interaction behavior of the front end, and controls each target component to respond based on the communication mechanism according to the user interaction behavior.
7. The component dynamic loading method of claim 6, wherein said controlling each of said target components to respond comprises:
acquiring a target component and an event corresponding to user interaction behavior;
and controlling the target component to respond to the event.
8. A component dynamic loading apparatus, the apparatus comprising:
the first acquisition module is used for acquiring a container assembly and an alternative assembly, wherein the container assembly is used for managing the loading and running of the alternative assembly, and one container assembly corresponds to a plurality of alternative assemblies;
the second acquisition module is used for acquiring a component registry of the container component and storing the mapping relation between each alternative component and related information thereof into the component registry, wherein the related information at least comprises registered component names, component paths and component dependencies of each alternative component;
the determining module is used for acquiring the user demand, inquiring an alternative component corresponding to the user demand based on the component registry, and determining the alternative component corresponding to the user demand as a target component, wherein the user demand at least comprises user input, page configuration and program logic;
and the loading module is used for acquiring the resource file corresponding to the target component and loading the target component according to the resource file.
9. An electronic device comprising a memory and a processor, the memory storing a computer program that, when executed by the processor, performs the component dynamic loading method of any one of claims 1 to 7.
10. A computer readable storage medium, characterized in that it stores a computer program which, when run on a processor, performs the component dynamic loading method according to any one of claims 1 to 7.
CN202311218833.0A 2023-09-20 2023-09-20 Component dynamic loading method and device, electronic equipment and storage medium Pending CN117435262A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311218833.0A CN117435262A (en) 2023-09-20 2023-09-20 Component dynamic loading method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311218833.0A CN117435262A (en) 2023-09-20 2023-09-20 Component dynamic loading method and device, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN117435262A true CN117435262A (en) 2024-01-23

Family

ID=89554380

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311218833.0A Pending CN117435262A (en) 2023-09-20 2023-09-20 Component dynamic loading method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN117435262A (en)

Similar Documents

Publication Publication Date Title
US11481247B2 (en) Computer-implemented systems and methods for service provisioning
CN101960449B (en) The web feed based on XML for the web access to remote resource
US6385664B1 (en) System and method for on demand registration of tasks
US8332459B2 (en) Federation of composite applications
CN106569783B (en) Method and device for executing task script
CN111475227B (en) Business plug-in loading implementation method and device and terminal equipment
CN109445841B (en) Interface document management method, device, server and storage medium
US20080072240A1 (en) Change notification agent
US11522967B2 (en) System metamodel for an event-driven cluster of microservices with micro frontends
CN113448650A (en) Live broadcast function plug-in loading method, device, equipment and storage medium
CN115390897B (en) Micro front end management method, micro front end management device, electronic equipment and storage medium
CN115934076B (en) Cross-platform client micro-service providing device and method and electronic equipment
CN117435262A (en) Component dynamic loading method and device, electronic equipment and storage medium
CN113127430A (en) Mirror image information processing method and device, computer readable medium and electronic equipment
US6636964B1 (en) Method and apparatus for loading an object-oriented operating system by providing an initial execution environment and migrating to a core execution environment thereafter
CN114510334A (en) Class instance calling method and device, electronic equipment and automatic driving vehicle
CN113961298A (en) Page switching method, device, equipment and medium
CN111857765B (en) Plug-in system for drug design system, and generation method and updating method thereof
CN113805858B (en) Method and device for continuously deploying software developed by scripting language
US20060161618A1 (en) Abstract mechanism for constructing commands for the command pattern
US20040199551A1 (en) Evolving entries within persistent stores in a scalable infrastructure environment
CN116627535A (en) Task execution method based on rule engine, computer equipment and storage medium
CN118259933A (en) Micro-service isolation deployment method and device, computer equipment and storage medium
CN116028072A (en) Application program hot update method and device, storage medium and electronic equipment
WO2024102326A1 (en) A non-intrusive build time injection tool for accelerating launching of cloud applications

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination