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

Method and device for cross-component state communication Download PDF

Info

Publication number
CN113709171A
CN113709171A CN202111020808.2A CN202111020808A CN113709171A CN 113709171 A CN113709171 A CN 113709171A CN 202111020808 A CN202111020808 A CN 202111020808A CN 113709171 A CN113709171 A CN 113709171A
Authority
CN
China
Prior art keywords
state
function
interface
interface function
calling
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.)
Granted
Application number
CN202111020808.2A
Other languages
Chinese (zh)
Other versions
CN113709171B (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)
  • Computer Security & Cryptography (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (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: importing a plurality of interface functions in a third-party state management library file; respectively encapsulating 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 method for realizing the cross-component state communication by directly using the existing state management library, the method can reduce the realization difficulty and improve the efficiency of realizing the cross-component state communication of programmers.

Description

Method and device for cross-component state communication
Technical Field
The invention relates to the technical field of computers, in particular to a method and a device for cross-component state communication.
Background
Cross-component state communication is where, in the front-end development of a computer program, a parent component communicates to a child component, passing a data structure called state. The existing cross-component state communication method mainly comprises three methods: defining the state in a parent component and downloading layer by layer; transferring state using a context interface; and communicating using a large state manager.
In the process of implementing the invention, the inventor finds that at least the following problems exist in the prior art:
the existing cross-component state communication method is realized by directly using the existing state management library, and the existing state management library is complex in use method, high in difficulty and low in efficiency when cross-component state communication is realized.
Disclosure of Invention
In view of this, 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 a programmer in implementing cross-component state communication, compared with the prior art.
To achieve the above object, according to an aspect of an embodiment of the present invention, there is provided a method for cross-component status communication, including:
importing a plurality of interface functions in a third-party state management library file;
respectively encapsulating 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 include:
a minimum state unit function for creating a base state; a state derivation function for creating a derived state; a state usage function for obtaining or modifying a state.
Optionally, the minimum state unit function is a minimum state unit function that does not support incoming parameters, and the state derivation function is a state derivation function that does not support incoming parameters.
Optionally, the minimum state unit function is a minimum state unit function supporting incoming parameters, and the state derivation function is a state derivation function supporting incoming parameters.
Optionally, the respectively performing encapsulation processing on the plurality of interface functions to obtain a plurality of encapsulated interface functions includes:
defining a first interface function, and packaging a logic for calling a minimum state unit function in a function body of the first interface function;
defining a second interface function, and packaging the logic for calling the state derivative function in the function body of the second interface function;
a third interface function is defined and logic to invoke the state use function is encapsulated within the body of the third interface function.
Optionally, the encapsulating the plurality of encapsulated interface functions to obtain a unified state management interface function includes:
defining a uniform state management interface function, and packaging and calling logic of a first interface function, a second interface function and a third interface function in a function body of the state management interface function.
Optionally, the state management interface function supports a first incoming parameter to a third incoming parameter;
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:
encapsulating parameter passing logic within a function body of the state management interface function, comprising: assigning the first incoming parameter to a state initial value for calling the first interface function or calling the second interface function for entering the parameter under the condition that the first incoming parameter exists; assigning the third incoming parameter to a state unique identifier for calling the first interface function or the second interface function under the condition that the third incoming parameter exists; when the type of the second incoming parameter is a function, the second incoming parameter is given to a state modification entry parameter required by calling a second interface function; when the type of the second incoming parameter is a character string, the second incoming parameter is given to a state unique identifier for calling the first interface function or calling the second interface function;
encapsulating interface function call logic according to incoming parameters within a function body of the state management interface function, comprising: and under the condition that the state modification parameter exists, calling a second interface function and a third interface function, and under the condition that the state modification parameter does not exist, calling a first interface function and a third interface function.
To achieve the above object, according to another aspect of the embodiments of the present invention, there is provided an apparatus for communicating across component states, including:
the import 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 packaging module is used for 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.
To achieve the above object, according to still another aspect of embodiments of the present invention, there is provided an electronic device for communication across component states, including:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement any of the above-described methods for communicating across component states.
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 the method for communicating across component states as described in any one of the above.
One embodiment of the above invention has the following advantages or benefits: the method comprises the steps of respectively encapsulating a plurality of interface functions by importing the plurality of interface functions in a third-party state management library file to obtain a plurality of encapsulated interface functions, and then encapsulating the plurality of encapsulated interface functions to obtain a uniform state management interface function, so that cross-component state communication is realized based on the uniform state management interface function.
Further effects of the above-mentioned non-conventional alternatives will be described below in connection with the embodiments.
Drawings
FIG. 1 is a schematic main flow diagram of a method for communicating across component states in accordance with a first embodiment of the present invention;
FIG. 2 is a flow diagram of a method for communicating across component states in accordance with 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 employed;
FIG. 5 is a schematic block diagram of a computer system suitable for use with a mobile device or server implementing an embodiment of the invention.
Detailed Description
Exemplary embodiments of the present invention are described below with reference to the accompanying drawings, in which various details of embodiments of the invention are included to assist understanding, and which are to be considered as 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 technical features in the embodiments and the embodiments of the present invention 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.
And (5) React: a JavaScript library for building a user interface.
Recoil: and React's state management library.
atom, selector, useRecoilCallback, atomFamily, selectrorFamily: the basic API (interface function) belonging to Recoil.
First embodiment
Referring to fig. 1, a main flow of a method for communicating across component states according to a first embodiment of the present invention is shown, which includes the following steps:
s101: importing a plurality of interface functions in a third-party state management library file;
s102: respectively encapsulating 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 can be newly created under a folder specified in the project, and a necessary interface function (API) can be imported from the third-party status management library file in the newly created js file.
In one exemplary scenario, cross-component state communication is conducted in a project developed based on the React framework. In order to solve the problem of complexity of state transfer across components and further reduce the burden of developers, a new generation state management library file Recoil is built in a Drip, but the step of Recoil is slightly complicated in the using process, and the Recoil is 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, thereby simplifying the process of communicating state across components.
In an optional implementation manner of the above optional example, for step S101, the plurality of interface functions imported from Recoil include: atom, selector, useRecoilValue, and useRecoilCallback.
In another optional implementation of the above optional example, for step S101, the plurality of interface functions imported from recoril include: atom family and selectrfamily, selector, useRecoilValue, and useRecoilCallback.
Where atom and atom family are minimum state unit functions used to create a base state when called. An atom represents a state that can be subscribed to and updated, and at the time of update, all components subscribed to it are re-rendered with new data. When atom is used, the parameters key and default are required. Wherein, key value is the only mark of atom, default is the initial state value of the atom. The distinction between atom and atom family is the minimum state unit function that does not support incoming parameters, the latter being the minimum state unit function that supports incoming parameters.
Wherein the selector and the selectrorfamily are state derivation functions for creating a derived state. A selector is a pure function with an input argument of atom or other selectors, representing a derived state, which is the output that passes the state to a pure function that modifies a given state in some way. The selector is typically used to compute some derived data based on the original state. Wherein the difference between the selector and the selectrolemamiy is similar to the difference between atom and atomfamile, the selector being a state derivative function that does not support incoming parameters, and the selectrolemamiy being a state derivative function that supports incoming parameters.
Wherein, the useRecoilValue and the useRecoilCallback are the state usage functions. Specifically, the useRecoilCallback may be used to modify the state values and the useRecoilValue may be used to obtain the state values. The interface function of the user RecoilValue returns the state value defined by atom, if the user RecoilValue is used in the React component, the component is subscribed, and the component is re-rendered when the state is updated. The interface function of the useRecoilCallback defines the data to be read by means of callback, but the data change does not cause the current component to be re-rendered.
In step S102, a plurality of APIs imported from the third party state 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 a record, the plurality of interface functions imported from the record include: a minimum state cell function, a state derivation function, and a state usage function.
In an optional implementation manner of step S102, the minimum state unit function atom, the state derivation function selector, and the state introduced from the recodel are respectively encapsulated by using the functions useRecoilValue and useRecoilCallback, so as to obtain a plurality of encapsulated interface functions.
In another optional implementation manner of step S102, the minimum state unit function atom family, the state derivation function selectrorfamily, and the state use function use recoilvalue and use recoilcallback, which are imported from the Recoil, are respectively encapsulated to obtain a plurality of encapsulated interface functions.
In step S103, the plurality of packaged interface functions obtained in step S102 are packaged to obtain a unified state management interface function. Thereafter, the state management interface function is exported. When cross-component state communication is required, the unified state management interface function obtained by encapsulation in steps S101 to S103 is imported, that is, cross-component state communication can be realized based on the unified state management interface function.
In the embodiment of the invention, the steps are adopted to realize that a plurality of interface functions in the third-party state management library file required by the realization of the cross-component state communication are packaged into a uniform and simple state management interface, so that the difficulty of realizing the cross-component state communication can be reduced, and the efficiency of the cross-component state communication is improved.
Referring to fig. 2, there is shown a flowchart of a method for communicating across component states according to a second embodiment of the present invention, 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 present invention, the third-party state management library file is record. In step S201, a new js file can be created under a specified folder in the project, and a plurality of required interface functions (APIs) can be imported from the record in the newly created js file.
In an alternative embodiment, the plurality of interface functions imported from Recoil includes: the minimum state cell function atom, the state derivation function selector, the state use function useRecoilValue, and useRecoilCallback. In another alternative embodiment, the plurality of interface functions imported from Recoil includes: the minimum state cell function atom family, the state derivation functions selectrfamile and selector, and the state use functions useRecoilValue and useRecoilCallback.
Where atom and atom family are minimum state unit functions used to create a base state when called. An atom represents a state that can be subscribed to and updated, and at the time of update, all components subscribed to it are re-rendered with new data. When atom is used, the parameters key and default are required. Wherein, key value is the only mark of atom, default is the initial state value of the atom. The distinction between atom and atom family is the minimum state unit function that does not support incoming parameters, the latter being the minimum state unit function that supports incoming parameters. In specific implementation, whether to import the minimum state unit function atom family supporting the incoming parameter or import the minimum state unit function atom not supporting the incoming parameter can be determined according to whether the communication between the components is required to be conducted during the cross-component state communication.
Wherein the selector and the selectrorfamily are state derivation functions for creating a derived state. A selector is a pure function with an input argument of atom or other selectors, representing a derived state, which is the output that passes the state to a pure function that modifies a given state in some way. The selector is typically used to compute some derived data based on the original state. Wherein the difference between the selector and the selectrolemamiy is similar to the difference between atom and atomfamile, the selector being a state derivative function that does not support incoming parameters, and the selectrolemamiy being a state derivative function that supports incoming parameters.
Wherein, the useRecoilValue and the useRecoilCallback are state usage functions for obtaining or modifying the base state or the derivative state. The interface function of the user RecoilValue returns the state value defined by atom, if the user RecoilValue is used in the React component, the component is subscribed, and the component is re-rendered when the state is updated. The interface function of the useRecoilCallback defines the data to be read by means of callback, but the data change does not cause the current component to be re-rendered.
S202: and encapsulating 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 introduced from Recoil includes: when the minimum state cell function atom, the state derivation function selector, and the state use functions useRecoilValue and useRecoilCallback, the step S202 specifically includes: defining an interface function (such as a function named makeAtomState), the parameter of which is an object containing an initial value of state entry (such as representing the entry as atomGet), a state unique identifier entry (such as representing the entry as atomKey), and a state identifier entry (such as representing the entry as stateKey); a variable (such as a variable defining the name atom state) is defined within the body of the interface function, logic to call the atom is defined, and a return value to call the atom is received.
Considering that a key (which identifies the uniqueness of the atom, and can be located to a specific atom according to the key) and a state initial value (default) are required when the atom is used, in the defined logic for calling the atom, the incoming state initial value is entered into the reference atom get as the default in the atom, the incoming state unique identifier atom key is used as the key in the atom, and in addition, when the state is not uniquely identified into the reference atom key, a default key can be obtained by adding a character string to the incoming state identifier participant stateKey, so that the unique key can be ensured when the atom key is empty. Further, in the defined logic for invoking atom, determining the default value in the atom according to the type of the state initial value entered into the atom get specifically includes: when the initial value of the state is entered into the atom Get as a non-function, taking the value of the atom Get as the default value in the atom; when the initial value of the state is taken as the function, the state value is obtained by calling the state derivation function selector and utilizing the get method in the selector as the default value in the atom.
In another alternative embodiment, the plurality of interface functions introduced from Recoil includes: when the minimum state cell function atomFamily, the state derivation function selectramily and selector, and the state use the functions useRecoilValue and useRecoilCallback, step S202 is similar to the previous alternative, except that the minimum state cell function atomFamily is called, if the state initial value input argument is not, the parameter userProps input by the component is assigned to the state initial value input argument, and the userpops attribute is added when the get method in the state derivation function selector is called. Illustratively, the userProps attribute passed between components may be version number, operating system type (such as IOS system or Android system), or other attribute parameters that need to be passed between components.
S203: and packaging the logic of the state derivative function in the plurality of interface functions, and defining and obtaining a packaged second interface function.
In an alternative embodiment, the plurality of interface functions introduced from Recoil includes: when the minimum state cell function atom, the state derivation function selector, and the state use function useRecoilValue and userecoilcalback (where the userecoilcalback may be used to modify the state value, and the useRecoilValue may be used to obtain the state value), step S203 specifically includes: defining an interface function (e.g., defining a function named makeSelectState) whose parameters are an object containing state initial value entries (e.g., representing the entries as atomGet), state modification entries (e.g., representing the entries as atomSet), state unique identification entries (e.g., representing the entries as atomKey), and state identification entries (e.g., representing the entries as stateKey); a variable (e.g., a variable defining the name selectrState) is defined within the body of the interface function, logic is defined to call the selector, and a return value is received to call the selector.
In the defined logic for calling the selector, the transmitted state unique identifier atomKey is used as a key value key, and in addition, when the state unique identifier is not transmitted into the participatory key, a default key value key can be obtained by adding a character string to the transmitted state identifier participatory key, so that the unique key value can be ensured when the atomKey is empty. Further, in the defined logic for calling the selector, if the state initial value is entered into the parameter atomGet as a function, calling a get method in the selector to acquire a state value; otherwise, returning error prompt information, such as 'undefined'; if the state modification is carried out with reference to atomSet as a function, calling a set method in a selector to modify the state value; otherwise, an error prompt message, such as "undefined" is returned.
In another alternative embodiment, when the interface functions imported from the Recoil include a minimum state cell function atom family, a state derivation function selectrorfamily and a selector, and the states use functions useRecoilValue and useRecoilCallback, step S203 is similar to the previous alternative embodiment, except that the state derivation function selectrorfamily is called, and the calling of the get method and the set method is implemented by using the userProps attribute value.
S204: and performing encapsulation processing on the states in the plurality of interface functions by using the logic of the function, and defining and obtaining an encapsulated third interface function.
In an alternative embodiment, the plurality of interface functions introduced from Recoil include: when the minimum state cell function atom, the state derivation function selector, and the state use function useRecoilValue and userecoilcalback (where the userecoilcalback may be used to modify the state value, and the useRecoilValue may be used to obtain the state value), step S204 specifically includes: defining an interface function (such as a function named makeUseState), defining a function (such as a function named set) in a function body of the interface function, calling the useRecoilCallback, and returning a tuple, wherein the tuple comprises two return values, one is a state value obtained by calling a useRecoilValue method, and the other is a state value modified by calling the useRecoilCallback method.
In another alternative embodiment, when the plurality of interface functions imported from the Recoil include a minimum state unit function atom family, a state derivation function selectrorfamily and selector, and a state use function useRecoilValue and useRecoilCallback, step S204 is similar to the previous alternative embodiment, except that a userpeps attribute is added to the set function in the function body, and the incoming userpeps attribute is used in the useRecoilValue method.
S205: defining a unified state management interface function, and packaging and calling logic of a first interface function, a second interface function and a 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 introduced from Recoil include: when the minimum state cell function atom, the state derivation function selector, and the state use function useRecoilValue and userecoilcalback (where the userecoilcalback may be used to modify the state value, and the useRecoilValue may be used to obtain the state value), step S205 specifically includes:
step a, defining a uniform state interface function (such as representing the function as makeState). The state management interface function supports first through third incoming parameters (e.g., which may be denoted as param1, param2, param 3).
Step b, encapsulating parameter transfer logic in the function body of the state management interface function, including: assigning the first incoming parameter to an initial value of a state required for calling the first interface function or the second interface function (for example, representing the initial value as atomGet) when the first incoming parameter exists; assigning the third incoming parameter to a state uniquely identifying the join (e.g., representing the join as atomKey) required to call the first interface function or call the second interface function if the third incoming parameter exists; when the type of the second incoming parameter is a function, assigning the second incoming parameter to a state modification entry (such as representing the entry as atomSet) required for calling the second interface function; when the type of the second incoming parameter is a character string, the second incoming parameter is given to a state unique identification join (such as representing the join as atomKey) required for calling the first interface function or calling the second interface function. Furthermore, in step b, a variable stateKey (i.e., state identification entry) is also defined within the function body of the state management interface function, which is generated by calling the defined function. For example, a function generating stateKey having the following function may be called: the initial value is 0, and each time the call is carried out, the returned value is added with 1 on the basis of the original value, so that the number is not repeated. In specific implementation, the stateKey defined in the function body of the state management interface function is used as the entry of the first interface function or the second interface function according to different calling logics.
Step c, packaging interface function calling logic according to the transmitted parameters in the function body of the state management interface function, comprising: the second interface function and the third interface function are invoked in the presence of a state modification argument (such as representing the argument as atomSet), and the first interface function and the third interface function are invoked in the absence of a state modification argument. And after the encapsulation is finished, exporting the uniform state manager interface function obtained by the encapsulation. For example, a function dripState may be defined within the body of the unified state manager interface function and define the following call logic: if the atomState exists, the driState value is a return value obtained after the makeSelectState function is called, otherwise, the driState 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 driState is called and the return value obtained after the makeUState function is called. And after the uniform state manager interface function makeState is obtained through encapsulation, exporting the state manager interface function file.
In another alternative embodiment, when the interface functions imported from the Recoil include the minimum state unit function atom family, the state derivation function selectrorfamily and selector, and the state use functions useRecoilValue and useRecoilCallback, step S205 is similar to the previous alternative embodiment, except that in the returned array, the userpeps attribute is passed in when the makeUseState function is called. In specific implementation, whether an API supporting incoming parameters is imported from a recodoil or an API not supporting incoming parameters is imported from the recodoil may be determined according to whether the parameters need to be transmitted between components during cross-component state communication, and then the imported API is encapsulated. In order to distinguish the uniform state manager interface function obtained in the two cases, different function names are taken. For example, for a state manager interface function obtained by encapsulating an API that does not support incoming parameters, the function name is set to makeState, and for a state manager interface function obtained by encapsulating an API that supports incoming parameters, the function name is set to makeState family. And after the uniform state manager interface function makeStateFamiliy is obtained through encapsulation, exporting the state manager interface function file.
In an alternative embodiment, after obtaining the unified state manager interface function through the process shown in fig. 1 or fig. 2, the process of performing cross-component state communication based on the state manager interface function includes:
step 1, importing the state manager interface function file makeState obtained by encapsulation.
And 2, setting a basic state and setting an initial value of the state.
For example: when const [ useState ] ═ makeState (0), the state default value is set to 0.
Step 3, obtaining or modifying state values in other assemblies
For example: const [ file, setFile ] ═ useState (). Wherein, file is the acquired state value, and the state value can be modified by using setFile () function.
In another optional embodiment, if some components need to use parameters transmitted from the components as state information, parameter assignment needs to be performed, a packaged makeStateFamily needs to be used to implement a cross-component transmission state with parameters, and after a unified state manager interface function is obtained through the process shown in fig. 1 or fig. 2, the 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 ] ((tips) = > ({ name: tips }) where tips are parameters passed by this component.
Step 3, obtaining or modifying state values
For example: const [ file, setFile ] ═ usestate (profiles). Where file is the current state value, setFile () may be used to modify the state value.
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 Recoil state management library related to the component state transmission are packaged into a unified and simple 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:
the importing module 301 is configured to import a plurality of interface functions in the third-party state management library file.
The first encapsulating module 302 is configured to perform encapsulation processing on the plurality of interface functions respectively to obtain a plurality of encapsulated interface functions.
A second encapsulating module 303, configured to encapsulate the multiple 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 an apparatus implemented by the present invention, the interface function imported by the import module 301 includes: a minimum state unit function for creating a base state; importing a state derivation function for creating a derived state; importing a state usage function for obtaining or modifying a state.
Illustratively, the third party state management library file is a Recoil. In an alternative implementation of this example, the plurality of interface functions imported from Recoil includes: the minimum state cell function atom, the state derivation function selector, the state use function useRecoilValue, and useRecoilCallback. In another optional implementation of this example, the plurality of interface functions imported from Recoil includes: the minimum state cell function atom family, the state derivation functions selectrfamile and selector, and the state use functions useRecoilValue and useRecoilCallback. Wherein, the useRecoilCallback can be used to modify the state value, and the useRecoilValue can be used to obtain the state value.
Optionally, in an implementation apparatus of the present invention, the first encapsulation module 302 is configured to: defining a first interface function, and packaging a logic for calling a minimum state unit function in a function body of the first interface function; defining a second interface function, and packaging the logic for calling the state derivative function in the function body of the second interface function; a third interface function is defined and logic to invoke the state use function is encapsulated within the body of the third interface function.
Optionally, in an apparatus implemented by the present invention, the second packaging module 303 is configured to: defining a uniform state management interface function, and packaging and calling logic of a first interface function, a second interface function and a third interface function in a function body of the state management interface function.
Optionally, in the apparatus for implementing the present invention, the state management interface function supports a first incoming parameter to a third incoming parameter; encapsulating logic calling the first interface function, the second interface function, and the third interface function within the function body of the state management interface function includes:
encapsulating parameter passing logic within a function body of the state management interface function, comprising: assigning the first incoming parameter to a state initial value for calling the first interface function or calling the second interface function for entering the parameter under the condition that the first incoming parameter exists; assigning the third incoming parameter to a state unique identifier for calling the first interface function or the second interface function under the condition that the third incoming parameter exists; when the type of the second incoming parameter is a function, the second incoming parameter is given to a state modification entry parameter required by calling a second interface function; when the type of the second incoming parameter is a character string, the second incoming parameter is given to a state unique identifier for calling the first interface function or calling the second interface function;
encapsulating interface function call logic according to incoming parameters within a function body of the state management interface function, comprising: and under the condition that the state modification parameter exists, calling a second interface function and a third interface function, and under the condition that the state modification parameter does not exist, calling a first interface function and a third interface function.
In the embodiment of the invention, the device realizes that a plurality of complex state management library interfaces related to component state transmission are packaged into a uniform and simple interface, can reduce the difficulty of realizing cross-component state communication, and improves the efficiency of realizing cross-component state communication of programmers.
FIG. 4 illustrates an exemplary system architecture 400 to which embodiments of the 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 serves as a medium for providing communication links between the terminal devices 401, 402, 403 and the server 405. Network 404 may include various types of connections, such as wire, wireless communication links, or fiber optic cables, to name a few.
A user may use terminal devices 401, 402, 403 to interact with a server 405 over a network 404 to receive or send messages or the like. Various communication client applications may 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 smart phones, tablet computers, laptop portable computers, desktop computers, and the like.
The server 405 may be a server providing various services, such as a background management server (for example only) providing support for shopping 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 disposed 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, shown is a block diagram of a computer system 500 suitable for use with a terminal device implementing an embodiment of the present invention. The terminal device shown in fig. 5 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present invention.
As shown in fig. 5, the computer system 500 includes a Central Processing Unit (CPU)501 that 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 necessary for the operation of the system 500 are also stored. The CPU 501, ROM 502, and RAM 503 are connected to each other via 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 portion 506 including a keyboard, a mouse, and the like; an output portion 507 including a display such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; 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 driver 510 is also connected to the I/O interface 505 as necessary. 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 necessary, so that a computer program read out therefrom is mounted into the storage section 508 as necessary.
In particular, according to the embodiments of the present disclosure, the processes described above with reference to the 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 illustrated in the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network through the communication section 509, and/or installed from the removable medium 511. The computer program performs the above-described functions defined in the system of the present invention when executed by the Central Processing Unit (CPU) 501.
It should be noted that the computer readable medium shown in the present invention can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination 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 present invention, 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, a computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. 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 flowchart 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 described in the embodiments of the present invention may be implemented by software or hardware. The described modules may also be provided in a processor, which may be described as: a processor comprises a lead-in module, a first packaging module and a second packaging module. The names of these modules do not in some cases form a limitation on the modules themselves, and for example, an 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 separate and not incorporated into the device. The computer readable medium carries one or more programs which, when executed by a device, cause the device to comprise: importing a plurality of interface functions in a third-party state management library file; respectively encapsulating 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 of the embodiment of the invention, the method for cross-component state communication realized by a 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 reduced, and the effect of improving the efficiency of realizing cross-component state communication of programmers is achieved.
The above-described embodiments should not be construed as limiting the scope of the invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions can occur, depending on design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims (10)

1. A method for communicating across component states, the method comprising:
importing a plurality of interface functions in a third-party state management library file;
respectively encapsulating 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.
2. The method of claim 1, wherein the plurality of interface functions comprises:
a minimum state unit function for creating a base state; a state derivation function for creating a derived state; a state usage function for obtaining or modifying a state.
3. The method of claim 2, wherein the minimum state unit function is a minimum state unit function that does not support incoming parameters, and wherein the state derivation function is a state derivation function that does not support incoming parameters.
4. The method of claim 2, wherein the minimum state cell function is a minimum state cell function that supports incoming parameters, and the state derivation function is a state derivation function that supports incoming parameters.
5. The method according to claim 3 or 4, wherein the encapsulating the plurality of interface functions respectively to obtain a plurality of encapsulated interface functions comprises:
defining a first interface function, and packaging a logic for calling a minimum state unit function in a function body of the first interface function;
defining a second interface function, and packaging the logic for calling the state derivative function in the function body of the second interface function;
a third interface function is defined and logic to invoke the state use function is encapsulated within the body of the third interface function.
6. The method of claim 5, wherein encapsulating the plurality of encapsulated interface functions to obtain a unified state management interface function comprises:
defining a uniform state management interface function, and packaging and calling logic of a first interface function, a second interface function and a third interface function in a function body of the state management interface function.
7. The method of claim 6, wherein the state management interface function supports a first incoming parameter to a third incoming parameter;
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:
encapsulating parameter passing logic within a function body of the state management interface function, comprising: assigning the first incoming parameter to a state initial value for calling the first interface function or calling the second interface function for entering the parameter under the condition that the first incoming parameter exists; assigning the third incoming parameter to a state unique identifier for calling the first interface function or the second interface function under the condition that the third incoming parameter exists; when the type of the second incoming parameter is a function, the second incoming parameter is given to a state modification entry parameter required by calling a second interface function; when the type of the second incoming parameter is a character string, the second incoming parameter is given to a state unique identifier for calling the first interface function or calling the second interface function;
encapsulating interface function call logic according to incoming parameters within a function body of the state management interface function, comprising: and under the condition that the state modification parameter exists, calling a second interface function and a third interface function, and under the condition that the state modification parameter does not exist, calling a first interface function and a third interface function.
8. An apparatus for communicating across component states, comprising:
the import 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 packaging module is used for 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.
9. An electronic device, comprising:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the method of any one of claims 1-7.
10. A computer-readable medium, on which a computer program is stored, which, when being executed by a processor, carries out the method according to any one of claims 1-7.
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 true CN113709171A (en) 2021-11-26
CN113709171B 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)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115242764A (en) * 2022-07-21 2022-10-25 平安科技(深圳)有限公司 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
丁炜: "浅析SAP集成开发技术的应用实践", 《科技视界》 *
无: ""PeopleSoft Component Interface Frequently Asked Question"", 《HTTPS://WWW.DBTUTOR.COM/2013/06/08/PEOPLESOFT-COMPONENT-INTERFACE-FREQUENTLY-ASKED-QUESTION》 *
李志超: ""基于SAP接口技术的研究与应用"", 《中国优秀硕士学位论文全文数据库(电子期刊)信息科技辑》 *
李鹏: ""基于SAP的跨组件流程集成与交换技术研究"", 《中国优秀硕士学位论文全文数据库(电子期刊)信息科技辑》 *
马川,王涛,祁晓园,王倩,尤殿龙: ""Android应用程序的组件间通信行为检测"", 《小型微型计算机***》 *

Cited By (2)

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

Also Published As

Publication number Publication date
CN113709171B (en) 2023-05-30

Similar Documents

Publication Publication Date Title
CN111158818A (en) Page rendering method and device
CN111338623B (en) Method, device, medium and electronic equipment for developing user interface
CN112286529A (en) Development method, device and equipment of front-end page and storage medium
CN111581555B (en) Document loading method, device, equipment and storage medium
CN110858202A (en) Method and device for generating where clause in database query statement
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
CN114035879A (en) Page theme color changing method and device, electronic equipment and computer readable medium
CN109343970B (en) Application program-based operation method and device, electronic equipment and computer medium
CN109725887B (en) Data interaction method and device based on message research and development framework and terminal equipment
CN113709171B (en) Method and device for cross-component state communication
CN113760264A (en) Method and device for multiplexing components among multiple applications
CN112416303A (en) Software development kit thermal restoration method and device and electronic equipment
CN113391860A (en) Service request processing method and device, electronic equipment and computer storage medium
CN111414154A (en) Method and device for front-end development, electronic equipment and storage medium
CN113760487B (en) Service processing method and device
CN112905273A (en) Service calling method and device
CN113778566A (en) Native application calling method and device, electronic equipment and computer readable medium
CN114840310A (en) Container creation method, device, electronic equipment and computer-readable storage medium
CN109669679B (en) Service detection and processing method and device and electronic equipment
CN114035778A (en) Object generation method, device, storage medium and electronic equipment
CN109669720B (en) Chain type asynchronous request processing method and device based on Promise and electronic equipment
CN113760262A (en) Task processing method, device, computer system and computer readable storage medium

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