Method and device for synchronizing data between components

By registering the synchronization method in the data controller, the direct interaction between the components and the data controller is realized, which solves the problem of complicated data interaction between components in the micro front-end project, improves the synchronization efficiency and flexibility, and simplifies component maintenance.

CN114579322BActive Publication Date: 2024-10-25阿里巴巴(中国)网络技术有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210139165.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-02-15
Publication Date
2024-10-25
Estimated Expiration
2042-02-15

AI Technical Summary

Technical Problem

The data interaction method between components in micro front-end projects is cumbersome, complex and inefficient, resulting in long and complex data transmission paths, which increases the coupling and pressure between components.

Method used

By registering the synchronization method in the data controller, the direct interaction between the component and the data controller is realized. Multiple synchronization methods are used for components to choose from, which directly decouples the data transfer between components and reduces the length and complexity of the transfer path.

Benefits of technology

It improves the efficiency of data synchronization between components, increases the flexibility and adaptability of components in obtaining data, simplifies component maintenance and reuse, and solves the problem of components transmitting useless data.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114579322B_ABST
    Figure CN114579322B_ABST
Patent Text Reader

Abstract

The embodiment of the present application provides a method and device for synchronizing data between components, including: in response to a registration request of a component, obtaining a synchronization method corresponding to the component from multiple synchronization methods; obtaining change information sent by the first component in the component after the logic is triggered; changing the component parameter information according to the change information; and sending the changed component parameter information to the second component for rendering and display according to the synchronization method corresponding to the second component. The present application directly decouples each component and establishes direct interaction between the component and the data controller, so that the component can synchronize the component parameter information between components through the synchronization method registered in the data controller, solving the problem of cumbersome and complex data synchronization methods generated by the transmission path of the tree structure and the external framework synchronization information in the related technology. The embodiment of the present application improves the synchronization efficiency on the basis of reducing the length and complexity of the transmission path.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a method and device for synchronizing data between components, an electronic device, and a machine-readable medium. Background Art

[0002] In order to achieve rich functions, micro-frontend projects often integrate multiple components that provide various services into the project.

[0003] At present, the components of the micro-frontend project can be nested in each other to form a tree structure. During the operation of the micro-frontend project, data interaction is required between the components, which can be achieved through the external framework of the project. The external framework can be used as the parent component of each component to implement data callback and transmission. For example, component b is nested in component a, and component d is nested in component c. If component b needs to send data to component d, component b can pass the data to the external framework through component a in the form of data callback, and the external framework then passes the data to component d through component c in the form of data transmission.

[0004] However, in the current solution, for micro-frontend projects with nested component structures, data needs to be transmitted by a unified external framework according to the nested path during data interaction. The external framework needs to implement data writing and reading methods for each component on the transmission path, resulting in cumbersome, complex and inefficient data interaction. Summary of the invention

[0005] The embodiment of the present application provides a method for synchronizing data between components to solve the problem that the data interaction mode in the related art is cumbersome, complex and inefficient.

[0006] Correspondingly, the embodiment of the present application also provides a device for synchronizing data between components, an electronic device, and a storage medium to ensure the implementation and application of the above method.

[0007] In order to solve the above problems, an embodiment of the present application discloses a method for synchronizing data between components, the method comprising:

[0008] In response to a registration request of a component, acquiring a synchronization mode corresponding to the component from a plurality of synchronization modes;

[0009] Obtaining change information sent by a first component in the components after logic triggering;

[0010] According to the change information, the component parameter information is changed;

[0011] In accordance with a synchronization method corresponding to the second component, the changed component parameter information is sent to the second component for rendering and display.

[0012] The present application embodiment discloses a device for synchronizing data between components, the device comprising:

[0013] A response module, configured to respond to a registration request of a component and obtain a synchronization mode corresponding to the component from a plurality of synchronization modes;

[0014] An acquisition module, used for acquiring change information sent by a first component in the components after logic triggering;

[0015] A change module, used to change component parameter information according to the change information;

[0016] The sending module is used to send the changed component parameter information to the second component for rendering and display in a synchronization manner corresponding to the second component.

[0017] An embodiment of the present application further discloses an electronic device, including: a processor; and a memory, on which executable code is stored. When the executable code is executed, the processor executes one or more methods described in the embodiments of the present application.

[0018] The embodiments of the present application also disclose one or more machine-readable media on which executable codes are stored. When the executable codes are executed, the processor executes one or more methods described in the embodiments of the present application.

[0019] Compared with the related art, the embodiments of the present application have the following advantages:

[0020] In the embodiment of the present application, in the scenario of component parameter information synchronization, each component can be directly decoupled, and a direct interaction between the component and the data controller can be established, so that the component can realize the synchronization of component parameter information between components in the form of one-way interaction with the data controller through the synchronization method registered in the data controller, which solves the problem of cumbersome and complicated data synchronization methods generated by the tree-structured transmission path and external framework synchronization information in the related technology. The embodiment of the present application improves the synchronization efficiency on the basis of reducing the length and complexity of the transmission path. In addition, the embodiment of the present application increases the flexibility of the way in which the component obtains component parameter information by implementing multiple synchronization methods in the data controller for the components to choose, and the universal synchronization method implemented in the data controller allows various types of components to be called and used, which improves the adaptability of the synchronization scheme. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] Figure 1 is a structural block diagram of a component of an embodiment of the present application;

[0022] Figure 2 is a structural block diagram of a data controller according to an embodiment of the present application;

[0023] Figure 3 It is an architectural diagram of a method for synchronizing data between components in an embodiment of the present application;

[0024] Figure 4 It is an architectural diagram of another method for synchronizing data between components according to an embodiment of the present application;

[0025] Figure 5 It is an architectural diagram of another method for synchronizing data between components according to an embodiment of the present application;

[0026] Figure 6 This is an interface diagram of a video editing scene in an embodiment of the present application;

[0027] Figure 7 This is an interface diagram of a search engine scenario in an embodiment of the present application;

