CN113709171B - Method and device for cross-component state communication - Google Patents

Method and device for cross-component state communication Download PDF

Info

Publication number
CN113709171B
CN113709171B CN202111020808.2A CN202111020808A CN113709171B CN 113709171 B CN113709171 B CN 113709171B CN 202111020808 A CN202111020808 A CN 202111020808A CN 113709171 B CN113709171 B CN 113709171B
Authority
CN
China
Prior art keywords
state
function
interface
interface function
parameter
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202111020808.2A
Other languages
Chinese (zh)
Other versions
CN113709171A (en
Inventor
石笑笑
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Jingdong Century Trading Co Ltd
Beijing Wodong Tianjun Information Technology Co Ltd
Original Assignee
Beijing Jingdong Century Trading Co Ltd
Beijing Wodong Tianjun Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Jingdong Century Trading Co Ltd, Beijing Wodong Tianjun Information Technology Co Ltd filed Critical Beijing Jingdong Century Trading Co Ltd
Priority to CN202111020808.2A priority Critical patent/CN113709171B/en
Publication of CN113709171A publication Critical patent/CN113709171A/en
Application granted granted Critical
Publication of CN113709171B publication Critical patent/CN113709171B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/06Notations for structuring of protocol data, e.g. abstract syntax notation one [ASN.1]
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/448Execution paradigms, e.g. implementations of programming paradigms
    • G06F9/4488Object-oriented
    • G06F9/449Object-oriented method invocation or resolution
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computer Security & Cryptography (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Stored Programmes (AREA)
  • Computer And Data Communications (AREA)

Abstract

The invention discloses a method and a device for cross-component state communication, and relates to the technical field of computers. One embodiment of the method comprises the following steps: importing a plurality of interface functions in a third party state management library file; respectively carrying out encapsulation treatment on the plurality of interface functions to obtain a plurality of encapsulated interface functions; and packaging the plurality of packaged interface functions to obtain a unified state management interface function so as to realize cross-component state communication based on the unified state management interface function. Compared with the embodiment, the method and the device for realizing the cross-component state communication by directly using the existing state management library can reduce the realization difficulty and improve the efficiency of programmers in realizing the cross-component state communication.

Description

Method and device for cross-component state communication
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a method and apparatus for cross-component status communication.
Background
Cross-component state communication is the communication of a parent component to a child component in the front-end development of a computer program, delivering a data structure called a state. The existing cross-component state communication methods are mainly three: defining the state in the parent component and downloading the state layer by layer; communicating a state using a context interface; and communicating using a large state manager.
In the process of implementing the present invention, the inventor finds that at least the following problems exist in the prior art:
the existing cross-component state communication methods are realized based on direct use of the existing state management library, the use method of the existing state management library is complex, and the difficulty and the efficiency of realizing the cross-component state communication are high.
Disclosure of Invention
In view of the above, the embodiments of the present invention provide a method and an apparatus for cross-component state communication, which can reduce difficulty in implementing cross-component state communication and improve efficiency of programmers implementing cross-component state communication compared with the prior art.
To achieve the above object, according to one aspect of an embodiment of the present invention, there is provided a method for cross-component state communication, including:
importing a plurality of interface functions in a third party state management library file;
respectively carrying out encapsulation treatment on the plurality of interface functions to obtain a plurality of encapsulated interface functions;
and packaging the plurality of packaged interface functions to obtain a unified state management interface function so as to realize cross-component state communication based on the unified state management interface function.
Optionally, the plurality of interface functions includes:
A minimum state unit function for creating a base state; a state derivation function for creating a derived state; the state usage function is used to obtain or modify the state.
Optionally, the minimum state unit function is a minimum state unit function that does not support the incoming parameter, and the state derived function is a state derived function that does not support the incoming parameter.
Optionally, the minimum state unit function is a minimum state unit function supporting an incoming parameter, and the state derived function is a state derived function supporting an incoming parameter.
Optionally, the performing packaging processing on the plurality of interface functions to obtain a plurality of packaged interface functions includes:
defining a first interface function, and encapsulating logic for calling a minimum state unit function in a function body of the first interface function;
defining a second interface function, and encapsulating logic for calling a state derivative function in a function body of the second interface function;
defining a third interface function and encapsulating the logic of the call state usage function within the function body of the third interface function.
Optionally, the encapsulating the plurality of encapsulated interface functions to obtain a unified state management interface function includes:
And defining a unified state management interface function, and encapsulating logic for calling the first interface function, the second interface function and the third interface function in a function body of the state management interface function.
Optionally, the state management interface function supports first to third incoming parameters;
the logic for encapsulating and calling the first interface function, the second interface function and the third interface function in the function body of the state management interface function comprises the following steps:
encapsulating parameter transfer logic within a function body of the state management interface function, comprising: under the condition that the first afferent parameter exists, assigning the first afferent parameter to a state initial value needed by calling the first interface function or the second interface function for afferent parameter; under the condition that the third afferent parameter exists, assigning the third afferent parameter to a state unique identification afferent parameter required by calling the first interface function or the second interface function; when the type of the second afferent parameter is a function, the second afferent parameter is assigned to the state modification afferent parameter required by calling the second interface function; when the type of the second incoming parameter is a character string, the second incoming parameter is endowed with a unique identification of the state required by calling the first interface function or the second interface function;
And encapsulating interface function call logic according to the input parameters in the function body of the state management interface function, comprising: and calling the second interface function and the third interface function when the state modification entry exists, and calling the first interface function and the third interface function when the state modification entry does not exist.
To achieve the above object, according to another aspect of an embodiment of the present invention, there is provided an apparatus for cross-component status communication, including:
the importing module is used for importing a plurality of interface functions in the third party state management library file;
the first encapsulation module is used for respectively encapsulating the plurality of interface functions to obtain a plurality of encapsulated interface functions;
and the second encapsulation module is used for encapsulating the plurality of encapsulated interface functions to obtain a unified state management interface function so as to realize cross-component state communication based on the unified state management interface function.
To achieve the above object, according to still another aspect of the embodiments of the present invention, there is provided an electronic device for cross-component status communication, including:
one or more processors;
storage means for storing one or more programs,
The one or more programs, when executed by the one or more processors, cause the one or more processors to implement any of the methods for cross-component state communication described above.
To achieve the above object, according to still another aspect of the embodiments of the present invention, there is provided a computer-readable medium having stored thereon a computer program which, when executed by a processor, implements a method for cross-component state communication as described in any of the above.
One embodiment of the above invention has the following advantages or benefits: the method comprises the steps of importing a plurality of interface functions in a third party state management library file, respectively carrying out encapsulation processing on the plurality of interface functions to obtain a plurality of encapsulated interface functions, and then carrying out encapsulation processing on the plurality of encapsulated interface functions to obtain a unified state management interface function so as to realize the steps of cross-component state communication based on the unified state management interface function, thereby overcoming the problems of high difficulty and low efficiency when the cross-component state communication is realized in the prior art, further obtaining the effects of reducing the realization difficulty and improving the efficiency of realizing the cross-component state communication.
Further effects of the above-described non-conventional alternatives are described below in connection with the embodiments.
Drawings
FIG. 1 is a main flow diagram of a method for cross-component status communication according to a first embodiment of the present invention;
FIG. 2 is a flow diagram of a method for cross-component status communication according to a second embodiment of the present invention;
FIG. 3 is a schematic diagram of the main modules of an apparatus for cross-component status communication according to a third embodiment of the present invention;
FIG. 4 is an exemplary system architecture diagram in which embodiments of the present invention may be applied;
fig. 5 is a schematic diagram of a computer system suitable for use in implementing a mobile device or server of an embodiment of the invention.
Detailed Description
Exemplary embodiments of the present invention will now be described with reference to the accompanying drawings, in which various details of the embodiments of the present invention are included to facilitate understanding, and are to be considered merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
It should be noted that, the embodiments of the present invention and the technical features of the embodiments may be combined with each other without affecting the implementation of the present invention.
Before describing embodiments of the present invention in detail, some technical terms related to the embodiments of the present invention will be described in detail.
Reaction: and the JavaScript library is used for constructing the user interface.
Recording: the state management library of the reaction.
atom, selector, useRecoilCallback, atomFamily, selectorFamily: basic APIs (interface functions) belonging to Recoil.
First embodiment
Referring to fig. 1, a main flow of a method for cross-component status communication according to a first embodiment of the present invention is shown, including the following steps:
s101: importing a plurality of interface functions in a third party state management library file;
s102: respectively carrying out encapsulation treatment on the plurality of interface functions to obtain a plurality of encapsulated interface functions;
s103: and packaging the plurality of packaged interface functions to obtain a unified state management interface function so as to realize cross-component state communication based on the unified state management interface function.
In step S101, a js file may be created under the specified folder in the project, and a required interface function (API) is imported from the third party state management library file in the created js file.
In one exemplary scenario, cross-component state communication is conducted in a project developed based on the exact framework. In order to solve the complexity problem of the cross-component transfer state, the burden of a developer is further reduced, a new generation of state management library file Recoil is built in the clip, but in the use process of the Recoil, the steps are slightly complicated, and the Recoil is relatively complex. In view of this, some interface functions (APIs) in the third party state management library file record may be encapsulated by the flow shown in fig. 1 to obtain a unified state management interface function, so as to simplify the process of transferring state communication across components.
In an alternative implementation manner of the above alternative example, for step S101, the plurality of interface functions imported from record include: atom, selector, useRecoilValue and useRecoilCallback.
In another optional implementation manner of the above optional example, for step S101, the plurality of interface functions imported from record include: atomFamily and selectorFamily, selector, useRecoilValue, useRecoolCallback.
Where atom and atom family are minimum state unit functions that are used to create a basic state at call time. One atom represents a state that the atom can be subscribed to and updated, at which time all components subscribed to it are re-rendered with new data. In using atoms, parameters key and default are required. Wherein, key (key value) is the unique identification of atom, default is the initial state value of the atom. The distinction between atom and atom family is that the former is the minimum state unit function that does not support the incoming parameters and the latter is the minimum state unit function that supports the incoming parameters.
Wherein selector and selector family are state-derived functions for creating a derived state. The selector is a pure function that is incorporated into the atom or other selector and represents a derived state, which is the output that passes the state to the pure function that uses some way to modify the given state. selector is typically used to calculate some derived data based on the original state. Wherein the difference between selector and selector family is similar to the difference between atom and atom family, selector is a state derived function that does not support an incoming parameter, and selector family is a state derived function that supports an incoming parameter.
Wherein useRecoolValue and useRecoolCallback are state usage functions. Specifically, useRecoolCallback can be used to modify state values, and useRecoolValue can be used to obtain state values. The useReceilValue interface function returns a state value defined by the atom, and if useReceiolValue is used in the React component, the component is subscribed to and re-rendered when the state is updated. The useRecailCallback interface function defines the data that needs to be read in a callback manner, but this data change does not cause the current component to re-render.
In step S102, the plurality of APIs imported from the third party status management library file are respectively encapsulated to obtain a plurality of encapsulated APIs. In an alternative example, when the third party state management library file is record, the plurality of interface functions imported from record include: a minimum state unit function, a state derivation function, and a state use function.
In an alternative embodiment of step S102, the minimum state unit function atom, the state derivation function selector, the state usage function useRecoilValue, and useRecoilCallback imported from the record are respectively encapsulated to obtain a plurality of encapsulated interface functions.
In another alternative embodiment of step S102, the minimum state unit function atom family, the state derivative function selection family, the state usage function useRecoilValue, and useRecoilCallback imported from the record are respectively encapsulated to obtain a plurality of encapsulated interface functions.
In step S103, the plurality of encapsulated interface functions obtained in step S102 are encapsulated to obtain a unified state management interface function. The state management interface function is then exported. When the inter-component state communication is required, the unified state management interface function obtained through packaging in the steps S101 to S103 is imported, and the inter-component state communication can be realized based on the unified state management interface function.
In the embodiment of the invention, the steps are used for packaging a plurality of interface functions in the third-party state management library file required for realizing the cross-component state communication into a unified and concise state management interface, so that the difficulty in realizing the cross-component state communication can be reduced, and the efficiency of the cross-component state communication is improved.
Referring to fig. 2, a flowchart of a method for cross-component status communication according to a second embodiment of the present invention is shown, including the steps of:
s201: and importing a plurality of interface functions in the third party state management library file.
In the embodiment of the invention, the third party state management library file is a record. In step S201, a js file may be created under the specified folder in the project, and a plurality of interface functions (APIs) required for the created js file are imported from the record.
In an alternative embodiment, the plurality of interface functions imported from Recoil include: a minimum state unit function atom, a state derivation function selector, a state usage function useRecoolValue, and useRecoolCallback. In another alternative embodiment, the plurality of interface functions imported from Recoil include: the minimum state unit functions atom family, state derivation functions selector family and selector, state usage functions useRecoolValue and useRecoolCallback.
Where atom and atom family are minimum state unit functions that are used to create a basic state at call time. One atom represents a state that the atom can be subscribed to and updated, at which time all components subscribed to it are re-rendered with new data. In using atoms, parameters key and default are required. Wherein, key (key value) is the unique identification of atom, default is the initial state value of the atom. The distinction between atom and atom family is that the former is the minimum state unit function that does not support the incoming parameters and the latter is the minimum state unit function that supports the incoming parameters. In particular, whether to import the minimum state unit function atom family supporting the incoming parameters or import the minimum state unit function atom not supporting the incoming parameters can be determined according to whether the inter-component transfer is required during the inter-component state communication.
Wherein selector and selector family are state-derived functions for creating a derived state. The selector is a pure function that is incorporated into the atom or other selector and represents a derived state, which is the output that passes the state to the pure function that uses some way to modify the given state. selector is typically used to calculate some derived data based on the original state. Wherein the difference between selector and selector family is similar to the difference between atom and atom family, selector is a state derived function that does not support an incoming parameter, and selector family is a state derived function that supports an incoming parameter.
Wherein useRecoolValue and useRecoolCallback are state usage functions used to obtain or modify a base state or a derived state. The useReceilValue interface function returns a state value defined by the atom, and if useReceiolValue is used in the React component, the component is subscribed to and re-rendered when the state is updated. The useRecailCallback interface function defines the data that needs to be read in a callback manner, but this data change does not cause the current component to re-render.
S202: and carrying out encapsulation processing on the logic of the minimum state unit function in the plurality of interface functions, and defining and obtaining an encapsulated first interface function.
In an alternative embodiment, the plurality of interface functions when imported from Recoil include: in the case of the minimum state unit function atom, the state derivation function selector, the state usage function useRecoilValue, and useRecoilCallback, the step S202 specifically includes: defining an interface function (e.g., a function defined as makeAtomState), the parameters of which are objects that contain a state initial value entry (e.g., representing the entry as an atomNet), a state unique identification entry (e.g., representing the entry as an atomKey), and a state identification entry (e.g., representing the entry as a stateKey); a variable (e.g., a variable defining a name atom State) is defined within the function body of the interface function, logic defining the calling atom, and a return value for the calling atom is received.
In consideration of the fact that a key is required when using an atom (the uniqueness of the identifier atom, a specific atom can be located according to the key) and a state initial value (default), in the defined logic of the calling atom, the incoming state initial value is taken as the default in the atom, the incoming state uniqueness identifier atom key is taken as the key in the atom, and in addition, when the incoming state uniqueness identifier is not taken as the parameter atom key, a default key can be obtained by adding a character string to the incoming state identifier parameter key, so that the fact that the atom key is empty can be guaranteed, and the unique key value can be obtained. Further, in the logic of the defined calling atom, determining the default value in the atom according to the type of the initial value of the state into the reference atom specifically includes: when the initial value of the state is non-functional, taking the value of the atom as the default value in the atom; when the state initial value is added as a function, the state value is obtained by calling a state derivation function selector and using a get method in the selector, and is used as a default value in the atom.
In another alternative embodiment, the plurality of interface functions when imported from Recoil include: step S202 is similar to the previous alternative embodiment when the minimum state unit function, state derived function, select family and selector, state usage functions useRecoolValue and useRecollback are invoked, except that the minimum state unit function, atom family, is invoked, the parameter userProps entered by the component is assigned to the state initial value, atom mGlut, if the state initial value is non-functional, and the userProps attribute is increased when the get method in the state derived function selector is invoked. The userProps attribute transferred between components may be, for example, a version number, an operating system type (such as IOS system or Android system), or other attribute parameters that need to be transferred between components.
S203: and encapsulating logic of the state derivative function in the plurality of interface functions, and defining and obtaining an encapsulated second interface function.
In an alternative embodiment, the plurality of interface functions when imported from Recoil include: when the minimum state unit function atom, the state derivation function selector, the state usage function useRecoilValue, and useRecoilCallback (where useRecoilCallback may be used to modify the state value, useRecoilValue may be used to obtain the state value), step S203 specifically includes: defining an interface function (e.g., a function defined as makeSelectState), the parameters of which are objects that contain a state initial value entry (e.g., representing the entry as an atomNet), a state modification entry (e.g., representing the entry as an atomSet), a state unique identification entry (e.g., representing the entry as an atomKey), and a state identification entry (e.g., representing the entry as a stateKey); a variable (e.g., a variable defining a name of the selector State) is defined within the function body of the interface function, logic defining the calling selector, and a return value calling selector is received.
In the defined logic for calling the selector, the input state unique identifier is used as a key value key, and in addition, when the input state unique identifier is not input into the parameter key, a default key value key is obtained by adding a character string to the input state identifier, so that the unique key value can be ensured even when the parameter key is empty. Further, in the defined logic for calling the selector, if the state initial value is a function, calling a get method in the selector to obtain a state value; otherwise, returning error prompt information, such as 'undefined'; if the state modification is performed by taking the parameter set as a function, calling a set method in the selector to modify the state value; otherwise, an error hint is returned, such as "undefined".
In another alternative embodiment, when the plurality of interface functions imported from the record include the minimum state unit function atom family, the state derivation function select family, and the selector, the state usage functions useRecoolValue, and useRecoolCalback, step S203 is similar to the previous alternative embodiment, except that the state derivation function select family is invoked, and the get method and the set method are invoked by useProps attribute values.
S204: and carrying out encapsulation processing on the logic of the state use function in the plurality of interface functions, and defining and obtaining an encapsulated third interface function.
In an alternative embodiment, the plurality of interface functions when imported from Recoil include: when the minimum state unit function atom, the state derivation function selector, the state usage function useRecoilValue, and useRecoilCallback (where useRecoilCallback may be used to modify the state value, useRecoilValue may be used to obtain the state value), step S204 specifically includes: an interface function (e.g., a function named makeUseState) is defined, a function (e.g., a function named set) is defined in the function body of the interface function, and useRecoolCallback is called to return a tuple containing two return values, one is a state value obtained by calling useRecoolValue method, and the other is a state value modified by calling useRecoolCallback method.
In another alternative embodiment, when the plurality of interface functions imported from the record include the minimum state unit function atom family, the state derivation function select family, and the selector, the state use functions useRecoolValue, and useRecoolCalback, step S204 is similar to the previous alternative embodiment, except that userProps attributes are added to the function body set function, and the imported userProps attributes are used in the useRecoolValue method.
S205: and defining a unified state management interface function, and encapsulating logic for calling the first interface function, the second interface function and the third interface function in a function body of the state management interface function so as to realize cross-component state communication based on the unified state management interface function.
In an alternative embodiment, the plurality of interface functions when imported from Recoil include: when the minimum state unit function atom, the state derivation function selector, the state usage function useRecoilValue, and useRecoilCallback (where useRecoilCallback may be used to modify the state value, useRecoilValue may be used to obtain the state value), step S205 specifically includes:
step a, a unified state interface function (e.g., representing the function as makeState) is defined. The state management interface function supports first through third incoming parameters (e.g., may be denoted as param1, param2, param 3).
Step b, encapsulating parameter transfer logic in a function body of the state management interface function, comprising: assigning the first incoming parameter to a state initial value incoming parameter (e.g., representing the incoming parameter as an atomic) required to call the first interface function or call the second interface function in the presence of the first incoming parameter; assigning the third incoming parameter to a state required to call the first interface function or call the second interface function in the presence of the third incoming parameter to uniquely identify the incoming parameter (e.g., represent the incoming parameter as an atomKey); when the type of the second incoming parameter is a function, assigning the second incoming parameter to a state modification incoming parameter (such as representing the incoming parameter as an atom set) required to call the second interface function; when the type of the second incoming parameter is a string, the second incoming parameter is assigned to a state required to call the first interface function or call the second interface function to uniquely identify the incoming parameter (e.g., the incoming parameter is denoted as an atomKey). In addition, in step b, a variable stateKey (i.e., a state identification parameter) is defined in the function body of the state management interface function, which is generated by calling the defined function. For example, a function with the following functions may be invoked to generate a value of stateKey: the initial value is 0, and every time the call is made, the returned value is added with 1 on the basis of the original value, so that the number is ensured not to be repeated. In particular, the stateKey defined in the function body of the state management interface function is used as a reference of the first interface function or the second interface function according to different calling logic.
And c, packaging interface function call logic according to the input parameters in the function body of the state management interface function, wherein the step comprises the following steps: the second interface function and the third interface function are invoked in the presence of a state modification entry (e.g., denoted as an atom set), and the first interface function and the third interface function are invoked in the absence of a state modification entry. And after the encapsulation is finished, deriving a unified state manager interface function obtained by encapsulation. For example, a function dripState may be defined within the function body of the unified state manager interface function, and the following call logic is defined: if the atom set exists, the dripState value is a return value obtained after the makeSelectState function is called, otherwise, the dripState value is a return value obtained after the makeAtomstate function is called, and finally an array is returned, wherein the array comprises the return value obtained after the dripState is called and the return value obtained after the makeUseState function is called. After the unified state manager interface function makeState is obtained by encapsulation, the state manager interface function file is exported.
In another alternative embodiment, step S205 is similar to the previous alternative embodiment, except that in the returned array, the userProps attribute is entered when the makeUsstate function is called, when the multiple interface functions imported from Recail include the minimum state element functions atom family, the state derivation functions select family and selector, the state usage functions useRecoolValue and useRecollback. In the implementation, whether to import an API supporting the import parameters from the Recoil or import an API not supporting the import parameters from the Recoil can be determined according to whether the inter-component transfer is needed during the inter-component state communication, and then the imported API is encapsulated. In order to facilitate distinguishing the unified state manager interface functions obtained in the two cases, different function names are taken for the unified state manager interface functions. For example, the function name of the state manager interface function obtained by encapsulating an API that does not support the incoming parameters is set to makeState, and the function name of the state manager interface function obtained by encapsulating an API that supports the incoming parameters is set to makeStateFamily. After the encapsulation results in a unified state manager interface function makeStateFamily, the state manager interface function file is exported.
In an alternative embodiment, after the unified state manager interface function is obtained through the process shown in fig. 1 or fig. 2, the process of performing the cross-component state communication based on the state manager interface function includes:
and step 1, importing a packaged state manager interface function file makeState.
And 2, setting a basic state and setting an initial value of the state.
For example: const [ useState ] =makestate (0), indicating that the state default value is set to 0.
Step 3, acquiring or modifying state values in other components
For example: const [ file, setFile ] =usestat (). Wherein file is the acquired state value, which can be modified using setFile () function.
In another alternative embodiment, when some components need to use parameters input into the components as state information, parameter transmission assignment needs to be performed, and encapsulated makeStateFamily needs to be used to implement a cross-component transmission state with parameters, after a unified state manager interface function is obtained through the process shown in fig. 1 or fig. 2, a process of performing cross-component state communication based on the state manager interface function includes:
step 1, importing the packaged makeStatefamily.
Step 2, setting a basic state, and transmitting the component parameter into makeStatefamily.
For example: const [ useState ] = makeStateFamily ((, tips) = > ({ name: tips }). Where tips is the parameter passed by this component.
Step 3, acquiring or modifying the state value
For example: const [ file, setFile ] = useState (props). Where file is the current state value, the state value may be modified using setFile ().
In the embodiment of the invention, the minimum state unit function interface, the state derivation function interface and the state use function interface of the record state management library related to component state transfer are packaged into a unified and concise interface through the steps, so that the difficulty of realizing cross-component state communication can be reduced, and the efficiency of realizing cross-component state communication of programmers is improved.
Referring to fig. 3, a schematic diagram of main modules of an apparatus 300 for cross-component status communication according to a third embodiment of the present invention is shown, including:
an importing module 301, configured to import a plurality of interface functions in the third party status management library file.
And the first encapsulation module 302 is configured to encapsulate the plurality of interface functions respectively, so as to obtain a plurality of encapsulated interface functions.
And the second encapsulation module 303 is configured to encapsulate the plurality of encapsulated interface functions to obtain a unified state management interface function, so as to implement cross-component state communication based on the unified state management interface function.
Optionally, in the apparatus of the present invention, the interface function imported by the importing module 301 includes: a minimum state unit function for creating a base state; importing a state derivative function for creating a derivative state; the import state uses a function for retrieving or modifying the state.
The third party state management library file is illustratively Recoil. In an alternative implementation of this example, the plurality of interface functions imported from Recoil include: a minimum state unit function atom, a state derivation function selector, a state usage function useRecoolValue, and useRecoolCallback. In another alternative embodiment of this example, the plurality of interface functions imported from Recoil include: the minimum state unit functions atom family, state derivation functions selector family and selector, state usage functions useRecoolValue and useRecoolCallback. Wherein useRecoolCallback can be used to modify state values and useRecoolValue can be used to obtain state values.
Optionally, in the embodiment of the present invention, the first encapsulation module 302 is configured to: defining a first interface function, and encapsulating logic for calling a minimum state unit function in a function body of the first interface function; defining a second interface function, and encapsulating logic for calling a state derivative function in a function body of the second interface function; defining a third interface function and encapsulating the logic of the call state usage function within the function body of the third interface function.
Optionally, in the embodiment of the present invention, the second packaging module 303 is configured to: and defining a unified state management interface function, and encapsulating logic for calling the first interface function, the second interface function and the third interface function in a function body of the state management interface function.
Optionally, in the implementation device of the present invention, the state management interface function supports first to third incoming parameters; the logic for encapsulating the call to the first interface function, the second interface function, and the third interface function within the function body of the state management interface function comprises:
encapsulating parameter transfer logic within a function body of the state management interface function, comprising: under the condition that the first afferent parameter exists, assigning the first afferent parameter to a state initial value needed by calling the first interface function or the second interface function for afferent parameter; under the condition that the third afferent parameter exists, assigning the third afferent parameter to a state unique identification afferent parameter required by calling the first interface function or the second interface function; when the type of the second afferent parameter is a function, the second afferent parameter is assigned to the state modification afferent parameter required by calling the second interface function; when the type of the second incoming parameter is a character string, the second incoming parameter is endowed with a unique identification of the state required by calling the first interface function or the second interface function;
And encapsulating interface function call logic according to the input parameters in the function body of the state management interface function, comprising: and calling the second interface function and the third interface function when the state modification entry exists, and calling the first interface function and the third interface function when the state modification entry does not exist.
In the embodiment of the invention, the plurality of complex state management library interfaces related to component state transmission are packaged into a unified and concise interface through the device, so that the difficulty of realizing the cross-component state communication can be reduced, and the efficiency of realizing the cross-component state communication for programmers is improved.
Fig. 4 illustrates an exemplary system architecture 400 in which embodiments of the present invention may be applied.
As shown in fig. 4, the system architecture 400 may include terminal devices 401, 402, 403, a network 404, and a server 405 (by way of example only). The network 404 is used as a medium to provide communication links between the terminal devices 401, 402, 403 and the server 405. The network 404 may include various connection types, such as wired, wireless communication links, or fiber optic cables, among others.
A user may interact with the server 405 via the network 404 using the terminal devices 401, 402, 403 to receive or send messages or the like. Various communication client applications can be installed on the terminal devices 401, 402, 403.
The terminal devices 401, 402, 403 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smartphones, tablets, laptop and desktop computers, and the like.
The server 405 may be a server providing various services, such as a background management server (by way of example only) providing support for shopping-type websites browsed by users using the terminal devices 401, 402, 403.
It should be noted that, the method for cross-component state communication provided by the embodiment of the present invention is generally performed by the terminal device 401 or 402 or 403, and accordingly, the apparatus for cross-component state communication is generally provided in the terminal device 401 or 402 or 403.
It should be understood that the number of terminal devices, networks and servers in fig. 4 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
Referring now to FIG. 5, there is illustrated a schematic diagram of a computer system 500 suitable for use in implementing an embodiment of the present invention. The terminal device shown in fig. 5 is only an example, and should not impose any limitation on the functions and the scope of use of the embodiment of the present invention.
As shown in fig. 5, the computer system 500 includes a Central Processing Unit (CPU) 501, which can perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM) 502 or a program loaded from a storage section 508 into a Random Access Memory (RAM) 503. In the RAM 503, various programs and data required for the operation of the system 500 are also stored. The CPU 501, ROM 502, and RAM 503 are connected to each other through a bus 504. An input/output (I/O) interface 505 is also connected to bus 504.
The following components are connected to the I/O interface 505: an input section 506 including a keyboard, a mouse, and the like; an output portion 507 including a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker, and the like; a storage portion 508 including a hard disk and the like; and a communication section 509 including a network interface card such as a LAN card, a modem, or the like. The communication section 509 performs communication processing via a network such as the internet. The drive 510 is also connected to the I/O interface 505 as needed. A removable medium 511 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 510 as needed so that a computer program read therefrom is mounted into the storage section 508 as needed.
In particular, according to embodiments of the present disclosure, the processes described above with reference to flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method shown in the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network via the communication portion 509, and/or installed from the removable media 511. The above-described functions defined in the system of the present invention are performed when the computer program is executed by a Central Processing Unit (CPU) 501.
The computer readable medium shown in the present invention may be a computer readable signal medium or a computer readable storage medium, or any combination of the two. The computer readable storage medium can be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or a combination of any of the foregoing. More specific examples of the computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, 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 disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the context of this document, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In the present invention, however, the computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, with the computer-readable program code embodied therein. Such a propagated data signal may take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination of the foregoing. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
The flowcharts and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The modules involved in the embodiments of the present invention may be implemented in software or in hardware. The described modules may also be provided in a processor, for example, as: a processor includes an import module, a first encapsulation module, and a second encapsulation module. The names of these modules do not in some way limit the module itself, and for example, the import module may also be described as a "state management library interface import module".
As another aspect, the present invention also provides a computer-readable medium that may be contained in the apparatus described in the above embodiments; or may be present alone without being fitted into the device. The computer readable medium carries one or more programs which, when executed by a device, cause the device to include: importing a plurality of interface functions in a third party state management library file; respectively carrying out encapsulation treatment on the plurality of interface functions to obtain a plurality of encapsulated interface functions; and packaging the plurality of packaged interface functions to obtain a unified state management interface function so as to realize cross-component state communication based on the unified state management interface function.
According to the technical scheme provided by the embodiment of the invention, the method for cross-component state communication realized by the computer program is provided, so that the problems of high difficulty and low realization efficiency of cross-component state communication in the prior art are solved, the realization difficulty of cross-component state communication is further reduced, and the efficiency of the programmer in realizing cross-component state communication is improved.
The above embodiments do not limit the scope of the present invention. It will be apparent to those skilled in the art that various modifications, combinations, sub-combinations and alternatives can occur depending upon design requirements and other factors. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the scope of the present invention.

Claims (9)

1. A method for cross-component state communication, the method comprising:
importing a plurality of interface functions in a third party state management library file;
respectively carrying out encapsulation treatment on the plurality of interface functions to obtain a plurality of encapsulated interface functions; wherein the plurality of interface functions includes: a minimum state unit function for creating a base state; a state derivation function for creating a derived state; a state use function for acquiring or modifying a state;
and packaging the plurality of packaged interface functions to obtain a unified state management interface function so as to realize cross-component state communication based on the unified state management interface function.
2. The method of claim 1, wherein the minimum state unit function is a minimum state unit function that does not support an incoming parameter, and the state derived function is a state derived function that does not support an incoming parameter.
3. The method of claim 1, wherein the minimum state unit function is a minimum state unit function supporting an incoming parameter and the state derived function is a state derived function supporting an incoming parameter.
4. A method according to claim 2 or 3, wherein the encapsulating the plurality of interface functions to obtain a plurality of encapsulated interface functions comprises:
defining a first interface function, and encapsulating logic for calling a minimum state unit function in a function body of the first interface function;
defining a second interface function, and encapsulating logic for calling a state derivative function in a function body of the second interface function;
defining a third interface function and encapsulating the logic of the call state usage function within the function body of the third interface function.
5. The method of claim 4, wherein encapsulating the plurality of encapsulated interface functions to obtain a unified state management interface function comprises:
and defining a unified state management interface function, and encapsulating logic for calling the first interface function, the second interface function and the third interface function in a function body of the state management interface function.
6. The method of claim 5, wherein the state management interface function supports first through third incoming parameters;
the logic for encapsulating and calling the first interface function, the second interface function and the third interface function in the function body of the state management interface function comprises the following steps:
encapsulating parameter transfer logic within a function body of the state management interface function, comprising: under the condition that the first afferent parameter exists, assigning the first afferent parameter to a state initial value needed by calling the first interface function or the second interface function for afferent parameter; under the condition that the third afferent parameter exists, assigning the third afferent parameter to a state unique identification afferent parameter required by calling the first interface function or the second interface function; when the type of the second afferent parameter is a function, the second afferent parameter is assigned to the state modification afferent parameter required by calling the second interface function; when the type of the second incoming parameter is a character string, the second incoming parameter is endowed with a unique identification of the state required by calling the first interface function or the second interface function;
and encapsulating interface function call logic according to the input parameters in the function body of the state management interface function, comprising: and calling the second interface function and the third interface function when the state modification entry exists, and calling the first interface function and the third interface function when the state modification entry does not exist.
7. An apparatus for cross-component state communication, comprising:
the importing module is used for importing a plurality of interface functions in the third party state management library file;
the first encapsulation module is used for respectively encapsulating the plurality of interface functions to obtain a plurality of encapsulated interface functions; wherein the plurality of interface functions includes: a minimum state unit function for creating a base state; a state derivation function for creating a derived state; a state use function for acquiring or modifying a state;
and the second encapsulation module is used for encapsulating the plurality of encapsulated interface functions to obtain a unified state management interface function so as to realize cross-component state communication based on the unified state management interface function.
8. An electronic device, comprising:
one or more processors;
storage means for storing one or more programs,
when executed by the one or more processors, causes the one or more processors to implement the method of any of claims 1-6.
9. A computer readable medium, on which a computer program is stored, characterized in that the program, when being executed by a processor, implements the method according to any of claims 1-6.
CN202111020808.2A 2021-09-01 2021-09-01 Method and device for cross-component state communication Active CN113709171B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111020808.2A CN113709171B (en) 2021-09-01 2021-09-01 Method and device for cross-component state communication

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111020808.2A CN113709171B (en) 2021-09-01 2021-09-01 Method and device for cross-component state communication

Publications (2)

Publication Number Publication Date
CN113709171A CN113709171A (en) 2021-11-26
CN113709171B true CN113709171B (en) 2023-05-30

Family

ID=78658740

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111020808.2A Active CN113709171B (en) 2021-09-01 2021-09-01 Method and device for cross-component state communication

Country Status (1)

Country Link
CN (1) CN113709171B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115242764B (en) * 2022-07-21 2023-10-27 平安科技(深圳)有限公司 Multi-terminal communication method, system, equipment and storage medium for front end

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105183445A (en) * 2015-07-10 2015-12-23 珠海金山网络游戏科技有限公司 Visual design system of artificial intelligence of game on the basis of XML (Extensive Markup Language)
CN106293680A (en) * 2015-06-11 2017-01-04 中兴通讯股份有限公司 A kind of assembly management method and device

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106293680A (en) * 2015-06-11 2017-01-04 中兴通讯股份有限公司 A kind of assembly management method and device
CN105183445A (en) * 2015-07-10 2015-12-23 珠海金山网络游戏科技有限公司 Visual design system of artificial intelligence of game on the basis of XML (Extensive Markup Language)

Non-Patent Citations (5)

* Cited by examiner, † Cited by third party
Title
"Android应用程序的组件间通信行为检测";马川,王涛,祁晓园,王倩,尤殿龙;《小型微型计算机***》;20181231;第39卷(第01期);全文 *
"PeopleSoft Component Interface Frequently Asked Question";无;《https://www.dbtutor.com/2013/06/08/peoplesoft-component-interface-frequently-asked-question》;20130608;全文 *
"基于SAP接口技术的研究与应用";李志超;《中国优秀硕士学位论文全文数据库(电子期刊)信息科技辑》;20130215(第2期);全文 *
"基于SAP的跨组件流程集成与交换技术研究";李鹏;《中国优秀硕士学位论文全文数据库(电子期刊)信息科技辑》;20070615(第6期);全文 *
浅析SAP集成开发技术的应用实践;丁炜;《科技视界》;20180825(第24期);全文 *

Also Published As

Publication number Publication date
CN113709171A (en) 2021-11-26

Similar Documents

Publication Publication Date Title
CN111581555B (en) Document loading method, device, equipment and storage medium
CN110895471A (en) Installation package generation method, device, medium and electronic equipment
CN110928912A (en) Method and device for generating unique identifier
CN111309375B (en) Method, device, medium and electronic equipment for generating remote procedure call toolkit
CN112631590A (en) Component library generation method and device, electronic equipment and computer readable medium
CN110968340A (en) Method and device for realizing multi-version dependence isolation
CN111309304B (en) Method, device, medium and electronic equipment for generating IDL file
CN113709171B (en) Method and device for cross-component state communication
CN113407165B (en) SDK generation and self-upgrade method, device, readable medium and equipment
CN109343970B (en) Application program-based operation method and device, electronic equipment and computer medium
CN112395098A (en) Application program interface calling method and device, storage medium and electronic equipment
CN112214250A (en) Application program assembly loading method and device
CN113127000A (en) Compiling method, device and equipment of application program assembly and storage medium
CN110704050B (en) Module initializing method and device, electronic equipment and computer readable storage medium
CN112416303A (en) Software development kit thermal restoration method and device and electronic equipment
CN109491687B (en) Hot updating method and device of application software, terminal and readable medium
CN108804088B (en) Protocol processing method and device
CN111767498A (en) Method and device for realizing file information sharing
CN113779122B (en) Method and device for exporting data
CN113760487B (en) Service processing method and device
CN113448585B (en) Compiling method and device of thread pool, electronic equipment and storage medium
CN111796865B (en) Byte code file modification method, device, terminal equipment and medium
CN114327404A (en) File processing method and device, electronic equipment and computer readable medium
CN113778566A (en) Native application calling method and device, electronic equipment and computer readable medium
CN109669720B (en) Chain type asynchronous request processing method and device based on Promise and electronic equipment

Legal Events

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