View component state management method, device, electronic device and storage medium
By obtaining the state behavior of the target view element in the Redux framework and determining the management tool processing state behavior in the state management library, the problems of excessive template code, weak type support, and complex interface definitions in the Redux framework are solved, and a simplified state is achieved Management and TypeScript type system support.
Patent Information
- Application Number
- CN202110013533.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-01-06
- Publication Date
- 2024-10-18
- Estimated Expiration
- 2041-01-06
AI Technical Summary
In the existing technology, the Redux framework has problems such as too much template code, weak type support, and complex interface definitions in state management. It is especially difficult to adapt to the TypeScript type system.
By obtaining the target state behavior of the target view element, the target management tool is determined in the state management library, and the tool is called to process the state behavior to directly update the state and avoid the state behavior transfer of multiple transit modules. Combined with the logical processor and type system to simplify state management.
The template code is greatly reduced, type support is improved, the TypeScript type system is applicable, the state management framework is simplified, and the complexity problems in the existing technology are solved.
Smart Images

Figure CN112698824B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present disclosure relate to the field of computer and network communication technology, and in particular, to a view component state management method, device, electronic device, and storage medium. Background Art
[0002] In recent years, with the rise of single-page applications, JavaScript needs to manage more states, or data, than ever before. These states include: server responses, cached data, locally generated data that has not yet been persisted to the server, and UI states, such as activated routes, selected tags, whether to display loading animations or pagers, etc. These are challenges that web developers did not encounter ten or twenty years ago. As the proportion of single-page applications with front-end rendering pages increases, the complexity of front-end work is also rising sharply, and the information displayed on the front-end page is becoming more and more complex. This makes state management more and more important.
[0003] At present, a large number of front-end projects are using or turning to frameworks such as Vue.js and React.js for development. Among the third-party frameworks for front-end state management, Flux, Redux, Vuex, Mobx, etc. are more commonly used, and Redux is the most widely used. There are two modes of using Redux: the first is to simply use the pure redux library, which has obvious disadvantages. It is necessary to introduce the state library store in the places where data is changed and monitored, and manually associate it with the components, so the second method is generated; the second is to use redux+react-redux. Compared with the first method, it does not need to manually handle the relationship between the global state and react (response), and the code becomes simpler, but in this method, two modules action creator and reducer are required. Action creators have to write a lot of repetitive code, and reducers frequently use switch case statements. In addition, the Redux framework uses string types too much for parameter passing, making this method difficult to adapt to Typescript-type systems and difficult to implement strict code constraints, which makes it easy to write erroneous code. Furthermore, Redux is split into many modules, resulting in the need to modify many modules associated with a single data modification, which brings great inconvenience to state management development work.
[0004] That is, the state management framework in the prior art has technical problems such as too much template code, weak type support, and complex interface definition. Summary of the invention
[0005] The embodiments of the present disclosure provide a view component state management method, device, electronic device and storage medium to overcome the technical problems in the prior art of state management framework, such as excessive template codes, weak type support and complex interface definition.
[0006] In a first aspect, an embodiment of the present disclosure provides a method for managing a view component state, including:
[0007] Get the target state behavior of the target view component. The target state behavior is used to determine the change type of the state. The state is the logical state of the target view component.
[0008] In the state management library, a target management tool is determined according to the target state behavior. The state management library includes a plurality of management tools. The management tools include a logic processor. The logic processor is used to process the logical relationship between the state of the view element in the management tool and the state behavior.
[0009] The target management tool is called to process the target state behavior to determine the new state of the target view element.
[0010] In a second aspect, an embodiment of the present disclosure provides a view component state management device, including:
[0011] An acquisition module, used to acquire a target state behavior of a target view component, where the target state behavior is used to determine a change type of a state, and the state is a logical state of the target view component;
[0012] A state management library module is used to determine a target management tool according to a target state behavior. The state management library module includes multiple management tools. The management tools include a logic processor. The logic processor is used to process the logical relationship between the state and state behavior of the view element in the management tool.
[0013] The processing module is used for calling the target management tool to process the target state behavior to determine the new state of the target view element.
[0014] In a third aspect, an embodiment of the present disclosure provides an electronic device, including:
[0015] at least one processor and memory;
[0016] The memory stores computer-executable instructions;
[0017] The at least one processor executes the computer-executable instructions stored in the memory, so that the at least one processor executes the view component state management method as described in the first aspect and various possible designs of the first aspect.
[0018] In a fourth aspect, an embodiment of the present disclosure provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer execution instructions. When a processor executes the computer execution instructions, the view element state management method described in the first aspect and various possible designs of the first aspect is implemented.
[0019] In a fifth aspect, an embodiment of the present disclosure provides a computer program product, including a computer program, which, when executed by a processor, implements the view element state management method as described in the first aspect and various possible designs of the first aspect.
[0020] The view component state management method, device, electronic device and storage medium provided in the present embodiment first obtain the target state behavior of the target view component, then determine a target management tool in the state management library according to the target state behavior, and then call the target management tool to process the target state behavior to determine the new state of the target view component. The state management library of the disclosed embodiment combines the state behavior with the logical processor for processing the state behavior to form a management tool. When processing the state behavior, the state update can be completed by directly instantiating the management tool. There is no need to transfer the state behavior through multiple transfer modules as in the prior art, which solves the technical problems of the state management framework in the prior art with too much template code, weak type support and complex interface definition. The technical effect of simplifying the state management framework, greatly reducing the template code, and applying the TypeScript type system is achieved. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] In order to more clearly illustrate the embodiments of the present disclosure or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present disclosure. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0022] Figure 1 A state management logic diagram provided for an embodiment of the present disclosure;
[0023] Figure 2 A logical diagram of the Redux framework management state provided in the embodiment of the present disclosure;
[0024] Figure 3 The embodiments of the present disclosure provide Figure 2 Schematic diagram of the structure of the state library;
[0025] Figure 4 A schematic diagram of the structure and application scenarios of the state management library provided in the embodiment of the present disclosure;
[0026] Figure 5 A flow chart of a method for managing the state of a view element provided in an embodiment of the present disclosure Figure 1 ;
[0027] Figure 6 A schematic diagram of an application scenario of the view component state management method provided in an embodiment of the present application;
[0028] Figure 7 A flow chart of a method for managing the state of a view element provided in an embodiment of the present disclosure Figure 2 ;
[0029] Figure 8 A flow chart of a method for managing the state of a view element provided in an embodiment of the present disclosure Figure 3 ;
[0030] Fig. 9 A schematic diagram of the logical relationship between the state management library, the context provider and the context component provided in the embodiment of the present application;
[0031] Fig.10 A structural block diagram of a view component state management device provided by an embodiment of the present disclosure;
[0032] Fig.11 A schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION
[0033] In order to make the purpose, technical solution and advantages of the embodiments of the present disclosure clearer, the technical solution in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are part of the embodiments of the present disclosure, not all of the embodiments. Based on the embodiments in the present disclosure, all other embodiments obtained by ordinary technicians in this field without creative work, including but not limited to the combination of multiple embodiments, belong to the scope of protection of the present disclosure.
[0034] The terms "first", "second", "third", "fourth", etc. (if any) in the specification and claims of the present disclosure and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present disclosure described herein can, for example, be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0035] To facilitate understanding, the professional terms involved in this application are explained below.
[0036] State: The state in this disclosure is a data source used to control the display effect of a view element.
[0037] State management: It is to extract the data source that controls the display effect of the view component separately, independently of the logical flow of the processing method, and manage it in a unified manner, so that the logic of state changes can be better predicted, and only the logical connection is highlighted, which makes the implementation of logic more organized and easier to control state changes.
[0038] Here is an explanation of why state management is necessary. Because there are usually some shared states between view components, we usually promote this part of the state to global variables, and the global components will manage the shared state uniformly, and when the state changes, the view components need to be notified to update. However, as the number of states increases and the project becomes more and more complex, a state management tool is urgently needed to help sort out the logic of shared states, and state management tools have also emerged.
[0039] The basic logic of the state management framework model is as follows:
[0040] 1. Store the state of the view component in an external state library store;
[0041] 2. Use state to control the display effect of view components, or the display effect;
[0042] 3. View components change their state by triggering logical behaviors or state behaviors, and update the view components to display the new state.
[0043] The initial inventive concept of the present disclosure is formed according to the above mode, and the corresponding state management process is as follows: Figure 1 shown.
[0044] refer to Figure 1 , Figure 1 A state management logic diagram provided by an embodiment of the present disclosure. Figure 1 As shown, the state library Store10 receives the state behavior notification of the view element 11, such as Figure 1The view element 11 includes at least two view elements, namely, view element 111 and view element 112, which can trigger state behavior notifications separately or simultaneously. After receiving the state behavior notification from view element 11, the state library Store 10 sends the shared state 101 of view element 111 and view element 112 to the corresponding view element 111 or view element 112, or sends it to view element 111 and view element 112 together after state management.
[0045] In this process, the most complicated issue is how to manage the status.
[0046] To facilitate explanation of the inventive concept of the disclosed embodiments, the management logic of the Redux framework for state management in the prior art is introduced below.
[0047] In the Redux framework, there are three core modules, namely the state library Store, the behavior Action, and the behavior processing module Reducer.
[0048] (1) State Library Store:
[0049] It is used to store the state of each view component in the application, as well as the dispatch method used to trigger the state update. There is only one state library Store in the entire application.
[0050] Several interface tool APIs for managing state are provided in the state library Store:
[0051] ■store.getState(): Get the current state;
[0052] ■store.dispatch(Action): sends an action to the action processing module Reducer for processing;
[0053] ■store.subscribe(listener): Set the listener function listener to monitor state changes (if the view component update function is passed in as the listener function listener, it can trigger the view to render automatically).
[0054] (2) Action:
[0055] An action is a parameter generated by the action encapsulation creator Action Creator and received by the action processing module Reducer. It is initially triggered by a view component.
[0056] The action contains the following information:
[0057] ●A string type field to indicate the action to be performed;
[0058] ●Other data information that needs to be passed to the application. The data format or type can be customized by the user.
[0059] (3) Behavior processing module Reducer:
[0060] It is a function that calculates the new state newState based on the action Action and the state State. That is, the new state newState is derived by applying the current state previousState and the action Action:
[0061] It can be expressed as: (previousState,Action)=>newState.
[0062] refer to Figure 2 , Figure 2 This is a logical diagram of the Redux framework management state provided in the embodiment of the present disclosure. Figure 2 As shown, after the user interacts with the view component on the front-end page, the tracker trigger captures the behavior Action, and the tracker trigger triggers the behavior encapsulation creator Action Creator to generate a string corresponding to the behavior Action. Then, store.dispatch(Action) in the state library Store passes the behavior Action to the state library Store through the string. The state library Store calls the behavior processing module Reducer and generates a new state newState. Then the state library Store updates the state of the view component and displays the new state.
[0063] It should be noted that the state library Store generally has a connection processor for processing connection relationships, which is used to receive behavior Actions and transmit new / old states. The behavior processing module Reducer can generally contain multiple modules, corresponding to different logical behaviors. When the logical behaviors have a progressive inclusion relationship or the logical behaviors have a logical order relationship, the relationship between the behavior processing module Reducers is as follows: Figure 2As shown, the root behavior processing module represents the logic behavior with the largest coverage, and its corresponding logic behavior can be further divided into two branches, such as behavior processing module 1 to behavior processing module 2, and behavior processing module 3 to behavior processing module 4. These two branches represent two parallel logics. If the root logic processing module is a four-arithmetic operation module, behavior processing module 1 represents the accumulation behavior, behavior processing module 3 represents the accumulation behavior, and behavior processing module 2 represents the behavior of adding two variables, and behavior processing module 4 represents the behavior of multiplying two variables.
[0064] from Figure 2 It can be seen that when the existing Redux framework is performing state management, the behavior Action needs to be encapsulated by the behavior encapsulation creator Action Creator with a string representing the behavior type Type, as well as other data involved in the behavior Action, before it can be passed to the state library Store using store.dispatch(Action). It is these two steps that require application developers to prepare a large amount of repetitive template code to make the Redux framework effective, and because the behavior encapsulation creator Action Creator attaches a string of the behavior type Type to the behavior Action, it is this string that causes type conflicts in the Typescript type system, which is based on the addition of variable types. This is because the behavior Action itself can be seen as an array type, but after using the Redux framework, it is assigned a string type String, which leads to type conflicts and makes the Redux framework unable to support the Typescript type system.
[0065] How to improve the Redux framework so that it can reduce the amount of repetitive template code caused when managing a large number of states, and enable the new state management framework to support the Typescript system with variable type restrictions as the core, has become a technical problem that needs to be solved urgently, that is, the innovative starting point of the present disclosure.
[0066] After in-depth research, the inventors of the present disclosure found that the difficulty in solving the above problem lies in how to omit the behavior encapsulation creator Action Creator and store.dispatch(Action) to achieve the following: Figure 1 The state update of the state library Store directly triggered by the state behavior as shown is the biggest technical obstacle faced by the embodiments of the present disclosure.
[0067] After in-depth research, the inventor of the present disclosure found that the core module in the Redux framework that really plays a role in obtaining new states is the "behavior processing module Reducer", and the state library Store only plays the role of storing the state. This simple storage method cannot meet the needs of efficient utilization. In order to make it easier to understand the problems of the existing Redux framework, the following is combined with Figure 3 Provide a brief description.
[0068] refer to Figure 3 , Figure 3 The embodiments of the present disclosure provide Figure 2 Schematic diagram of the state library in the figure. Figure 3 As shown, the state library 300 in the Redux framework simply stores the states corresponding to various view components by category, such as Figure 3 The first state set 301, the second state set 302, the third state set 303, the fourth state set 304, the fifth state set 305, the sixth state set 306, and the seventh state set 307 shown correspond to different states of different view components. If the state State is regarded as a component, then the behavior processing module Reducer is the machine that processes the component. The old component is processed by the machine to obtain a new component, and the behavior Action is the switch button of the machine. This is the relationship between the state library Store, the behavior processing module Reducer, and the behavior Action in the existing Redux framework.
[0069] After in-depth research on the relationship between the above three, the inventor of the present disclosure found that the reason why the existing Redux framework requires a lot of template codes to connect is that it must ensure that the behavior processing module Reducer used by the state State changed by the behavior Action is already registered and exists, otherwise it will cause a logic call error, resulting in the Redux framework being unable to complete the state update. In other words, the machine corresponding to the switch button must be an existing machine to process the parts. If the machine corresponding to the switch button has not been installed and prepared, then the parts cannot be processed, which will cause an error.
[0070] Thus, the inventive concept of the present disclosure is obtained: the embodiment of the present disclosure creatively breaks the way or logical structure of responding to the behavior Action of the Redux framework in the prior art. The behavior processing module Reducer, the behavior Action and the state State are combined together to form a management tool. In this way, when the behavior Action is captured, the management tool that matches it can be found, and the management tool can be instantiated, that is, the corresponding instance of the management tool is generated. This instance exists with the view component and is specifically used to manage the state generated by the preset behavior corresponding to the view component. Correspondingly, the original state library is transformed into a state management library to store various state management tools. The state management library can be set as a type system, that is, the variables involved specify their data types, and the type limitation of the type system is used to ensure the accurate calling of each data. There will be no situation in which the behavior processing module Reducer in the existing Redux framework is called without being registered, and there is no need for a large amount of target code to construct the behavior encapsulation creator Action Creator and the store.dispatch (Action) method tool, which solves the technical problems of too much template code and complex interface definition in the state management framework in the prior art. At the same time, variable type restrictions are added to the state management library and state management tools to meet the support requirements of the Typescript type system, solving the technical problem of weak type support in the existing state management framework.
[0071] For ease of understanding, the following Figure 4 The state management library of the embodiment of the present disclosure is described below.
[0072] refer to Figure 4 , Figure 4 The structure and application scenario diagram of the state management library provided in the embodiment of the present disclosure. Figure 4 As shown, the state management library 400 includes multiple management tools, such as the first management tool 401, the second management tool 402, and the third management tool 403. After the state behavior 411 is captured by the tracker trigger, the interface tool API (Application Programming Interface) of the state management library finds the corresponding management tool, i.e., the first management tool 401, and instantiates it into the first instance 4011. Then, the state behavior 411 is used to activate the first instance 4011, and after being processed by the first instance 4011, a new state 412 is output.
[0073] The specific steps of the view component state management method provided by the embodiment of the present disclosure are introduced in detail below.
[0074] refer to Figure 5 , Figure 5 A flow chart of a method for managing the state of a view element provided in an embodiment of the present disclosure Figure 1 The method of this embodiment is applied in a terminal device and / or a server at a user end. The view component state management method includes:
[0075] S501: Obtain the target state behavior of the target view component.
[0076] In this step, the target state behavior is used to determine the change type of the state, which is the logical state of the target view element.
[0077] Specifically, after the user operates the target view element, that is, after there is an interactive operation with the target view element, the state of each view element in the application can be detected in real time by setting a patrol thread or a state tracker trigger in the application. Therefore, the user's interactive operation on the target view element constitutes a trigger factor for the state change of the target view element, that is, the target state behavior.
[0078] refer to Figure 6 , Figure 6 A schematic diagram of an application scenario of the view component state management method provided in the embodiment of the present application. Figure 6 As shown in FIG. 6 , when the user clicks the “add 1 button 601” or the “multiply 2 button 602” on the application interface, the inspection thread or the state tracker trigger will capture this interactive operation, i.e., the target state behavior. Figure 6 The target view element is digital display element 603 .
[0079] S502: In the state management library, determine a target management tool according to the target state behavior.
[0080] In this step, the state management library includes a plurality of management tools, and the management tools include a logic processor, and the logic processor is used to process the logical relationship between the state and state behavior of the view element in the management tool.
[0081] Specifically, the target management tool corresponding to the target state behavior can be retrieved in the state management library through the interface component of the state management library, such as the Hooks component. It should be noted that different target state behaviors require different numbers of target management tools. For example, a weighted average calculation button can use the addition management tool and the multiplication management tool respectively, and of course, the weighted average management tool can also be used directly. Therefore, for the target state behavior, a target management tool can be found in the state management library.
[0082] For example, Figure 6As shown, the plus 1 button 601 corresponds to the "plus 1" management tool, i.e., the target management tool. The "plus 1" management tool processes the logical behavior of "addition", and the logical behavior of "addition" requires "addend" and "addend". The "addend" is equivalent to the old state PreviousState of the digital display element 603, and the "addend" is the state variable with the variable type defined in the logical processor in the "plus 1" management tool. Here, the state variable is 1, and the variable type is a digital type. It should be noted that the difference between the logical processor in the "plus 1" management tool and the behavior processing module Reducer in the prior art includes the definition of the variable type of the state variable, so that if the developer calls the wrong logical processor or target management tool, the compiler or compilation environment tool will automatically prompt a logical error, and there is no need to build a behavior encapsulation creator Action Creator and a store.dispatch (Action) method tool like the Redux framework to avoid such errors. It saves a lot of repeated template code work, improves the efficiency of application development, simplifies the application code volume, and improves the processing and compilation efficiency.
[0083] It should be noted that, in a possible design, the old state PreviousState of the target view component is included in all management tools that use the old state, and when the old state is updated to a new state, all management tools will be updated synchronously.
[0084] It should also be noted that in another possible design, in addition to the logical processor, the target management tool also includes type-defined parameters, such as the old state PreviousState, which enables the target management tool to well support Typescript type systems.
[0085] That is, the parameters in the management tool and the logical processor define parameter types, and the parameter types include: at least one of a value, an array, a text, and a function;
[0086] The parameter type is used to ensure that no logic error occurs when the target management tool is called to process the target state behavior.
[0087] S503: Calling the target management tool to process the target state behavior to determine the new state of the target view element.
[0088] In this step, since the logical processors are already included in the target management tool, Figure 1 In the framework, the corresponding logical relationship is directly processed according to the state behavior to determine the basic design of the new state. This truly avoids the above problems in the Redux framework.
[0089] The view component state management method provided by the embodiment of the present disclosure first obtains the target state behavior of the target view component, then determines the target management tool in the state management library according to the target state behavior, and then calls the target management tool to process the target state behavior to determine the new state of the target view component. The state management library of the embodiment of the present disclosure combines the state behavior with the logical processor for processing the state behavior to form a management tool. When processing the state behavior, the state update can be completed by directly instantiating the management tool. There is no need to transfer the state behavior through multiple transfer modules as in the prior art, which solves the technical problems of the state management framework in the prior art with too much template code, weak type support, and complex interface definition. The technical effect of simplifying the state management framework, greatly reducing the template code, and applying the TypeScript type system is achieved.
[0090] refer to Figure 7 , Figure 7 A flow chart of a method for managing the state of a view element provided in an embodiment of the present disclosure Figure 2 The method of this embodiment is applied in a terminal device and / or a server at a user end. The view component state management method includes:
[0091] S701: Obtain the target state behavior of the target view component.
[0092] In this step, the target state behavior is used to determine the change type of the state, which is the logical state of the target view element.
[0093] Specifically, after the user operates the target view element, that is, after there is an interactive operation with the target view element, the state of each view element in the application can be detected in real time by setting a patrol thread or a state tracker trigger in the application. Therefore, the user's interactive operation on the target view element constitutes a trigger factor for the state change of the target view element, that is, the target state behavior.
[0094] S702: According to the target state behavior, determine the target management tool in the state management library through the target pointer of the hook interface component.
[0095] In this step, the state management library includes: a logical processor set, a state behavior set, an initial state set and a management tool set; the management tool set includes multiple management tools, and the management tool includes a logical processor, which is used to process the logical relationship between the state and state behavior of the view elements in the management tool.
[0096] It should be noted that the logical processor set includes the logical processors in each management tool, the state behavior set includes the state behaviors involved in each management tool, and the initial state set includes the initial state of each state behavior.
[0097] In this embodiment, the logical processor set, state behavior set and initial state set are used to provide the logical processors, state behaviors and initial states of each state involved in a new management tool when the management tool is newly created. After a management tool is created for the first time, it will be added to the management tool set and a corresponding pointer will be created for the management tool so that the management tool can be quickly found when the management tool is called without traversing and searching one by one.
[0098] It should also be noted that the hook interface component, such as the hooks class function object, is the API interface component corresponding to the state management library. Each management tool in the management tool set has its corresponding pointer, which is stored in the hook interface component.
[0099] S703: Call the target management tool to process the target state behavior according to the target pointer to determine the new state of the target view element.
[0100] In this step, after the hook interface component finds the corresponding target management tool through the target pointer, the hook interface component passes the state behavior to the target management tool for logical processing to obtain the new state of the target view component.
[0101] The view component state management method provided by the embodiment of the present disclosure first obtains the target state behavior of the target view component, then determines the target management tool in the state management library through the target pointer of the hook interface component according to the target state behavior, and then calls the target management tool according to the target pointer to process the target state behavior to determine the new state of the target view component. Figure 5 On the basis of the illustrated embodiment, a pointer is used to quickly locate the target management tool, and a logical processor set, a state behavior set, an initial state set, and a management tool set are added to the state management library to facilitate updating or creating a new management tool or initializing the management tool. The state management library of the disclosed embodiment combines the state behavior with the logical processor that processes the state behavior to form a management tool. When processing the state behavior, the management tool is directly instantiated to complete the state update. There is no need to transfer the state behavior through multiple transfer modules as in the prior art, which solves the technical problems of the state management framework in the prior art, such as too much template code, weak type support, and complex interface definition. The technical effect of simplifying the state management framework, greatly reducing the template code, and applying the TypeScript type system is achieved.
[0102] refer to Figure 8 , Figure 8 A flow chart of a method for managing the state of a view element provided in an embodiment of the present disclosure Figure 3The method of this embodiment is applied in a terminal device and / or a server at a user end. The view component state management method includes:
[0103] S801: Obtain the target state behavior of the target view element through the hook interface component.
[0104] In this step, the target state behavior includes: the current state of the target behavior object and the target logical behavior. Logical behavior is the trigger factor of the internal logical relationship that triggers the state change, including: operation logic behavior, judgment logic behavior, selection logic behavior, etc. For example, addition, subtraction, multiplication, division, integration, and differentiation belong to operation logic behavior, and Boolean type belongs to judgment logic behavior.
[0105] S802: Using the hook interface component, determine the target pointer corresponding to the target management tool according to the target logical behavior.
[0106] In this step, the target pointer is included in the hook interface component, and there is a corresponding mapping relationship between the target logical behavior and the target pointer. The corresponding target pointer can be found from the mapping table.
[0107] It should be noted that, when the new state corresponding to the target state behavior is a state shared by multiple view components, a context component is required to obtain a target pointer corresponding to the shared target management tool.
[0108] Specifically, when determining the target pointer, the target logical behavior must have certain context support, that is, the logical settings of various passed parameters and the definition and limitation of parameter types must be done well. The specific steps include:
[0109] S8021: Get the context provider of the target pointer according to the logical behavior.
[0110] In this step, multiple context providers, such as contextProvider in Java, are attached to the state management library or the hook interface component of the state management library to provide corresponding interface APIs for the connection between the logical behavior and the target pointer.
[0111] S8022: Determine the target pointer based on the context provider.
[0112] In this step, the context provider directly extracts the corresponding target pointer from the hook interface component. Specifically, it includes:
[0113] Get the context component encapsulated by the context provider;
[0114] Determine the target pointer based on the context component.
[0115] It should be noted that the context provider is used to provide a connection interface between the state management library and the context component (such as context in Java), and the target context component is used to provide a logical calling environment support for calling the target management tool.
[0116] In order to facilitate understanding of the implementation principle of step S802, Fig. 9 To illustrate it visually.
[0117] refer to Fig. 9 , Fig. 9 A schematic diagram of the logical relationship between the state management library, context provider, and context component provided in the embodiment of the present application. Fig. 9 As shown, the state management library 91 includes multiple management tools, namely management tool 911, management tool 912 and management tool 913. Each management tool only corresponds to a specific transmission pipeline in the context provider 92, that is, the context provider 921, the following context provider 922 and the following context provider 923 can be regarded as the door for leaving the state management library or the corresponding library administrator when the management tool 911, the management tool 912 and the management tool 913 are called. Only through the corresponding door or with the consent of the library administrator can they leave the state library and be called. The context component is equivalent to the corresponding transportation channel or transportation vehicle after leaving the warehouse. The management tool 911 can only be transported out in the context component 931, and the management tool 912 can only be transported out in the context component 932. Similarly, the management tool 913 can only be transported out in the context component 933 and finally arrive at the called location. This is the specific process of calling the management tool in the state library. This process ensures that the management tool is strictly limited in its calling logic. Calling logic errors in the context provider and / or context component will trigger compilation alerts. This ensures that there will be no logic errors when the state behavior directly calls the management tool, avoiding the need for the Redux framework to use a large number of repeated behavior encapsulation creators Action Creator and template codes corresponding to the store.dispatch(Action) method tool to avoid logic errors.
[0118] S803: Calling the target management tool to process the target state behavior according to the target context component to determine the new state of the target view element.
[0119] In this step, the target context component passes intermediate parameters such as global variables to the target management tool for processing the state change corresponding to the target state behavior, so that the target management tool finally generates a new state.
[0120] S804: Update and configure a new state for the target view component through the state giver.
[0121] After the new state is generated, the state management library is equivalent to the original Store, which updates the new state to the target view element through the corresponding state giver, which is a function tool for resetting or updating view elements, such as the render method tool, so that the target view element displays the new state.
[0122] Optionally, various management tools related to the state of the target view component also synchronously update this state, or replace the initial state in the state management library with a new state.
[0123] In a possible design, in order to enable the state giver to meet the preparation requirements for configuring a new state, before step S808, the following is further included:
[0124] Gets the function selector used to configure the parameters in the state giver and / or the target configuration model to be called.
[0125] Configure the state giver according to the function selector so that the state giver meets the new state configuration requirements of the target view element.
[0126] The view component state management method provided by the embodiment of the present disclosure first obtains the target state behavior of the target view component, then determines the target management tool in the state management library through the target pointer of the hook interface component according to the target state behavior, and then calls the target management tool according to the target pointer to process the target state behavior to determine the new state of the target view component. Figure 5 On the basis of the illustrated embodiment, a pointer is used to quickly locate the target management tool, and a context context provider and a context context component are added to the state management library to provide a simpler multiplexing interface tool for calling the management tool. The state management library of the disclosed embodiment combines the state behavior with the logical processor that processes the state behavior to form a management tool. When processing the state behavior, the management tool is directly instantiated to complete the state update. There is no need to transfer the state behavior through multiple transfer modules as in the prior art, which solves the technical problems of the state management framework in the prior art, such as too much template code, weak type support, and complex interface definition. The technical effect of simplifying the state management framework, greatly reducing the template code, and applying the TypeScript type system is achieved.
[0127] Corresponding to the media push method in the above embodiment, Fig.10 The structure block diagram of the view component state management device provided by the embodiment of the present disclosure. For the convenience of explanation, only the part related to the embodiment of the present disclosure is shown. Fig.10 , the device comprises:
[0128] An acquisition module 1001 is used to acquire a target state behavior of a target view element, where the target state behavior is used to determine a change type of a state, where the state is a logical state of the target view element;
[0129] A state management library module 1002, used to determine a target management tool according to the target state behavior, wherein the state management library module includes a plurality of management tools, and the management tool includes a logic processor, and the logic processor is used to process the logical relationship between the state and state behavior of the view element in the management tool;
[0130] The processing module 1003 is used to call the target management tool to process the target state behavior to determine the new state of the target view element.
[0131] In one embodiment of the present disclosure, the parameters in the management tool and the logical processor define parameter types, and the parameter types include: at least one of a value, an array, a text, and a function;
[0132] The parameter type is used to enable correct calling when calling the target management tool to process the target status behavior.
[0133] In one embodiment of the present disclosure, the state management library module 1002 further includes: a logical processor set, a state behavior set, an initial state set, and a management tool set;
[0134] The set of logical processors includes the logical processors in each of the management tools;
[0135] The state behavior set includes the state behaviors in each of the management tools;
[0136] The initial state set includes the initial state of each of the state behaviors;
[0137] The management tool set includes all the management tools.
[0138] In one embodiment of the present disclosure, the state management library module 1002 is used to determine the target management tool according to the target state behavior, including:
[0139] The state management library module 1002 is used to determine at least one of the target management tools in the state management library through the target pointer of the hook interface component according to the target state behavior;
[0140] The hook interface component includes pointers corresponding to each of the management tools.
[0141] In one embodiment of the present disclosure, the processing module 1003 is used to call the target management tool to process the target state behavior, including:
[0142] The processing module 1003 is used to call the target management tool to process the target state behavior according to the target pointer.
[0143] In one embodiment of the present disclosure, the target state behavior includes: the current state of the target behavior object and the target logical behavior. The acquisition module 1001, which is used to acquire the target state behavior of the target view element, includes:
[0144] The acquisition module 1001 is used to acquire the current state and the target logical behavior through the hook interface component;
[0145] Correspondingly, the state management library module 1002 is used to determine the target management tool according to the target state behavior, including:
[0146] The state management library module 1002 is used to use the hook interface component to determine the target pointer corresponding to the target management tool according to the target logical behavior, and the target pointer is included in the hook interface component;
[0147] The state management library module 1002 is further used to determine the target management tool according to the target pointer and the state management library.
[0148] In one embodiment of the present disclosure, when the new state corresponding to the target state behavior is a state shared by multiple view elements, the state management library module 1002 is used to determine the target pointer corresponding to the target management tool according to the target logical behavior, including:
[0149] The state management library module 1002 is used to obtain the context provider of the target pointer according to the target logical behavior;
[0150] The state management library module 1002 is further used to determine the target pointer according to the context provider.
[0151] In one embodiment of the present disclosure, the context provider is used to provide a connection interface between the state management library and the context component, and the processing module 1003 is used to determine the target pointer according to the context provider, including:
[0152] The processing module 1003 is used to obtain the context component encapsulated by the context provider;
[0153] The processing module 1003 is further configured to determine the target pointer according to the context component.
[0154] In one embodiment of the present disclosure, the processing module 1003 is used to call the target management tool to process the target state behavior to determine the new state of the target view element, including:
[0155] The processing module 1003 is used to call the target management tool to process the target state behavior according to the target context component to determine the new state of the target view element.
[0156] In one embodiment of the present disclosure, the view component state management device 1000 further includes:
[0157] The processing module 1003 is further used to update and configure the new state for the target view element through a state giver.
[0158] In one embodiment of the present disclosure, before the processing module 1003 is further configured to update the target view element with the new state through the state giver, it also includes:
[0159] The acquisition module 1001 is further used to acquire a function selector for configuring each parameter in the state giver and / or a called target configuration model;
[0160] The processing module 1003 is further used to configure the state giver according to the function selector so that the state giver meets the new state configuration requirement of the target view element.
[0161] The device 1000 provided in this embodiment can be used to execute the steps related to the user end in the technical solution of the above method embodiment. Its implementation principle and technical effects are similar and will not be repeated in this embodiment.
[0162] refer to Fig.11 , which shows a schematic diagram of the structure of an electronic device 1100 suitable for implementing the embodiment of the present disclosure, and the electronic device 1100 may be a terminal device or a server. The terminal device may include but is not limited to mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, personal digital assistants (PDAs), tablet computers (Portable Android Devices, PADs), portable multimedia players (PMPs), vehicle terminals (such as vehicle navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Fig.11The electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.
[0163] like Fig.11 As shown, the electronic device 1100 may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 1101, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 1102 or a program loaded from a storage device 1108 to a random access memory (RAM) 1103. Various programs and data required for the operation of the electronic device 1100 are also stored in the RAM 1103. The processing device 1101, the ROM 1102, and the RAM 1103 are connected to each other via a bus 1104. An input / output (I / O) interface 1105 is also connected to the bus 1104.
[0164] Typically, the following devices may be connected to the I / O interface 1105: input devices 1106 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; output devices 1107 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; storage devices 1108 including, for example, a magnetic tape, a hard disk, etc.; and communication devices 1109. The communication devices 1109 may allow the electronic device 1100 to communicate with other devices wirelessly or by wire to exchange data. Although Fig.11 The electronic device 1100 is shown with various devices, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead.
[0165] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program contains program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication device 1109, or installed from the storage device 1108, or installed from the ROM 1102. When the computer program is executed by the processing device 1101, the above-mentioned functions defined in the method of the embodiment of the present disclosure are executed.
[0166] It should be noted that the computer-readable medium disclosed above may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program that may be used by or in combination with an instruction execution system, device or device. In the present disclosure, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, in which a computer-readable program code is carried. This propagated data signal may take a variety of forms, including but not limited to an electromagnetic signal, an optical signal, or any suitable combination of the above. The computer readable signal medium may also be any computer readable medium other than a computer readable storage medium, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer readable medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.
[0167] The computer-readable medium may be included in the electronic device, or may exist independently without being incorporated into the electronic device.
[0168] The computer-readable medium carries one or more programs. When the one or more programs are executed by the electronic device, the electronic device executes the method shown in the above embodiment.
[0169] Computer program code for performing the operations of the present disclosure may be written in one or more programming languages or a combination thereof, including object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as an independent software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0170] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some implementations as replacements, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0171] The units involved in the embodiments described in the present disclosure may be implemented by software or hardware. The name of a unit does not limit the unit itself in some cases. For example, the first acquisition unit may also be described as a "unit for acquiring at least two Internet Protocol addresses".
[0172] The functions described above herein may be performed at least in part by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), and the like.
[0173] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0174] A computer program product is also provided in an embodiment of the present disclosure, including a computer program, which implements the methods in the above embodiments when executed by a processor.
[0175] In a first aspect, according to one or more embodiments of the present disclosure, a view component state management method is provided, including:
[0176] Obtaining a target state behavior of a target view element, wherein the target state behavior is used to determine a change type of a state, wherein the state is a logical state of the target view element;
[0177] In a state management library, a target management tool is determined according to the target state behavior, wherein the state management library includes a plurality of management tools, and the management tool includes a logic processor, and the logic processor is used to process the logical relationship between the state of the view element and the state behavior in the management tool;
[0178] The target management tool is called to process the target state behavior to determine a new state of the target view element.
[0179] According to one or more embodiments of the present disclosure, the parameters in the management tool and the logical processor define parameter types, and the parameter types include: at least one of a value, an array, a text, and a function;
[0180] The parameter type is used to enable correct calling when calling the target management tool to process the target status behavior.
[0181] According to one or more embodiments of the present disclosure, the state management library further includes: a logical processor set, a state behavior set, an initial state set, and a management tool set;
[0182] The set of logical processors includes the logical processors in each of the management tools;
[0183] The state behavior set includes the state behaviors in each of the management tools;
[0184] The initial state set includes the initial state of each of the state behaviors;
[0185] The management tool set includes all the management tools.
[0186] According to one or more embodiments of the present disclosure, determining the target management tool in the state management library according to the target state behavior includes:
[0187] According to the target state behavior, determining the target management tool in the state management library through the target pointer of the hook interface component;
[0188] The hook interface component includes a pointer corresponding to the management tool.
[0189] According to one or more embodiments of the present disclosure, calling the target management tool to process the target state behavior includes:
[0190] The target management tool is called according to the target pointer to process the target state behavior.
[0191] According to one or more embodiments of the present disclosure, the target state behavior includes: the current state of the target behavior object and the target logical behavior, and the target state behavior of obtaining the target view element includes:
[0192] Obtain the current state and the target logical behavior through the hook interface component;
[0193] Correspondingly, in the state management library, determining the target management tool according to the target state behavior includes:
[0194] Using the hook interface component, determining a target pointer corresponding to the target management tool according to the target logical behavior, the target pointer being included in the hook interface component;
[0195] The target management tool is determined according to the target pointer and the state management library.
[0196] According to one or more embodiments of the present disclosure, when the new state corresponding to the target state behavior is a state shared by multiple view elements, determining the target pointer corresponding to the target management tool according to the target logical behavior includes:
[0197] Acquire a context provider of the target pointer according to the target logical behavior;
[0198] The target pointer is determined according to the context provider.
[0199] According to one or more embodiments of the present disclosure, the context provider is used to provide a connection interface between the state management library and the context component, and determining the target pointer according to the context provider includes:
[0200] Obtain the context component encapsulated by the context provider;
[0201] The target pointer is determined according to the context component.
[0202] According to one or more embodiments of the present disclosure, calling the target management tool to process the target state behavior to determine a new state of the target view element includes:
[0203] The target management tool is called according to the target context component to process the target state behavior to determine a new state of the target view element.
[0204] According to one or more embodiments of the present disclosure, the method further includes:
[0205] The new state is updated and configured to the target view element through the state giver.
[0206] According to one or more embodiments of the present disclosure, before updating and configuring the new state of the target view element through the state giver, the method further includes:
[0207] Obtaining a function selector for configuring each parameter in the state giver and / or a called target configuration model;
[0208] The state giver is configured according to the function selector so that the state giver satisfies the new state configuration requirement of the target view element.
[0209] In a second aspect, according to one or more embodiments of the present disclosure, a view element state management device is provided, including:
[0210] An acquisition module, used for acquiring a target state behavior of a target view element, wherein the target state behavior is used for determining a change type of a state, wherein the state is a logical state of the target view element;
[0211] A state management library module, used for determining a target management tool according to the target state behavior, wherein the state management library module includes a plurality of management tools, and the management tools include a logic processor, and the logic processor is used for processing the logical relationship between the state and state behavior of the view element in the management tool;
[0212] A processing module is used to call the target management tool to process the target state behavior to determine a new state of the target view element.
[0213] According to one or more embodiments of the present disclosure, the parameters in the management tool and the logical processor define parameter types, and the parameter types include: at least one of a value, an array, a text, and a function;
[0214] The parameter type is used to enable correct calling when calling the target management tool to process the target status behavior.
[0215] According to one or more embodiments of the present disclosure, the state management library module further includes: a logical processor set, a state behavior set, an initial state set, and a management tool set;
[0216] The set of logical processors includes the logical processors in each of the management tools;
[0217] The state behavior set includes the state behaviors in each of the management tools;
[0218] The initial state set includes the initial state of each of the state behaviors;
[0219] The management tool set includes all the management tools.
[0220] According to one or more embodiments of the present disclosure, the state management library module is used to determine the target management tool according to the target state behavior, including:
[0221] The state management library module is used to determine at least one of the target management tools in the state management library through the target pointer of the hook interface component according to the target state behavior;
[0222] The hook interface component includes pointers corresponding to each of the management tools.
[0223] According to one or more embodiments of the present disclosure, the processing module is used to call the target management tool to process the target state behavior, including:
[0224] The processing module is used to call the target management tool to process the target state behavior according to the target pointer.
[0225] According to one or more embodiments of the present disclosure, the target state behavior includes: the current state of the target behavior object and the target logical behavior, and the acquisition module, used to acquire the target state behavior of the target view element, includes:
[0226] The acquisition module is used to acquire the current state and the target logical behavior through the hook interface component;
[0227] Correspondingly, the state management library module is used to determine the target management tool according to the target state behavior, including:
[0228] The state management library module is used to determine the target pointer corresponding to the target management tool according to the target logical behavior by using the hook interface component, and the target pointer is included in the hook interface component;
[0229] The state management library module is further used to determine the target management tool according to the target pointer and the state management library.
[0230] According to one or more embodiments of the present disclosure, when the new state corresponding to the target state behavior is a state shared by multiple view elements, the state management library module is used to determine the target pointer corresponding to the target management tool according to the target logical behavior, including:
[0231] The state management library module is used to obtain the context provider of the target pointer according to the target logical behavior;
[0232] The state management library module is also used to determine the target pointer according to the context provider.
[0233] According to one or more embodiments of the present disclosure, the context provider is used to provide a connection interface between the state management library and the context component, and in the processing module, determining the target pointer according to the context provider includes:
[0234] The processing module is used to obtain the context component encapsulated by the context provider;
[0235] The processing module is further used to determine the target pointer according to the context component.
[0236] According to one or more embodiments of the present disclosure, the processing module is used to call the target management tool to process the target state behavior to determine the new state of the target view element, including:
[0237] The processing module is used to call the target management tool to process the target state behavior according to the target context component to determine the new state of the target view element.
[0238] According to one or more embodiments of the present disclosure, the view element state management device further includes:
[0239] The processing module is further used to update and configure the new state for the target view element through a state giver.
[0240] According to one or more embodiments of the present disclosure, before the processing module is further configured to update the target view element with the new state through the state giver, it also includes:
[0241] The acquisition module is further used to acquire a function selector for configuring each parameter in the state giver and / or a called target configuration model;
[0242] The processing module is further used to configure the state giver according to the function selector so that the state giver meets the new state configuration requirements of the target view element.
[0243] In a third aspect, according to one or more embodiments of the present disclosure, there is provided an electronic device, including:
[0244] at least one processor and memory;
[0245] The memory stores computer-executable instructions;
[0246] The at least one processor executes the computer-executable instructions stored in the memory, so that the at least one processor executes the view component state management method as described in the first aspect and various possible designs of the first aspect.
[0247] In a fourth aspect, according to one or more embodiments of the present disclosure, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer execution instructions. When a processor executes the computer execution instructions, the view element state management method described in the first aspect and various possible designs of the first aspect is implemented.
[0248] In a fifth aspect, according to one or more embodiments of the present disclosure, a computer program is provided, including a computer program, which, when executed by a processor, implements the view element state management method described in various possible designs of the first aspect above.
[0249] The above description is only a preferred embodiment of the present disclosure and an explanation of the technical principles used. Those skilled in the art should understand that the scope of disclosure involved in the present disclosure is not limited to the technical solutions formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above disclosed concept. For example, the above features are replaced with the technical features with similar functions disclosed in the present disclosure (but not limited to) by each other to form a technical solution.
[0250] In addition, although each operation is described in a specific order, this should not be understood as requiring these operations to be performed in the specific order shown or in a sequential order. Under certain circumstances, multitasking and parallel processing may be advantageous. Similarly, although some specific implementation details are included in the above discussion, these should not be interpreted as limiting the scope of the present disclosure. Some features described in the context of a separate embodiment can also be implemented in a single embodiment in combination. On the contrary, the various features described in the context of a single embodiment can also be implemented in multiple embodiments individually or in any suitable sub-combination mode.
[0251] Although the subject matter has been described in language specific to structural features and / or methodological logical actions, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. On the contrary, the specific features and actions described above are merely example forms of implementing the claims.
Claims
1. A method for managing the state of a view component, characterized in that: include: Acquire a target state behavior of a target view element, where the target state behavior is used to determine a change type of a state, where the state is a logical state of the target view element, and the target state behavior includes a target logical behavior; In the state management library, according to the target logical behavior in the target state behavior, a target pointer corresponding to the target management tool is determined, and according to the target pointer, the target management tool is determined, the state management library includes a plurality of management tools, the management tool includes a logic processor, the logic processor is used to process the logical relationship between the state of the view element and the state behavior in the management tool, the parameters in the management tool and the logic processor define parameter types, and the parameter types are used to correctly call the target management tool when it is called to process the target state behavior; The target management tool is called to process the target state behavior to determine a new state of the target view element.
2. The method for managing the state of a view component according to claim 1, characterized in that: The parameter type includes at least one of: a value, an array, a text, and a function.
3. The view component state management method according to claim 1 or 2, characterized in that: The state management library also includes: a logical processor set, a state behavior set, an initial state set, and a management tool set; The set of logical processors includes the logical processors in each of the management tools; The state behavior set includes the state behaviors in each of the management tools; The initial state set includes the initial state of each of the state behaviors; The management tool set includes all the management tools.
4. The method for managing the state of a view component according to claim 3, characterized in that: Determining the target management tool in the state management library according to the target state behavior includes: According to the target state behavior, determining the target management tool in the state management library through the target pointer of the hook interface component; The hook interface component includes a pointer corresponding to the management tool.
5. The method for managing the state of a view component according to claim 4, characterized in that: The calling of the target management tool to process the target state behavior includes: The target management tool is called according to the target pointer to process the target state behavior.
6. The method for managing the state of a view component according to claim 1, characterized in that: The target state behavior further includes: the current state of the target behavior object, and the target state behavior of obtaining the target view element includes: Obtain the current state and the target logical behavior through the hook interface component; Correspondingly, in the state management library, according to the target logical behavior in the target state behavior, determining the target pointer corresponding to the target management tool includes: The hook interface component is used to determine the target pointer corresponding to the target management tool according to the target logical behavior, and the target pointer is included in the hook interface component.
7. The method for managing the state of a view component according to claim 6, characterized in that: When the new state corresponding to the target state behavior is a state shared by multiple view components, the using the hook interface component to determine the target pointer corresponding to the target management tool according to the target logical behavior includes: Acquire a context provider of the target pointer according to the target logical behavior; The target pointer is determined according to the context provider.
8. The method for managing the state of a view component according to claim 7, characterized in that: The context provider is used to provide a connection interface between the state management library and the context component, and the determining the target pointer according to the context provider includes: Obtain the context component encapsulated by the context provider; The target pointer is determined according to the context component.
9. The method for managing the state of a view component according to claim 8, characterized in that: The calling of the target management tool to process the target state behavior to determine a new state of the target view element includes: The target management tool is called according to the target context component to process the target state behavior to determine a new state of the target view element.
10. The view component state management method according to any one of claims 1, 6-9, characterized in that: The method further comprises: The new state is updated and configured to the target view element through the state giver.
11. The method for managing the state of a view component according to claim 10, characterized in that: Before updating and configuring the new state of the target view element through the state giver, the method further includes: Obtaining a function selector for configuring each parameter in the state giver and / or a called target configuration model; The state giver is configured according to the function selector so that the state giver satisfies the new state configuration requirement of the target view element.
12. A view component state management device, characterized in that: include: An acquisition module, used for acquiring a target state behavior of a target view element, wherein the target state behavior is used for determining a change type of a state, wherein the state is a logical state of the target view element, and the target state behavior includes a target logical behavior; A state management library module, used to determine a target pointer corresponding to a target management tool according to a target logical behavior in the target state behavior, and to determine the target management tool according to the target pointer. The state management library module includes a plurality of management tools, and the management tool includes a logic processor, and the logic processor is used to process the logical relationship between the state of a view element in the management tool and the state behavior. The parameters in the management tool and the logic processor define parameter types, and the parameter types are used to enable correct calling when the target management tool is called to process the target state behavior. A processing module is used to call the target management tool to process the target state behavior to determine a new state of the target view element.
13. An electronic device, characterized in that: include: at least one processor and memory; The memory stores computer-executable instructions; The at least one processor executes the computer program stored in the memory, so that the at least one processor performs the view component state management method according to any one of claims 1 to 11.
14. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, and when the processor executes the computer-executable instructions, the view component state management method according to any one of claims 1 to 11 is implemented.
15. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the method for managing the state of a view component according to any one of claims 1 to 11 is implemented.
Citation Information
Patent Citations
Front-end data flow control component development system, method and device and storage medium
CN109597611A