[0028] Figure 8 This is an interface diagram of logistics information sorting in an embodiment of the present application;

[0029] Fig. 9 This is a flowchart of a method for synchronizing data between components according to an embodiment of the present application;

[0030] Fig.10 is a flowchart of another method for synchronizing data between components according to an embodiment of the present application;

[0031] Fig.11 is a flowchart of another method for synchronizing data between components according to an embodiment of the present application;

[0032] Fig.12 It is a structural block diagram of a device for synchronizing data between components according to an embodiment of the present application;

[0033] Fig.13 It is a schematic diagram of the structure of a device provided in one embodiment of the present application. DETAILED DESCRIPTION

[0034] In order to make the above-mentioned objects, features and advantages of the present application more obvious and easy to understand, the present application is further described in detail below in conjunction with the accompanying drawings and specific implementation methods.

[0035] In order to enable those skilled in the art to better understand the present application, the concepts involved in the present application are explained below:

[0036] Component: It is a simple encapsulation of data and methods. A component can have its own properties and methods. Properties are simple accessors to component data, and methods are some simple and visible functions of components. Components can be used as interface elements, and through the combination of components, an interface that can realize complex functions can be constructed.

[0037] Component parameter information: refers to the state and data in the component. The component is rendered and displayed based on the state, data, and logic defined in the logic layer. Data can affect the state, and logic can affect data and state.

[0038] Micro front-end project: a technology that converts a single application into multiple services or applications that can be run, developed, deployed, and maintained independently. A micro front-end project is equivalent to a collection of multiple components, which are nested in a tree structure.

[0039] React: A JavaScript library for building user interfaces by combining selected components.

[0040] The embodiments of the present application can be applied to scenarios such as micro-frontends where multiple components are aggregated for use. In such scenarios, multiple components collaborate with each other to achieve complex functions, which results in the following requirements: 1. Component parameter information needs to be interacted between components, such as component 1 obtains new component parameter information when the logic is triggered, and the operation of another component 2 requires obtaining the new component parameter information, that is, component 1 and component 2 need to synchronize component parameter information. 2. When developing the front end, in order to improve the stability and reusability of the project, some common components are often extracted for direct use by other projects, thereby reducing the amount of repeated development and improving development efficiency. This requires decoupling between components to achieve loose coupling, thereby achieving better scalability and maintainability.

[0041] The method for synchronizing data between components provided in the embodiment of the present application can be applied to a data controller, which provides a data controller to directly connect to each component. After the component is registered in the data controller, the component parameter information can be changed based on the data controller, and the component parameter information can be synchronized to other components.

[0042] Specifically, refer to Figure 1 , which shows a structural block diagram of a component provided in an embodiment of the present application, Figure 1 In the component shown, there are data (Data), state (State), logic (runtime) layer, rendering (render) layer, service interface and input parameters (props), among which data is information used for internal logical operations of the component, state is information used to change the rendering of the component itself, the logic layer defines the processing rules of data and state, the logic layer can affect the state and data, the rendering layer is used to render the component style and component function according to the state, the service interface provides access to external services, and the input parameters are used to realize the import of external data and state.

[0043] Further, see Figure 2 , which shows a structural block diagram of a data controller provided by an embodiment of the present application, for Figure 2 The data controller shown has a component parameter storage area for data storage, and implements a modification state interface (Setstate), a use state interface (Usestate), a data acquisition interface (Getdata), a modification data interface (Setdata), and an event emitter (event emitter) in the data controller. Among them, the modification state interface (Setstate) can interact with the component and the use state interface (Usestate), and the use state interface (Usestate) can interact with the component parameter storage area and the state (state) in the form of variables; the modification data interface (Setdata) can interact with the component and the component parameter storage area, and the data acquisition interface (Getdata) can interact with the component and the component parameter storage area; and the event emitter (event emitter) can interact with the component and the component parameter storage area, and the event emitter (event emitter) has two modes: enable (On) and disable (Off).

[0044] Reference Figure 3 , which shows an architecture diagram of data synchronization between components provided by an embodiment of the present application, based on Figure 3 The architecture shown, the data controller of the embodiment of the present application provides three data or state synchronization methods, method one is based on the modification state interface (Setstate), the use state interface (Usestate) and the state (state) in the form of variables to provide synchronization of states between components; method two is based on the data acquisition interface (Getdata) and the modification data interface (Setdata) to provide synchronization of data between components; method three is based on the modification data interface (Setdata) and the event dispatcher (eventEmitter) to provide synchronization of data between components. If the component needs to synchronize component parameter information through the data controller, it is first necessary to register the synchronization method corresponding to the target component parameter information in the data controller for the target component parameter information to be obtained. The specific target component parameter information to be selected and the synchronization method to be registered can be determined according to the rules defined for the component parameter information in the logical layer of the component.

[0045] For method 1, refer to Figure 3For S1, component 1 generates state change information after the logic is triggered. The data controller obtains the state change information by modifying the state interface (Setstate), and then executes S2, obtains the state change information by using the state interface (Usestate), and executes S3, uses the state change information to set the state (state) in the form of a variable after the change. Then, S4 and S5 are executed, and the state (state) in the form of a variable after the assignment is actively sent to component 1 and component 2, so that component 1 and component 2 can passively receive the state (state) after the assignment. Finally, S6 can be executed, and the state (state) in the form of a variable after the assignment is stored in the component parameter storage area using the state interface (Usestate) to ensure the accuracy of the state value read next time.

[0046] Method 1 allows component 1 to receive the changed state value set by modifying the state interface (Setstate) and perform subsequent rendering, and component 2 can receive the changed state value according to the logic trigger operation of component 1, so that component 2 can synchronously obtain the changed state while component 1 changes its state. It should be noted that if component 1 does not need to obtain the changed state, component 1 may not register the state based on the synchronization method of method 1, so that the data controller does not execute S4. If component 1 or component 2 needs to obtain the state through other synchronization methods, it can register other synchronization methods of the state to synchronize the state through other methods.

[0047] For method 2, refer to Figure 4 , which shows another architecture diagram of data synchronization between components provided by an embodiment of the present application. For M1, component 1 generates data change information after the logic is triggered. The data controller can obtain the data change information by modifying the data interface (Setdata), and use the data change information to change the value of the corresponding data in the component parameter storage area. After that, it can respond to the call operation of component 2 and component 1 to the data acquisition interface (Getdata), execute M2, and extract the changed data from the component parameter storage area by the data acquisition interface (Getdata), execute M3 and M4, and send the changed data to component 1 and component 2, so that component 1 and component 2 can actively receive the changed data. Mode 2 enables component 1 and component 2 to actively obtain the changed data and perform subsequent rendering, so that component 2 can synchronously obtain the changed data while component 1 changes the data. It should be noted that if component 1 does not need to obtain the changed data, component 1 may not register the synchronization method based on mode 2 for the data, so that the data controller does not execute M4. If component 1 or component 2 needs to obtain data through other synchronization methods, it can register other synchronization methods of data to synchronize data through other methods.

[0048] It should be noted that component 1 can also set the value of the state (state) in the form of a variable by using the state interface (Usestate) according to method 1, in the order of M5, M6, and M7, and then execute M8, and store the assigned state (state) in the form of a variable into the component parameter storage area by using the state interface (Usestate). At this time, the value of the state (state) becomes a data format in the component parameter storage area. If component 2 needs to obtain the value of the state (state), it can extract the state value in the data format from the component parameter storage area by calling the data acquisition interface (Getdata).

[0049] For method 3, refer to Figure 5 , which shows another architecture diagram of data synchronization between components provided by an embodiment of the present application. For N1, component 1 generates data change information after the logic is triggered. The data controller can obtain the data change information by modifying the data interface (Setdata), and use the data change information to change the value of the corresponding data in the component parameter storage area. Then N2 can be executed, and the event dispatcher extracts the changed data from the component parameter storage area, and executes N3 and N4 when it is determined that component 1 and component 2 have selected enable (On) for the changed data, and sends the changed data to component 1 and component 2 by broadcasting, so that component 1 and component 2 can passively receive the changed data. Method 2 enables component 1 and component 2 to passively obtain the changed data and perform subsequent rendering, so that component 1 can change the data while component 2 can synchronously obtain the changed data. It should be noted that if component 1 does not need to obtain the changed data, component 1 can also not register the data based on the synchronization method of method 3, or switch the data to off (Off) in the event dispatcher, so that the data controller does not execute N4. If component 1 or component 2 needs to obtain data through other synchronization methods, it can register other data synchronization methods to synchronize data through other methods.

[0050] It should be noted that component 1 can also set the value of the state in the form of a variable by using the state interface (Usestate) according to method 1, in the order of N5, N6, and N7, and then execute N8, and store the assigned state in the form of a variable in the component parameter storage area by using the state interface (Usestate). At this time, the value of the state becomes a data format in the component parameter storage area. If component 2 needs to obtain the value of the state, it can set enable (On) for the value in the event dispatcher. The state value stored in the data format in the component parameter storage area will notify the event dispatcher. When the event dispatcher determines that component 2 has selected enable (On) for the changed state value, it will send the state value in the data format to component 2 by broadcasting.

[0051] In the embodiment of the present application, the synchronization of component parameter information between components is achieved for the above three methods, and the above-mentioned requirement 1 is achieved. In the scheme of using an external framework to synchronize data proposed in the embodiment of the present application, data needs to be transmitted by a unified external framework according to the nested path during data interaction. For example, when component b is nested in component a, and component d is nested in component c, if component b needs to send data to component d, component b can pass the data to the external framework through component a in the form of data callback, and the external framework then passes the data to component d through component c in the form of data transmission. In this case, the strong coupling between the components is difficult to separate, the path of data propagation to be synchronized is long and complex, and the transmitted data is only useful for components b and d, and only serves to forward data for components a and c. These data are useless data for components a and c. In this case, the pressure on components a and c is increased, causing adverse effects.

[0052] In the embodiment of the present application, in the scenario of component parameter information synchronization, each component can be directly decoupled, and an association between the component and the data controller can be established, so that the component can synchronize the component parameter information between components through one-way interaction with the data controller, so that the data obtained by each component is useful data, which solves the problem of useless data transmission by the component, thereby reducing the length and complexity of the transmission path. The embodiment of the present application also provides a variety of data synchronization methods for the components to select according to their actual needs, thereby improving the robustness of the synchronization scheme. In addition, after the components are decoupled in the embodiment of the present application, it provides convenience for the maintenance and reuse of the components, thereby meeting the above-mentioned requirement 2.

[0053] Several specific scenarios that can be implemented for micro front-end projects are as follows:

[0054] In a video editing scenario, refer to Figure 6, which shows an interface diagram of a video editing scene provided by an embodiment of the present application. The interface for implementing video editing may include a property editing component, a preview component, and a progress component. The data that these three components need to use synchronously include bit rate, frame rate, and play time, wherein the play time can be used as both component data and component status. The property editing component can receive user input to change the bit rate and frame rate of the video; the progress component can receive user touch input to change the play time of the video, and the preview component is used to play the video screen according to the bit rate, frame rate, volume, and play time. The logic layer of the preview component has a rendering rule, that is, the artistic text is only displayed within a time range of 1 minute to 2 minutes. Based on this rule, the preview component needs to use the play time of the progress component synchronously. In addition, the preview component also needs to use the bit rate and frame rate of the property editing component synchronously to complete the adjustment of the played screen.

[0055] Assuming that the preview component is registered in the data controller to obtain the playback time of the progress component in the above method 1, and to obtain the bit rate and frame rate of the property editing component in the above method 2, then in specific operation, when the user realizes the logic trigger by dragging the progress bar to 1 minute and 30 seconds in the progress component, the state change information of "progress bar changed to 1 minute and 30 seconds" can be passed to the data controller. The data controller sets the value of the variable state to 1 minute and 30 seconds according to the state change information, and then sends the variable state to the preview component. The preview component determines that it is in the time range for playing the artistic text based on the rendering rules according to the value of the variable state of 1 minute and 30 seconds. The preview component can play the artistic text while playing the 1 minute and 30 second picture.

[0056] In addition, in specific operation, when the user inputs the bit rate and frame rate values ​​in the property editing component to realize the logic trigger, the corresponding data change information can be transmitted to the data controller, and the data controller can store the corresponding values ​​in the component parameter storage area according to the data change information. Before playing each screen, the preview component can send a request to obtain the bit rate and frame rate to the data controller, so that the data controller responds to the acquisition request and sends the bit rate and frame rate in the component parameter storage area to the preview component, and the preview component can play the screen according to the acquired bit rate and frame rate. It should be noted that the component can also register different synchronization methods to obtain component parameter information according to actual needs, and the embodiment of the present application does not limit the registered synchronization method.

[0057] In another search engine scenario, refer to Figure 7, which shows an interface diagram of a search engine scenario provided in an embodiment of the present application. The interface for implementing the search engine may include an input box component and a search result component, wherein the input box component is built-in by a search engine interface and can receive search content entered by the user, and the search result component needs to synchronously obtain the search results and display them.

[0058] Assuming that the input box component is registered in the data controller to obtain the search content in the above method 1, and the search result component is registered in the data controller to obtain the search result in the above method 3, then in the specific operation, when the user enters the search content in the input box component and clicks the search button to realize the logic trigger, the corresponding state change information can be passed to the data controller, and the data controller sets the value of the variable state to the search content according to the state change information, and sends the variable state to the input box component. The preview component displays the search content according to the variable state, and at the same time switches the text of the search button from "search" to "searching", and calls the search engine interface, uses the search content to search, obtains the search result, and passes the data change information corresponding to the search result to the data controller. The data controller writes the search result into the component parameter information storage area according to the data change information, and the event dispatcher extracts the search result from the component parameter storage area, and when it is determined that the search result component has selected Enable (On) for the data, the search result is sent to the search result component by broadcasting for display. It should be noted that the component can also register different synchronization methods to obtain component parameter information according to actual needs, and the embodiment of the present application does not limit the registered synchronization method.

[0059] In another logistics information sorting scenario, refer to Figure 8 , which shows an interface diagram of logistics information sorting provided in an embodiment of the present application. The interface for implementing logistics information sorting may include a logistics query component and a query result sorting and display component, wherein the logistics query component has a built-in interface for accessing the logistics information server, and can receive the identifiers of packages to be batch queried and sorted by the user, and the query result sorting and display component needs to synchronously obtain the logistics information of the packages and sort and display them according to the sorting rules.

[0060] Assuming that the search result component is registered in the data controller to obtain the logistics information of the package in the above-mentioned method three, in the specific operation, when the user enters the identifiers of multiple packages in the logistics query component to realize the logic trigger, the interface for accessing the logistics information server is called to obtain the logistics information of these packages from the logistics information server, and the data change information corresponding to the search result is passed to the data controller. The data controller writes the search result into the component parameter information storage area according to the data change information. The event dispatcher extracts the search result from the component parameter storage area, and when it is determined that the query result sorting and display component has selected enable (On) for the data, the logistics information of the package is sent to the query result sorting and display component by broadcasting. The query result sorting and display component can sort and display the logistics information of each package according to the shipping date from early to late based on the sorting rules from early to late in the logistics information in the logic layer. It should be noted that the component can also register different synchronization methods to obtain component parameter information according to actual needs. The embodiment of the present application does not limit the registered synchronization method.

[0061] In the embodiment of the present application, in the scenario of component parameter information synchronization, each component can be directly decoupled, and a direct interaction between the component and the data controller can be established, so that the component can realize the synchronization of component parameter information between components in the form of one-way interaction with the data controller through the synchronization method registered in the data controller, which solves the problem of cumbersome and complicated data synchronization methods generated by the tree-structured transmission path and external framework synchronization information in the related technology. The embodiment of the present application improves the synchronization efficiency on the basis of reducing the length and complexity of the transmission path. In addition, the embodiment of the present application increases the flexibility of the way in which the component obtains component parameter information by implementing multiple synchronization methods in the data controller for the components to choose, and the universal synchronization method implemented in the data controller allows various types of components to be called and used, which improves the adaptability of the synchronization scheme.

[0062] Reference Fig. 9 , which shows a flowchart of the steps of a method for synchronizing data between components provided by an embodiment of the present application, including:

[0063] Step 101: In response to a registration request of a component, a synchronization mode corresponding to the component is acquired from a plurality of synchronization modes.

[0064] In the embodiment of the present application, the method for synchronizing data between components is applied to Figure 1In the data controller, when the component goes online, the synchronization method can be registered in the data controller. The data controller of the embodiment of the present application provides three data or state synchronization methods. Method 1 is based on the modified state interface (Setstate), the used state interface (Usestate) and the state (state) in the form of variables to provide synchronization of states between components; Method 2 is based on the data acquisition interface (Getdata) and the modified data interface (Setdata) to provide synchronization of data between components; Method 3 is based on the modified data interface (Setdata) and the event dispatcher (event Emitter) to provide synchronization of data between components. Components can register corresponding synchronization methods according to actual needs.

[0065] It should be noted that the embodiment of the present application decouples the coupled components and forms a combined micro-front-end project, and then connects the decoupled components with the data controller to form a new synchronization method. The data controller can be extracted into an independent plug-in, which only needs to be introduced and used in the component to achieve the function of synchronizing component parameter information, and the data controller only collects and notifies changes to the component parameter information.

[0066] Step 102: Obtain change information sent by the first component in the components after the logic is triggered.

[0067] In the embodiment of the present application, there are many logic rules written in the logic layer of the component, including rules for sending change information after logic triggering, such as when a user Figure 4 When the progress bar of the progress component is dragged, the logic rule is triggered. According to the logic rule, the change information of "drag the progress bar to XX time" can be sent to the data controller, so that the data controller can change the component parameter information based on the change information, so that other subsequent components can synchronously obtain the changed component parameter information.

[0068] Step 103: Change component parameter information according to the change information.

[0069] In an embodiment of the present application, the change information is information provided after the first component logic is triggered to indicate the change of component parameter information. The data controller can change the component parameter information based on the change information. For example, there is a state in the form of a variable in the data controller. If the change information obtained by the data controller is "progress bar changes to 1 minute and 30 seconds", the value of the state in the form of the variable can be set to 1 minute and 30 seconds.

[0070] Step 104: send the changed component parameter information to the second component for rendering and display in a synchronization manner corresponding to the second component.

[0071] Optionally, the first component and the second component are the same component, or the first component and the second component are different components.

[0072] In an embodiment of the present application, when the first component and the second component are different components, a second component different from the first component registers a corresponding synchronization method in the data controller based on the need to obtain component parameter information. After the data controller changes the component parameter information according to the change information, the changed component parameter information can be sent to the second component in accordance with the synchronization method corresponding to the second component. The second component can use the component parameter information for rendering and display according to the rendering rules in the logic layer.

[0073] It should be noted that, when the first component and the second component are the same component, the first component can obtain the component parameter information in a synchronous manner of registration based on setting the component parameter information using the data controller, thereby satisfying the need for the first component to obtain the component parameter information. Figure 5 The progress component sets the state of the play time in the data controller through the user dragging the progress bar, and can also obtain the state of the play time after dragging in method 1, and display the play time after dragging at the corresponding position of the progress component.

[0074] Optionally, step 101 may be specifically implemented by responding to a registration request of a component and acquiring a synchronization method corresponding to the target component parameter information of the component from a plurality of synchronization methods.

[0075] Optionally, step 104 may be specifically implemented by sending the changed component parameter information to the second component for rendering and display in a synchronization manner corresponding to the component parameter information of the second component.

[0076] In an embodiment of the present application, a component may require multiple types of component parameter information, and the component may register different synchronization methods in the data controller for different component parameter information. For example, a component requires three types of component parameter information a, b, and c. The component may, according to actual needs, register the synchronization method of method one for component parameter information a in the data controller; register the synchronization method of method two for component parameter information b; and register the synchronization method of method three for component parameter information c, so that when the component obtains these component parameter information, it is obtained in accordance with the registered method. The embodiment of the present application does not limit the selection rules for the registered synchronization method.

[0077] In summary, in the embodiment of the present application, in the scenario of component parameter information synchronization, each component can be directly decoupled, and a direct interaction between the component and the data controller can be established, so that the component can realize the synchronization of component parameter information between components in the form of one-way interaction with the data controller through the synchronization method registered in the data controller, which solves the problem of cumbersome and complicated data synchronization methods generated by the tree-structured transmission path and external framework synchronization information in the related technology. The embodiment of the present application improves the synchronization efficiency on the basis of reducing the length and complexity of the transmission path. In addition, the embodiment of the present application increases the flexibility of the way in which the component obtains component parameter information by implementing multiple synchronization methods in the data controller for the components to choose, and the universal synchronization method implemented in the data controller allows various types of components to be called and used, thereby improving the adaptability of the synchronization scheme.

[0078] Reference Fig.10 , shows a flowchart of another embodiment of a method for synchronizing data between components of the present application. It includes:

[0079] Step 201: In response to a registration request of a component, a synchronization mode corresponding to the component is acquired from a plurality of synchronization modes.

[0080] This step may specifically refer to the above step 101, which will not be described in detail here.

[0081] Step 202: According to the modification status interface, obtain the status change information sent by the first component after the logic is triggered.

[0082] The change information includes: state change information; the component parameter information includes: state information;

[0083] Step 203: Change the state information according to the use state interface and the state change information, where the state information is in the form of variables.

[0084] Step 204, when the second component corresponds to the first synchronization mode, a rendering instruction including the changed state information is sent to the second component according to the usage state interface, so that the second component performs rendering and display according to the rendering instruction.

[0085] The solution implemented for steps 201-204 is the above embodiment. Figure 1The proposed method 1 generates state change information after component 1 is triggered by logic, and the data controller obtains the state change information through the modified state interface (Setstate), then executes S2, obtains the state change information through the use state interface (Usestate), and executes S3, uses the state change information to set the value of the state in the form of a variable after the change, and then executes S4 and S5, actively sends the state in the form of a variable after the assignment to component 1 and component 2, so that component 1 and component 2 passively receive the state after the assignment. Method 1 enables component 1 to receive the state value after the change set by the modified state interface (Setstate) and perform subsequent rendering, and component 2 can receive the state value changed according to the logic trigger operation of component 1, so that component 1 can change the state while component 2 can synchronously obtain the changed state. Among them, the use state interface (Usestate) can be a hook method provided after react 16.8, and the data controller can modify the state information of the component through this method.

[0086] In this way, the status information can be synchronized between components, and component 2 passively obtains the status information sent by the data controller, which meets the actual needs of component 2 to passively obtain status information.

[0087] Optionally, after step 204, the method further includes:

[0088] Step 205: According to the usage status interface, the changed status information is stored in a component parameter storage area.

[0089] Reference Figure 1 After sending the rendering instruction including the changed state information to component 2, S6 can be executed finally, using the state interface (Usestate) to store the state (state) in the form of a variable after the assignment to the component parameter storage area to ensure the accuracy of the state value read next time.

[0090] In summary, in the embodiment of the present application, in the scenario of component parameter information synchronization, each component can be directly decoupled, and a direct interaction between the component and the data controller can be established, so that the component can realize the synchronization of component parameter information between components in the form of one-way interaction with the data controller through the synchronization method registered in the data controller, which solves the problem of cumbersome and complicated data synchronization methods generated by the tree-structured transmission path and external framework synchronization information in the related technology. The embodiment of the present application improves the synchronization efficiency on the basis of reducing the length and complexity of the transmission path. In addition, the embodiment of the present application increases the flexibility of the way in which the component obtains component parameter information by implementing multiple synchronization methods in the data controller for the components to choose, and the universal synchronization method implemented in the data controller allows various types of components to be called and used, thereby improving the adaptability of the synchronization scheme.

[0091] Reference Fig.11 , shows a flowchart of another embodiment of a method for synchronizing data between components of the present application. It includes:

[0092] Step 301: In response to a registration request of a component, a synchronization mode corresponding to the component is acquired from a plurality of synchronization modes.

[0093] This step may specifically refer to the above step 101, which will not be described in detail here.

[0094] Step 302: According to the modified data interface, obtain the data change information sent by the first component after the logic is triggered.

[0095] The change information includes: data change information; the component parameter information includes: data information;

[0096] Step 303: modify the data information in the component parameter storage area according to the data modification interface and the data change information.

[0097] Step 304, when the second component corresponds to the second synchronization mode, in response to the second component's calling operation on the data acquisition interface, the changed data information is sent from the component parameter storage area to the second component through the data acquisition interface, so that the second component can render and display according to the changed data information.

[0098] The solution implemented for steps 301-304 is the above embodiment. Figure 2The proposed method 2 generates data change information after component 1 is logically triggered. The data controller can obtain the data change information by modifying the data interface (Setdata), and use the data change information to change the value of the corresponding data in the component parameter storage area. After that, in response to the call operation of component 2 and component 1 to the data acquisition interface (Getdata), M2 is executed, and the data acquisition interface (Getdata) extracts the changed data from the component parameter storage area, executes M3 and M4, and sends the changed data to component 1 and component 2, so that component 1 and component 2 can actively receive the changed data. Method 2 enables component 1 and component 2 to actively obtain the changed data and perform subsequent rendering, thereby achieving the purpose of component 2 being able to synchronously obtain the changed data while component 1 changes the data.

[0099] In this way, data information can be synchronized between components, and component 2 actively obtains status information sent by the data controller, which meets the actual need of component 2 to actively obtain status information.

[0100] Optionally, after step 303, the following steps may also be included:

[0101] Step 305: When the second component corresponds to the third synchronization mode, determine the state of the event dispatcher.

[0102] Step 306: When the event dispatcher is enabled, the changed data information is sent from the component parameter storage area to the second component, so that the second component can render and display according to the changed data information.

[0103] Step 307: When the event dispatcher is in a closed state, stop sending data to the second component.

[0104] The solution implemented for steps 301, 302, 303, 305, 306, and 307 is the above embodiment. Figure 3The proposed method 3 is a solution that generates data change information after component 1 is triggered by logic. The data controller can obtain the data change information by modifying the data interface (Setdata), and use the data change information to change the value of the corresponding data in the component parameter storage area. Then N2 can be executed, and the event dispatcher extracts the changed data from the component parameter storage area, and executes N3 and N4 when it is determined that component 1 and component 2 have selected enable (On) for the changed data, and sends the changed data to component 1 and component 2 by broadcasting, so that component 1 and component 2 can passively receive the changed data. Method 2 enables component 1 and component 2 to passively obtain the changed data and perform subsequent rendering, achieving the purpose of component 2 being able to synchronously obtain the changed data while component 1 is changing the data. Among them, the event dispatcher can be implemented based on the eventtEmitter3 framework. The event dispatcher is a pattern that observes a named event, triggers a callback, and then emits the event with a value.

[0105] In this way, data information can be synchronized between components, and component 2 passively obtains status information sent by the data controller, which meets the actual needs of component 2 to passively obtain status information.

[0106] Optionally, the method further includes:

[0107] Step 308: Obtain the state switching instruction sent by the second component in response to the logic rule.

[0108] Step 309: According to the state switching instruction, the event dispatcher is switched from the enabled state to the disabled state, or the event dispatcher is switched from the disabled state to the enabled state.

[0109] In addition, the second component can also send a state switching instruction to the data controller according to the judgment of the logic rule to switch the event dispatcher from the enabled state to the disabled state, or switch the event dispatcher from the disabled state to the enabled state, so that the second component can choose to receive or not receive data information. For example, when the event dispatcher is in the enabled state, the second component judges the received data information according to the prohibition of receiving data rules defined in the logic layer, and when the received data information meets the prohibition of receiving data rules, the state switching instruction is sent to the data controller to switch the event dispatcher from the enabled state to the disabled state.

[0110] In summary, in the embodiment of the present application, in the scenario of component parameter information synchronization, each component can be directly decoupled, and a direct interaction between the component and the data controller can be established, so that the component can realize the synchronization of component parameter information between components in the form of one-way interaction with the data controller through the synchronization method registered in the data controller, which solves the problem of cumbersome and complicated data synchronization methods generated by the tree-structured transmission path and external framework synchronization information in the related technology. The embodiment of the present application improves the synchronization efficiency on the basis of reducing the length and complexity of the transmission path. In addition, the embodiment of the present application increases the flexibility of the way in which the component obtains component parameter information by implementing multiple synchronization methods in the data controller for the components to choose, and the universal synchronization method implemented in the data controller allows various types of components to be called and used, thereby improving the adaptability of the synchronization scheme.

[0111] Reference Fig.12 , which shows a block diagram of an inter-component data synchronization device provided by an embodiment of the present application, including:

[0112] A response module 401 is used to respond to a registration request of a component and obtain a synchronization mode corresponding to the component from multiple synchronization modes;

[0113] An acquisition module 402 is used to acquire change information sent by a first component in the components after logic triggering;

[0114] A change module 403, used to change the component parameter information according to the change information;

[0115] The sending module 404 is used to send the changed component parameter information to the second component for rendering and display in a synchronization manner corresponding to the second component.

[0116] Optionally, the change information includes: state change information; the component parameter information includes: state information;

[0117] The acquisition module 402 includes:

[0118] A first acquisition submodule, used for acquiring, according to a modification state interface, state change information sent by the first component after logic triggering;

[0119] The changing module 403 includes:

[0120] The first changing submodule is used to change the state information according to the use state interface and the state change information, wherein the state information is in the form of variables.

[0121] Optionally, the sending module 404 includes:

[0122] The first sending submodule is used to send a rendering instruction including the changed state information to the second component according to the usage state interface when the second component corresponds to the first synchronization mode, so that the second component can render and display according to the rendering instruction.

[0123] Optionally, also include:

[0124] The storage module is used to store the changed status information in the component parameter storage area according to the usage status interface.

[0125] Optionally, the change information includes: data change information; the component parameter information includes: data information;

[0126] The acquisition module 402 includes:

[0127] A second acquisition submodule, used for acquiring data change information sent by the first component after logic triggering according to the modified data interface;

[0128] The changing module 403 includes:

[0129] The second changing submodule is used to change the data information in the component parameter storage area according to the data modification interface and the data change information.

[0130] Optionally, the sending module 404 includes:

[0131] The second sending submodule is used to send the changed data information from the component parameter storage area to the second component through the data acquisition interface in response to the calling operation of the second component on the data acquisition interface when the second component corresponds to the second synchronization mode, so that the second component can render and display according to the changed data information.

[0132] Optionally, the sending module 404 includes:

[0133] a determination submodule, configured to determine a state of an event dispatcher when the second component corresponds to a third synchronization mode;

[0134] A first processing submodule, configured to send the changed data information from the component parameter storage area to the second component when the event dispatcher is in an enabled state, so that the second component can render and display the changed data information;

[0135] The second processing submodule is used to stop sending data to the second component when the event dispatcher is in a closed state.

[0136] Optionally, also include:

[0137] A switching instruction module, used for obtaining a state switching instruction sent by the second component in response to a logic rule;

[0138] The switching module is used to switch the event dispatcher from an enabled state to a disabled state, or from a disabled state to an enabled state according to the state switching instruction.

[0139] Optionally, the acquisition module 402 includes:

[0140] A selection submodule, for obtaining, in response to a registration request of a component, a synchronization method corresponding to target component parameter information of the component from a plurality of synchronization methods;

[0141] The sending module 404 includes:

[0142] The synchronization submodule is used to send the changed component parameter information to the second component for rendering and display in a synchronization manner corresponding to the component parameter information of the second component.

[0143] Optionally, the first component and the second component are the same component, or the first component and the second component are different components.

[0144] In summary, in the embodiment of the present application, in the scenario of component parameter information synchronization, each component can be directly decoupled, and a direct interaction between the component and the data controller can be established, so that the component can realize the synchronization of component parameter information between components in the form of one-way interaction with the data controller through the synchronization method registered in the data controller, which solves the problem of cumbersome and complicated data synchronization methods generated by the tree-structured transmission path and external framework synchronization information in the related technology. The embodiment of the present application improves the synchronization efficiency on the basis of reducing the length and complexity of the transmission path. In addition, the embodiment of the present application increases the flexibility of the way in which the component obtains component parameter information by implementing multiple synchronization methods in the data controller for the components to choose, and the general synchronization method implemented in the data controller allows various types of components to be called and used, thereby improving the adaptability of the synchronization scheme.

[0145] The embodiment of the present application also provides a non-volatile readable storage medium, which stores one or more modules (programs). When the one or more modules are applied to a device, the device can execute instructions (instructions) of each method step in the embodiment of the present application.

[0146] The present application embodiment provides one or more machine-readable media on which instructions are stored, and when executed by one or more processors, an electronic device executes one or more of the methods described in the above embodiments. In the present application embodiment, the electronic device includes various types of devices such as terminal devices and server terminals (clusters).

[0147] The embodiments of the present disclosure may be implemented as a device that uses any appropriate hardware, firmware, software, or any combination thereof to perform desired configurations, and the device may include electronic devices such as terminal devices and server (cluster). Fig.13 An exemplary device 1000 that can be used to implement various embodiments described in the embodiments of the present application is schematically shown.

[0148] For one embodiment, Fig.13 An exemplary apparatus 1000 is shown having one or more processors 1002, a control module (chip set) 1004 coupled to at least one of the (one or more) processors 1002, a memory 1006 coupled to the control module 1004, a non-volatile memory (NVM) / storage device 1008 coupled to the control module 1004, one or more input / output devices 1010 coupled to the control module 1004, and a network interface 1012 coupled to the control module 1004.

[0149] The processor 1002 may include one or more single-core or multi-core processors, and the processor 1002 may include any combination of general-purpose processors or special-purpose processors (such as graphics processors, application processors, baseband processors, etc.). In some embodiments, the device 1000 can be used as a terminal device, a server (cluster), and other devices described in the embodiments of the present application.

[0150] In some embodiments, the apparatus 1000 may include one or more computer-readable media (e.g., memory 1006 or NVM / storage device 1008) having instructions 1014 and one or more processors 1002 combined with the one or more computer-readable media and configured to execute the instructions 1014 to implement a module to perform the actions described in the present disclosure.

[0151] For one embodiment, the control module 1004 may include any suitable interface controller to provide any suitable interface to at least one of the processor(s) 1002 and / or any suitable device or component in communication with the control module 1004 .

[0152] The control module 1004 may include a memory controller module to provide an interface to the memory 1006. The memory controller module may be a hardware module, a software module, and / or a firmware module.

[0153] The memory 1006 may be used, for example, to load and store data and / or instructions 1014 for the device 1000. For one embodiment, the memory 1006 may include any suitable volatile memory, such as a suitable DRAM. In some embodiments, the memory 1006 may include double data rate type four synchronous dynamic random access memory (DDR4 SDRAM).

[0154] For one embodiment, control module 1004 may include one or more input / output controllers to provide an interface to NVM / storage device 1008 and input / output device(s) 1010 .

[0155] For example, NVM / storage 1008 may be used to store data and / or instructions 1014. NVM / storage 1008 may include any suitable non-volatile memory (e.g., flash memory) and / or may include any suitable non-volatile storage device(s) (e.g., one or more hard disk drives (HDDs), one or more compact disk (CD) drives, and / or one or more digital versatile disk (DVD) drives).

[0156] NVM / storage device 1008 may include storage resources that are physically part of the device on which apparatus 1000 is installed, or it may be accessible to the device without being part of the device. For example, NVM / storage device 1008 may be accessed via input / output device(s) 1010 over a network.

[0157] (One or more) input / output devices 1010 may provide an interface for the apparatus 1000 to communicate with any other appropriate device, and the input / output device 1010 may include a communication component, an audio component, a sensor component, etc. The network interface 1012 may provide an interface for the apparatus 1000 to communicate through one or more networks, and the apparatus 1000 may wirelessly communicate with one or more components of a wireless network according to any of one or more wireless network standards and / or protocols, for example, accessing a wireless network based on a communication standard, such as WiFi, 2G, 3G, 4G, 5G, etc., or a combination thereof for wireless communication.

[0158] For one embodiment, at least one of the processor(s) 1002 may be packaged together with the logic of one or more controllers (e.g., a memory controller module) of the control module 1004. For one embodiment, at least one of the processor(s) 1002 may be packaged together with the logic of one or more controllers of the control module 1004 to form a system-in-package (SiP). For one embodiment, at least one of the processor(s) 1002 may be integrated on the same die with the logic of one or more controllers of the control module 1004. For one embodiment, at least one of the processor(s) 1002 may be integrated on the same die with the logic of one or more controllers of the control module 1004 to form a system-on-chip (SoC).

[0159] In various embodiments, the device 1000 may be, but is not limited to, a terminal device such as a server, a desktop computing device, or a mobile computing device (e.g., a laptop computing device, a handheld computing device, a tablet computer, a netbook, etc.). In various embodiments, the device 1000 may have more or fewer components and / or different architectures. For example, in some embodiments, the device 1000 includes one or more cameras, a keyboard, a liquid crystal display (LCD) screen (including a touch screen display), a non-volatile memory port, multiple antennas, a graphics chip, an application-specific integrated circuit (ASIC), and a speaker.

[0160] Among them, the main control chip can be used as a processor or control module in the detection device, sensor data, location information, etc. are stored in a memory or NVM / storage device, the sensor group can be used as an input / output device, and the communication interface may include a network interface.

[0161] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0162] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.

[0163] The embodiments of the present application are described with reference to the flowcharts and / or block diagrams of the methods, terminal devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0164] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing terminal device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0165] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable terminal device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0166] Although the preferred embodiments of the present application have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and changes and modifications that fall within the scope of the embodiments of the present application.

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

[0168] The above is a detailed introduction to a method, device, electronic device and storage medium for synchronizing data between components provided by the present application. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea; at the same time, for general technical personnel in this field, according to the idea of ​​the present application, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.

Claims

1. A method for synchronizing data between components, applied to a data controller, characterized in that: include: In response to a registration request of a component, acquiring a synchronization method corresponding to target component parameter information of the component from a plurality of synchronization methods; Registering the synchronization mode corresponding to the target component parameter information in the data controller; Obtaining change information sent by a first component in the components after logic triggering; According to the change information, the component parameter information is changed; In a synchronization manner corresponding to the component parameter information of the second component, the changed component parameter information is sent to the second component for rendering and display.

2. The method according to claim 1, characterized in that The change information includes: state change information; the component parameter information includes: state information; The obtaining of change information sent by the first component in the components after the logic is triggered includes: According to the modification state interface, obtaining the state change information sent by the first component after the logic is triggered; The step of changing the component parameter information according to the change information includes: The state information is changed according to the usage state interface and the state change information, wherein the state information is in the form of a variable.

3. The method according to claim 2, characterized in that The sending the changed component parameter information to the second component for rendering and display in a synchronization manner corresponding to the component parameter information of the second component includes: In the case where the second component corresponds to the first synchronization mode, a rendering instruction including the changed state information is sent to the second component according to the usage state interface, so that the second component performs rendering and display according to the rendering instruction.

4. The method according to claim 3, characterized in that After sending the rendering instruction including the changed state information to the second component according to the usage state interface, the method further includes: According to the usage status interface, the changed status information is stored in a component parameter storage area.

5. The method according to claim 1, characterized in that The change information includes: data change information; the component parameter information includes: data information; The obtaining of change information sent by the first component in the components after the logic is triggered includes: According to the data modification interface, obtaining data change information sent by the first component after the logic is triggered; The step of changing the component parameter information according to the change information includes: According to the data modification interface and the data change information, the data information in the component parameter storage area is changed.

6. The method according to claim 5, characterized in that The sending the changed component parameter information to the second component for rendering and display in a synchronization manner corresponding to the component parameter information of the second component includes: When the second component corresponds to the second synchronization mode, in response to the second component's calling operation on the data acquisition interface, the changed data information is sent to the second component from the component parameter storage area through the data acquisition interface, so that the second component can render and display according to the changed data information.

7. The method according to claim 5, characterized in that The sending the changed component parameter information to the second component for rendering and display in a synchronization manner corresponding to the component parameter information of the second component includes: In the case where the second component corresponds to the third synchronization mode, determining a state of the event dispatcher; When the event dispatcher is in an enabled state, the changed data information is sent from the component parameter storage area to the second component, so that the second component can render and display according to the changed data information; When the event dispatcher is in a closed state, stop sending data to the second component.

8. The method according to claim 7, characterized in that Also includes: Obtaining a state switching instruction sent by the second component in response to a logic rule; According to the state switching instruction, the event dispatcher is switched from the enabled state to the disabled state, or the event dispatcher is switched from the disabled state to the enabled state.

9. The method according to any one of claims 1 to 8, characterized in that: The first component and the second component are the same component, or the first component and the second component are different components.

10. An electronic device, characterized in that: include: processor; and A memory having executable codes stored thereon, which, when the executable codes are executed, enable the processor to perform the method according to any one of claims 1 to 9.

11. A machine-readable medium having executable codes stored thereon, which, when executed, causes a processor to execute the method according to any one of claims 1 to 9.