CN115586897A - An interface programming method, device and related equipment - Google Patents
An interface programming method, device and related equipment Download PDFInfo
- Publication number
- CN115586897A CN115586897A CN202211215395.8A CN202211215395A CN115586897A CN 115586897 A CN115586897 A CN 115586897A CN 202211215395 A CN202211215395 A CN 202211215395A CN 115586897 A CN115586897 A CN 115586897A
- Authority
- CN
- China
- Prior art keywords
- node
- component
- page
- nodes
- displayed
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/30—Creation or generation of source code
- G06F8/38—Creation or generation of source code for implementing user interfaces
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/90—Details of database functions independent of the retrieved data types
- G06F16/95—Retrieval from the web
- G06F16/958—Organisation or management of web site content, e.g. publishing, maintaining pages or automatic linking
- G06F16/986—Document structures and storage, e.g. HTML extensions
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- General Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Databases & Information Systems (AREA)
- Human Computer Interaction (AREA)
- Data Mining & Analysis (AREA)
- User Interface Of Digital Computer (AREA)
Abstract
本申请应用于计算机技术领域,提供了一种界面编程方法、装置以及相关设备,其中方法包括:显示第一页面,其中第一页面包括多个组件,多个组件中的每个组件至少对应一个节点,每个节点具有各自的属性值;获取到界面更新请求,确定出第一页面属性值发生变化的节点;将属性值发生变化的节点进行更新,得到第二页面。这样,通过本申请提供的界面编程方法,能根据有属性变化的节点,在界面更新中只更新该属性变化的节点,无需更新整个界面,提高了界面渲染效率。
The application is applied in the field of computer technology, and provides an interface programming method, device and related equipment, wherein the method includes: displaying a first page, wherein the first page includes a plurality of components, and each component in the plurality of components corresponds to at least one Each node has its own attribute value; the interface update request is obtained, and the node whose attribute value changes on the first page is determined; the node whose attribute value changes is updated to obtain the second page. In this way, through the interface programming method provided by the present application, according to the nodes with attribute changes, only the nodes whose attributes change can be updated in the interface update, without updating the entire interface, which improves the interface rendering efficiency.
Description
技术领域technical field
本发明涉及计算机技术领域,尤其涉及一种界面编程方法、装置以及相关设备。The present invention relates to the field of computer technology, in particular to an interface programming method, device and related equipment.
背景技术Background technique
在界面开发中,通常将界面中的数据以文档对象模型(document object model,DOM)进行处理,通过DOM可以将一个界面表示为一个DOM树,树的每个节点表示了界面中的一个标签或标签内的文本项,DOM树的结构能描述出界面中各个标签间的相互关联性。电子设备通过渲染DOM树即可显示对应的界面。In interface development, the data in the interface is usually processed with a document object model (document object model, DOM), through which an interface can be represented as a DOM tree, and each node of the tree represents a label or The text item in the label, the structure of the DOM tree can describe the interrelationship between the various labels in the interface. The electronic device can display the corresponding interface by rendering the DOM tree.
然而,每次修改界面数据时,都会引起DOM节点的变化,此时电子设备都将重新渲染整个界面,从而让界面的内容与更新后的DOM的内容保持一致。然而,电子设备每次渲染整个界面时,会依次调用DOM树中各个节点对应的API,导致界面与DOM之间需要频繁交互,产生了较大的开销。However, every time interface data is modified, DOM nodes will be changed, and the electronic device will re-render the entire interface at this time, so that the content of the interface is consistent with the content of the updated DOM. However, every time the electronic device renders the entire interface, it will sequentially call APIs corresponding to each node in the DOM tree, resulting in frequent interaction between the interface and the DOM, resulting in relatively large overhead.
为了减少DOM接口的调用,在一些方法中,在界面更新的时候,将根据当前的界面数据先解析出一个虚拟DOM(virtual DOM,VDOM)树,然后在界面数据有变化时,再将变化后的界面数据解析成一个新的VDOM树,然后将两次的VDOM树进行比对,确定新增、修改或者删除的节点,然后只调用上述有修改的节点的API来更新该节点在界面中的内容。In order to reduce the calls of the DOM interface, in some methods, when the interface is updated, a virtual DOM (virtual DOM, VDOM) tree will be parsed out according to the current interface data, and then when the interface data changes, the changed The interface data is parsed into a new VDOM tree, and then the two VDOM trees are compared to determine the newly added, modified or deleted nodes, and then only the API of the above modified node is called to update the node in the interface. content.
但是,在比对上一次VDOM树和本次VDOM树的过程中,需要通过上一次VDOM树和本次VDOM树中节点的类型等依次确认节点的对应关系,进而才能确认出有更改的节点。该对比过程会花费较长时间,会占用处理器较多资源,使得界面更新效率较低。However, in the process of comparing the previous VDOM tree and the current VDOM tree, it is necessary to confirm the corresponding relationship of the nodes through the types of nodes in the previous VDOM tree and the current VDOM tree, and then confirm the changed nodes. The comparison process will take a long time, occupy more resources of the processor, and make the interface updating efficiency lower.
发明内容Contents of the invention
本申请提供了一种界面编程方法、装置以及相关设备,通过响应式数据确定有属性变化的节点,通过显示属性的值能确定节点的删除和增加,进而电子设备能获取到所有有变化的节点,然后对有变化的节点在界面中重新进行渲染,提升了界面更新的效率。。The present application provides an interface programming method, device and related equipment. Nodes with attribute changes can be determined through responsive data, and the deletion and addition of nodes can be determined by displaying attribute values, so that electronic equipment can obtain all changed nodes. , and then re-render the changed nodes in the interface, which improves the efficiency of interface update. .
第一方面,提供一种界面编程方法,应用于电子设备,包括:显示第一页面,其中第一页面包括多个组件,多个组件中的每个组件至少对应一个节点,每个节点具有各自的属性值;获取到界面更新请求,确定出第一页面属性值发生变化的节点;将属性值发生变化的节点进行更新,得到第二页面。In a first aspect, an interface programming method is provided, which is applied to an electronic device, including: displaying a first page, wherein the first page includes a plurality of components, and each component in the plurality of components corresponds to at least one node, and each node has its own attribute value; obtain the interface update request, and determine the node whose attribute value changes on the first page; update the node whose attribute value changes to obtain the second page.
在上述方案中,界面是由多个组件构成的,每个组件对应一个节点,界面在显示时,需要遍历所有节点。通过本申请提供的界面编程方法,能根据有属性变化的节点,在界面更新中只更新该属性变化的节点,无需更新整个界面,提高了界面渲染效率。In the above solution, the interface is composed of multiple components, each component corresponds to a node, and all nodes need to be traversed when the interface is displayed. Through the interface programming method provided by the present application, according to the nodes with attribute changes, only the nodes whose attributes change can be updated in the interface update without updating the entire interface, which improves the interface rendering efficiency.
结合第一方面,在一些实现方式中,节点的属性包括显示属性,显示属性用于指示是否显示节点对应的第一组件。With reference to the first aspect, in some implementation manners, the attribute of the node includes a display attribute, and the display attribute is used to indicate whether to display the first component corresponding to the node.
在上述方案中,通过在节点中添加显示属性,来标记该节点是否显示,显示属性的值表示是否在界面中显示该节点,进而电子设备能根据该显示属性值的和界面是否显示该节点的组件确定是否有节点的增删。无需电子设备去将存储的原始VDOM树与新的VDOM树进行对比,确定新增、修改或者删除的节点,无需因为比较VDOM树给处理器带来较大开销。In the above solution, by adding a display attribute to the node, it is marked whether the node is displayed, and the value of the display attribute indicates whether the node is displayed in the interface, and then the electronic device can display the node according to the value of the display attribute and the interface. The component determines if there are additions or deletions of nodes. There is no need for electronic devices to compare the stored original VDOM tree with the new VDOM tree to determine the newly added, modified or deleted nodes, and there is no need to bring a large overhead to the processor due to the comparison of the VDOM tree.
结合第一方面,在一些实现方式中,还包括确定出显示属性与第一页面不对应的节点,其中,显示属性与第一页面不对应包括:显示属性指示显示第一组件且第一页面中未显示第一组件;或者,显示属性指示不显示第一组件且第一页面中显示了第一组件。In combination with the first aspect, in some implementations, it also includes determining that the display attribute does not correspond to the first page node, wherein the display attribute does not correspond to the first page includes: the display attribute indicates that the first component is displayed and the first page The first component is not displayed; or, the display attribute indicates that the first component is not displayed and the first component is displayed on the first page.
在上述方案中,当显示属性表示显示该节点,但是界面没有显示该组件,则表示该节点是新添加的,当显示属性表示不显示该节点,但是界面中显示了该组件,则表示该节点是要删除的。进而电子设备能根据该显示属性值的和界面是否显示该节点的组件确定是否有节点的增删。无需电子设备去将存储的原始VDOM树与新的VDOM树进行对比,确定新增或者删除的节点,无需因为比较VDOM树给处理器带来较大开销。In the above solution, when the display attribute indicates that the node is displayed, but the interface does not display the component, it means that the node is newly added; when the display attribute indicates that the node is not displayed, but the component is displayed in the interface, it indicates that the node is to be deleted. Furthermore, the electronic device can determine whether there is addition or deletion of nodes according to the display attribute value and whether the interface displays the component of the node. There is no need for electronic devices to compare the stored original VDOM tree with the new VDOM tree to determine the newly added or deleted nodes, and there is no need to bring a large overhead to the processor due to the comparison of the VDOM tree.
结合第一方面,在一些实现方式中,还包括,确定出第一属性发生变化的节点,其中,第一属性是根据第一变量确定的,第一变量关联第一属性的计算。With reference to the first aspect, in some implementation manners, the method further includes determining a node whose first attribute changes, where the first attribute is determined according to a first variable, and the first variable is associated with calculation of the first attribute.
在上述方案中,将数据定义为响应式数据,其中,响应式数据在定义中会绑定对应的执行函数,当数据发生变化时,将触发电子设备执行该绑定的函数。In the above solution, the data is defined as responsive data, wherein the responsive data is bound to a corresponding execution function in the definition, and when the data changes, the electronic device will be triggered to execute the bound function.
结合第一方面,在一些实现方式中,还包括,基于节点中第一属性发生变化,自动重新计算节点的第一属性;将属性值发生变化的节点进行更新,得到第二页面,包括:基于显示属性指示显示第一组件,根据重新计算第一属性后的节点,在第二页面中显示节点对应的组件。In combination with the first aspect, in some implementations, it also includes automatically recalculating the first attribute of the node based on the change of the first attribute in the node; updating the node whose attribute value has changed to obtain the second page, including: based on The display attribute indicates to display the first component, and according to the node after recalculating the first attribute, the component corresponding to the node is displayed on the second page.
在上述方案中,在当节点中某一属性使用了该响应式数据时,将响应式数据与计算该节点的属性进行绑定,因此只要响应式数据发生了变化时,电子设备将自动对该节点的属性进行重算,进而,电子设备能通过确定哪些节点进行了重算,来确定属性有变化的节点直接通过绑定关系确定调用了该响应式数据的节点,进而实现节点中属性变化的监控,通过响应式数据的变化就能监控到有修改的节点。无需电子设备去将存储的原始VDOM树与新的VDOM树进行对比,确定属性有变化的节点,节省了处理器的开销。In the above solution, when a certain property in a node uses the responsive data, the responsive data is bound to the calculated property of the node, so as long as the responsive data changes, the electronic device will automatically The properties of the nodes are recalculated, and then the electronic device can determine which nodes have been recalculated to determine the nodes whose properties have changed and directly determine the nodes that call the responsive data through the binding relationship, thereby realizing the control of property changes in the nodes. Monitoring, the modified nodes can be monitored through changes in responsive data. There is no need for electronic devices to compare the stored original VDOM tree with the new VDOM tree to determine nodes with changed attributes, which saves processor overhead.
结合第一方面,在一些实现方式中,还包括,根据多个节点的属性,创建可视节点树,可视节点树包括多个可视节点,多个可视节点中的每个可视节点都对应一个节点;根据多个可视节点,显示第一页面。In combination with the first aspect, in some implementations, it also includes, according to the attributes of multiple nodes, creating a visual node tree, where the visual node tree includes multiple visual nodes, and each visual node in the multiple visual nodes All correspond to a node; according to multiple visible nodes, the first page is displayed.
在上述方案中,界面显示的过程具体为根据节点属性,生成可视节点,然后根据可视节点来渲染界面。In the above scheme, the process of displaying the interface is specifically to generate visible nodes according to the attributes of the nodes, and then render the interface according to the visible nodes.
结合第一方面,在一些实现方式中,还包括,基于第一页面已显示第一组件,在第二视图中保持第一组件的显示;基于第一页面未显示第一组件,在可视节点树中创建节点对应的可视节点,并根据可视节点在第二页面中显示第一组件。In combination with the first aspect, in some implementations, it also includes, based on the first component being displayed on the first page, maintaining the display of the first component in the second view; based on the first page not displaying the first component, in the visible node A visible node corresponding to the node is created in the tree, and the first component is displayed on the second page according to the visible node.
在上述方案中,如果显示属性的值表示显示该节点时,若电子设备确定在上一次界面显示中显示了该节点,则说明该节点的显示属性没有改变,若电子设备将确定在上一次界面显示中没有显示该节点,则说明该节点是新创建的,将生成该节点的可视节点,然后界面将显示该节点对应的组件。进而电子设备能根据该显示属性值的和界面是否显示该节点的组件确定是否有节点的增删。无需电子设备去将存储的原始VDOM树与新的VDOM树进行对比,确定新增或者删除的节点,无需因为比较VDOM树给处理器带来较大开销。In the above solution, if the value of the display attribute indicates that the node is displayed, if the electronic device determines that the node was displayed in the last interface display, it means that the display attribute of the node has not changed. If the node is not displayed in the display, it means that the node is newly created, and the visible node of the node will be generated, and then the interface will display the corresponding components of the node. Furthermore, the electronic device can determine whether there is addition or deletion of nodes according to the display attribute value and whether the interface displays the component of the node. There is no need for electronic devices to compare the stored original VDOM tree with the new VDOM tree to determine the newly added or deleted nodes, and there is no need to bring a large overhead to the processor due to the comparison of the VDOM tree.
结合第一方面,在一些实现方式中,在显示属性指示不显示第一组件的情况下,还包括:基于第一页面未显示第一组件,在第二页面中保持第一页面的显示;基于第一页面显示了第一组件,在可视节点树中删除节点对应的可视节点,并在第二页面中不显示第一组件。With reference to the first aspect, in some implementations, when the display attribute indicates that the first component is not displayed, the method further includes: maintaining the display of the first page on the second page based on the fact that the first component is not displayed on the first page; The first page displays the first component, deletes the visible node corresponding to the node in the visible node tree, and does not display the first component on the second page.
在上述方案中,当显示属性的值表示不显示该节点时,若电子设备确定在上一次界面显示中也没有显示该节点,则说明该节点的显示属性没有改变,若电子设备确定在上一次界面显示中显示了该节点,则说明该节点是本次删除的,界面将不显示该节点对应的组件,并销毁该节点及其子节点。进而电子设备能根据该显示属性值的和界面是否显示该节点的组件确定是否有节点的增删。无需电子设备去将存储的原始VDOM树与新的VDOM树进行对比,确定新增或者删除的节点,无需因为比较VDOM树给处理器带来较大开销。In the above solution, when the value of the display attribute indicates that the node is not displayed, if the electronic device determines that the node was not displayed in the last interface display, it means that the display attribute of the node has not changed. If the node is displayed in the interface display, it means that the node is deleted this time, the interface will not display the corresponding component of the node, and the node and its sub-nodes will be destroyed. Furthermore, the electronic device can determine whether there is addition or deletion of nodes according to the display attribute value and whether the interface displays the component of the node. There is no need for electronic devices to compare the stored original VDOM tree with the new VDOM tree to determine the newly added or deleted nodes, and there is no need to bring a large overhead to the processor due to the comparison of the VDOM tree.
结合第一方面,在一些实现方式中,第一节点具有子节点,且显示属性指示显示第一组件的情况下,还包括:基于子节点的显示属性,确定是否显示子节点对应的第一组件;基于第一页面未显示第一组件且子节点的显示属性指示显示子节点对应的第二组件,在可视节点树中创建第一节点和子节点对应的可视节点,并根据第一可视节点在第二页面中显示第一组件和第二组件。In conjunction with the first aspect, in some implementations, when the first node has child nodes, and the display attribute indicates that the first component is displayed, the method further includes: based on the display attribute of the child node, determining whether to display the first component corresponding to the child node ;Based on the fact that the first component is not displayed on the first page and the display attribute of the child node indicates that the second component corresponding to the child node is displayed, the first node and the visible node corresponding to the child node are created in the visual node tree, and according to the first visual The node displays the first component and the second component in the second page.
在上述方案中,如果节点还具有子节点的情况下,如果要显示该节点,则还会根据子节点的显示属性判断是否要显示子节点。在节点的显示属性指示显示第一组件,子节点的显示属性指示不显示第二组件的时候,只能第一节点对应的组件。在节点的显示属性指示显示第一组件,子节点的显示属性指示显示第二组件的时候,才能同时子节点和第一节点对应的组件。In the above solution, if the node also has child nodes, if the node is to be displayed, it is also determined whether to display the child node according to the display attribute of the child node. When the display attribute of the node indicates to display the first component, and the display attribute of the child node indicates not to display the second component, only the component corresponding to the first node can be used. Only when the display attribute of the node indicates to display the first component and the display attribute of the child node indicates to display the second component can the child node and the corresponding component of the first node be displayed at the same time.
结合第一方面,在一些实现方式中,第一节点具有子节点,且显示属性指示不显示第一组件的情况下,还包括:基于第一页面未显示第一组件和子节点对应的第二组件,在第二页面中保持第一页面的显示;基于第一页面显示了第一组件和第二组件,在可视节点树中删除第一节点和第二节点对应的可视节点,并在第二页面中不显示第一组件和第二组件。In combination with the first aspect, in some implementations, when the first node has child nodes, and the display attribute indicates that the first component is not displayed, the method further includes: not displaying the first component and the second component corresponding to the child node based on the first page , keep the display of the first page in the second page; based on the display of the first component and the second component on the first page, delete the visible nodes corresponding to the first node and the second node in the visible node tree, and The first component and the second component are not displayed on the second page.
在上述方案中,在第一节点不会显示的情况下,该第一节点的子节点也一定不会显示的。对应地,在可视节点树中会一并删除该节点和子节点的可视节点。In the above solution, if the first node will not be displayed, the child nodes of the first node will also not be displayed. Correspondingly, the node and the visible nodes of the child nodes will be deleted together in the visible node tree.
第二方面,本申请提供了一种计算设备,其特征在于,包括处理器和存储器,存储器用于存储指令,处理器用于执行指令,当处理器执行该指令时,执行如第一方面所描述的方法。In a second aspect, the present application provides a computing device, which is characterized in that it includes a processor and a memory, the memory is used to store instructions, and the processor is used to execute the instructions. When the processor executes the instructions, the execution is as described in the first aspect. Methods.
第三方面,本申请提供一种计算机可读存储介质,其特征在于,计算机可读存储介质中存储有指令,当指令在计算设备上运行时,执行如第一方面所描述的方法。In a third aspect, the present application provides a computer-readable storage medium, wherein instructions are stored in the computer-readable storage medium, and when the instructions are run on a computing device, the method described in the first aspect is executed.
第四方面,本申请提供了一种计算机程序产品,其特征在于,计算机程序产品包括计算机指令,在被计算设备执行时,计算设备执行如第一方面所描述的方法。In a fourth aspect, the present application provides a computer program product, which is characterized in that the computer program product includes computer instructions, and when executed by a computing device, the computing device executes the method described in the first aspect.
附图说明Description of drawings
为了更清楚地说明本申请实施例中的技术方案,下面将对实施例描述中所需要使用的附图作简单地介绍。In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings that need to be used in the description of the embodiments.
图1是本申请实施例提供的一种VDOM模型的代码示意图;Fig. 1 is a code schematic diagram of a VDOM model provided by the embodiment of the present application;
图2是本申请实施例提供的一种VDOM模型比对节点的示意图;Fig. 2 is a schematic diagram of a VDOM model comparison node provided by the embodiment of the present application;
图3是本申请实施例提供的一种VDOM模型和界面编程方法确定属性有更改的节点的对比示意图;Fig. 3 is a kind of VDOM model provided by the embodiment of the present application and the interface programming method determine the comparative schematic diagram of the node that property has changed;
图4是本申请实施例提供的一种VDOM模型和界面编程方法确定有增加和删除节点的对比示意图;Fig. 4 is a kind of VDOM model provided by the embodiment of the present application and the interface programming method determine that there is a comparative schematic diagram of adding and deleting nodes;
图5是本申请实施例提供的一种界面编程系统的结构示意图;Fig. 5 is a schematic structural diagram of an interface programming system provided by an embodiment of the present application;
图6是本申请实施例提供的一种界面编程系统应用于命令式编程的示意图;Fig. 6 is a schematic diagram of an interface programming system provided by an embodiment of the present application applied to imperative programming;
图7是本申请实施例提供的一种界面编程系统应用于DOM模型的示意图;Fig. 7 is a schematic diagram of an interface programming system provided by an embodiment of the present application applied to a DOM model;
图8是本申请实施例提供的一种界面编程方法的流程示意图;Fig. 8 is a schematic flowchart of an interface programming method provided by an embodiment of the present application;
图9是本申请实施例提供的一种界面编程方法中确定有数据变化的节点的代码示意图;Fig. 9 is a schematic diagram of codes for determining nodes with data changes in an interface programming method provided by an embodiment of the present application;
图10是本申请实施例提供的一种界面编程方法中确定增加或删除节点的代码示意图;Fig. 10 is a schematic diagram of the code for determining to add or delete nodes in an interface programming method provided by the embodiment of the present application;
图11是本申请实施例提供的另一种界面编程方法中确定增加或删除节点的代码示意图;Fig. 11 is a schematic diagram of the code for determining to add or delete nodes in another interface programming method provided by the embodiment of the present application;
图12是本申请实施例提供的另一种界面编程方法的流程示意图;Fig. 12 is a schematic flowchart of another interface programming method provided by the embodiment of the present application;
图13是本申请实施例提供的一种VDOM模型和界面编程方法性能比对的示意图;Fig. 13 is a schematic diagram of performance comparison between a VDOM model and an interface programming method provided by the embodiment of the present application;
图14是本申请实施例提供的一种界面编程方法中视图伸缩方法的流程示意图;Fig. 14 is a schematic flowchart of a view scaling method in an interface programming method provided by an embodiment of the present application;
图15是本申请实施例提供的一种界面编程方法中视图伸缩的代码的示意图;Fig. 15 is a schematic diagram of codes for view expansion and contraction in an interface programming method provided by an embodiment of the present application;
图16是本申请实施例提供的一种界面编程方法中视图伸缩的示意图;Fig. 16 is a schematic diagram of view expansion and contraction in an interface programming method provided by an embodiment of the present application;
图17是本申请实施例提供的一种界面编程装置的示意图;Fig. 17 is a schematic diagram of an interface programming device provided by an embodiment of the present application;
图18是本申请实施例提供的一种电子设备的结构示意图。FIG. 18 is a schematic structural diagram of an electronic device provided by an embodiment of the present application.
具体实施方式detailed description
本申请的说明性实施例包括但不限于界面编程方法、设备、产品及介质。Illustrative embodiments of the present application include, but are not limited to, interface programming methods, devices, products, and media.
首先,对本申请实施例涉及的界面开发的相关技术进行介绍。First, the related technologies of interface development involved in the embodiment of the present application are introduced.
在软件开发中包含命令式(imperative)编程和声明式(Declarative)编程两种模式。其中,命令式编程通常用于命令电子设备以特定顺序去执行某些操作,电子设备是逐行遍历代码,更新相应的变量。声明式编程语言用于直接向电子设备声明目标,让电子设备根据程序库中封装好的指令操作去决定如何完成目标。也即是说,命令式编程用于命令电子设备如何去做,不管指令的目的是什么,电子设备都会按照指令去实现。而声明式编程则是告诉电子设备想要的是什么,让电子设备去决定如何实现。In software development, there are two modes of imperative programming and declarative programming. Among them, imperative programming is usually used to command electronic equipment to perform certain operations in a specific order, and electronic equipment traverses the code line by line to update corresponding variables. The declarative programming language is used to directly declare the goal to the electronic device, and let the electronic device decide how to complete the goal according to the instructions encapsulated in the program library. That is to say, imperative programming is used to instruct electronic equipment how to do it, no matter what the purpose of the instruction is, the electronic equipment will follow the instruction. Declarative programming is to tell the electronic device what it wants, and let the electronic device decide how to achieve it.
上述命令式编程和声明式编程也可用于软件的用户界面(user interface,UI)开发。命令式UI开发主要通过编写调用API的指令来更改界面内容,而声明式UI开发主要通过编写界面中组件的属性来更改界面内容。声明式UI开发相比于命令式UI开发,能通过更直观形象的编程语言描述界面内容,能减少代码量,使得声明式UI开发的开发效率更高。例如SwiftUI、VUE、Angular和扩展性Type Script(expansibility TS,eTS)采用的就是声明式编程进行UI开发。The above imperative programming and declarative programming can also be used in software user interface (user interface, UI) development. Imperative UI development mainly changes the content of the interface by writing instructions to call APIs, while declarative UI development mainly changes the content of the interface by writing the properties of components in the interface. Compared with imperative UI development, declarative UI development can describe interface content through a more intuitive and vivid programming language, which can reduce the amount of code and make declarative UI development more efficient. For example, SwiftUI, VUE, Angular and extensibility TypeScript (expansibility TS, eTS) use declarative programming for UI development.
在UI开发中,通常将界面中的数据通过文档对象模型(Document Object Model,DOM)来进行处理,通过DOM可以将一个界面表示为一个DOM树,树的每个节点表示了界面中的一个标签或标签内的文本项,DOM树的结构能描述出界面中各个标签间的相互关联性。In UI development, the data in the interface is usually processed through the Document Object Model (DOM), through which an interface can be represented as a DOM tree, and each node of the tree represents a label in the interface Or the text items in the tags, the structure of the DOM tree can describe the interrelationship between the tags in the interface.
举例来说,界面开发中的超文本标记语言(hyper text markup language,HTML)或者可扩展标记语言(extensible markup language,XML)就属于DOM。举例来说,HTML的标签根据其作用可分为5类,包括描述标题及页面概要信息的标签:如标题〈title〉、主体〈body〉等,描述网页布局的标签:如〈table〉、〈tr〉、〈td〉、〈p〉、〈div〉等,描述显示特点的标签:如〈b〉、〈I〉、〈strong〉、〈h1〉-〈h6〉等,用于表示界面间的内容相关性信息的超链接相关的标签,以及其他标签,如设置图像的标签〈img〉。DOM节点中可以存储有HTML标签的类别(category)、非链接文字数(wordNum)、超链接数(linkNum)、属性集(attribution)和影响度因子(influence)等属性。For example, hypertext markup language (hyper text markup language, HTML) or extensible markup language (extensible markup language, XML) in interface development belongs to DOM. For example, HTML tags can be divided into five categories according to their functions, including tags describing titles and page summary information: such as title <title>, subject <body>, etc., tags describing web page layout: such as <table>, < tr>, <td>, <p>, <div>, etc., tags describing the display characteristics: such as <b>, <I>, <strong>, <h1>-<h6>, etc., used to represent the interface between Hyperlink-related tags for content-related information, and other tags, such as <img> for setting images. Attributes such as category of HTML tags, number of non-link texts (wordNum), number of hyperlinks (linkNum), attribute set (attribution) and influence factor (influence) can be stored in the DOM node.
电子设备将HTML或XML文档转化为DOM树的过程称为解析(parse),HTML或XML文档被解析后将转化为DOM树。进而,开发人员可以通过修改HTML或XML文档,实现的DOM树中节点的删除和添加,以及节点内容的访问和修改。电子设备可以通过调用DOM树中每个节点对应的应用程序编程接口(application programming interface,API)来获取每个节点的内容,并通过渲染DOM树中节点的内容来呈现界面。The process of converting an HTML or XML document into a DOM tree by an electronic device is called parsing, and the HTML or XML document will be converted into a DOM tree after being parsed. Furthermore, developers can delete and add nodes in the DOM tree, as well as access and modify node content, by modifying HTML or XML documents. The electronic device can obtain the content of each node by calling an application programming interface (application programming interface, API) corresponding to each node in the DOM tree, and present an interface by rendering the content of the node in the DOM tree.
下面对采用声明式编程修改DOM中的一个节点进行举例说明,如图1所示,示例性地展示了声明式编程的代码,图1中的代码定义了横向排列的文本"Number:\(value)"和按钮“+”,以及定义了文本“bottom”,按钮“-”等内容,具体内容可参考图1中代码的批注,此处不再赘述。上述代码的组织结构可称为一个组件,组件在DOM中对应一个节点,组件中定了组件的属性数据,组件视图组成并绑定组件数据,其中,如图1所示,value就是属性数据,如果value的值改变,则会引起body组件的重算,进而导致DOM树中还有一个节点产生变化,使得会重新解析出一个DOM树。The following is an example of using declarative programming to modify a node in the DOM. As shown in Figure 1, it exemplarily shows the code of declarative programming. The code in Figure 1 defines the horizontally arranged text "Number:\( value)" and the button "+", as well as the definition of the text "bottom", the button "-", etc. For details, please refer to the comments in the code in Figure 1, which will not be repeated here. The organizational structure of the above code can be called a component. The component corresponds to a node in the DOM. The attribute data of the component is defined in the component. The component view is composed and bound to the component data. As shown in Figure 1, the value is the attribute data. If the value of value changes, it will cause the recalculation of the body component, which will cause another node in the DOM tree to change, so that a DOM tree will be re-parsed.
然而,每次修改界面数据时,都会引起DOM节点的变化,电子设备都将重新渲染整个界面,从而让界面的内容与更新后的DOM的内容保持一致。然而,电子设备每次渲染整个界面时,会依次调用DOM树中各个节点对应的API,会存在界面与DOM之间的频繁交互,会产生了较大的开销,会使得界面更新的效率较低。However, every time the interface data is modified, the DOM nodes will change, and the electronic device will re-render the entire interface, so that the content of the interface is consistent with the content of the updated DOM. However, every time the electronic device renders the entire interface, it will sequentially call the API corresponding to each node in the DOM tree, and there will be frequent interaction between the interface and the DOM, which will generate a large overhead and make the interface update efficiency low. .
为了减少DOM接口的调用,提高界面更新的效率,在一些实施例中,提供了一种虚拟DOM(virtual DOM,VDOM)模型,通过存储界面原有的VDOM树,在HTML或XML文档有修改的时候,将先解析出一个新的VDOM树,然后将存储的原始VDOM树与新的VDOM树进行对比,确定新增、修改或者删除的节点,然后只调用上述有修改的节点的API来更新该节点在界面中的内容。这样,只调用有修改的节点的API就能实现界面的更新,减少了API接口调用产生的开销,提高了界面更新的效率。In order to reduce the calls of DOM interfaces and improve the efficiency of interface updates, in some embodiments, a virtual DOM (virtual DOM, VDOM) model is provided. By storing the original VDOM tree of the interface, there are modified HTML or XML documents. At this time, a new VDOM tree will be parsed first, and then the stored original VDOM tree will be compared with the new VDOM tree to determine the newly added, modified or deleted nodes, and then only the API of the above-mentioned modified nodes will be called to update the VDOM tree. The content of the node in the interface. In this way, the interface can be updated only by calling the API of the modified node, which reduces the overhead of calling the API interface and improves the efficiency of the interface update.
因此,在界面开发中,为了减少代码量,提高开发效率,开发人员通常采用声明式编程。而为了减少界面更新带来的API调用的开销,以及提升界面更新的效率,开发人员通常选用VDOM模型。Therefore, in interface development, in order to reduce the amount of code and improve development efficiency, developers usually use declarative programming. In order to reduce the overhead of API calls brought by interface updates and improve the efficiency of interface updates, developers usually choose the VDOM model.
下面对VDOM更新界面进行举例说明。如图2所示,示例性展示了界面更新前,电子设备保存的原始VDOM树,其中,节点0具有3个子节点:节点1、节点2和节点3,节点1具有子节点:节点5和节点6。The following describes the VDOM update interface with an example. As shown in Figure 2, it exemplarily shows the original VDOM tree saved by the electronic device before the interface is updated, wherein
在界面获取到用户操作,或者开发人员通过编程代码更改了界面数据之后,通过更改后的数据能解析出一个虚拟DOM树(VDOM树),举例来说,VDOM树中,节点7具有子节点为节点8、节点9具有子节点a,节点8具有子节点b,节点9具有子节点c。After the user operation is acquired on the interface, or the developer changes the interface data through the programming code, a virtual DOM tree (VDOM tree) can be parsed out through the changed data. For example, in the VDOM tree,
VDOM模型将先确定节点直接的对应关系,然后确定节点是否有修改、删除或添加,进而比较出原始VDOM树和VDOM树的区别。具体包括,电子设备通过节点的类型、节点属性、节点创建顺序以及节点的位置等确定原始VDOM树和VDOM树之间节点的对应关系,例如,图2中VDOM树的节点8对应原始VDOM的节点1,VDOM树的节点b对应原始VDOM的节点6等等。进而可以确定原始VDOM中节点5被删除,新创建了节点c,原始VDOM树中节点0的属性被修改,使得节点1、节点2和节点3的部分属性也对应受影响被修改。The VDOM model will first determine the direct correspondence of the nodes, and then determine whether the nodes have been modified, deleted or added, and then compare the difference between the original VDOM tree and the VDOM tree. Specifically, the electronic device determines the corresponding relationship between the original VDOM tree and the nodes between the VDOM tree through the type of node, node attribute, node creation order, and node position. For example,
由此可知,VDOM虽然能通过比对原始VDOM和新的VDOM树,确定有变化的节点,然后将有变化的节点在界面中对应进行更新,但是,原始VDOM树和新的VDOM树中的节点对应关系需要通过节点的类型等依次进行确认。如果原始VDOM中各个节点的类型大多都不相同,那么很容易通过比对节点类型就能确定节点的对应关系。然而,如果原始VDOM中各个节点大多都是同一个类型,那么还需要通过其他方式来确定节点的对应关系,会花费较多时间和占用电子设备处理器的较多资源,且容易出现判断错误,导致界面显示出错。并且,在电子设备无法准确判定节点的对应关系时,会将无法确定对应关系的节点也在界面显示前进行重新渲染,会产生API接口调用的开销,导致界面更新的效率较低。It can be seen that although the VDOM can determine the changed nodes by comparing the original VDOM and the new VDOM tree, and then update the changed nodes in the interface, the nodes in the original VDOM tree and the new VDOM tree The corresponding relationship needs to be confirmed sequentially through the type of the node and so on. If the types of each node in the original VDOM are mostly different, it is easy to determine the corresponding relationship of the nodes by comparing the node types. However, if most of the nodes in the original VDOM are of the same type, then other methods are needed to determine the corresponding relationship of the nodes, which will take more time and occupy more resources of the processor of the electronic device, and is prone to judgment errors. Causes an error in the interface display. Moreover, when the electronic device cannot accurately determine the corresponding relationship of the nodes, the nodes whose corresponding relationship cannot be determined will be re-rendered before the interface is displayed, which will generate the overhead of API interface calls, resulting in low interface update efficiency.
为了解决上述比对VDOM节点会花费较多时间,占用电子设备处理器的较多资源,且容易出现判断错误的问题,本申请基于VDOM提供了一种界面编程方法,将数据定义为响应式数据,其中,响应式数据在定义中会绑定对应的执行函数,当数据发生变化时,将触发电子设备执行该绑定的函数。本方案使得在当节点中某一属性使用了该响应式数据时,将响应式数据与计算该节点的属性进行绑定,因此只要响应式数据发生了变化时,电子设备将自动对该节点的属性进行重算,进而,电子设备能通过确定哪些节点进行了重算,来确定属性有变化的节点直接通过绑定关系确定调用了该响应式数据的节点,进而实现节点中属性变化的监控,通过响应式数据的变化就能监控到有修改的节点。然后,在界面显示中,只对属性有变化的节点进行重新渲染,也无需通过比对原始VDOM和新的VDOM来确定有属性变化的节点。In order to solve the above problems that comparing VDOM nodes will take more time, occupy more resources of the electronic device processor, and be prone to judgment errors, this application provides an interface programming method based on VDOM, defining data as responsive data , wherein the definition of responsive data will bind the corresponding execution function, and when the data changes, the electronic device will be triggered to execute the bound function. This solution makes it possible to bind the responsive data to the property of the node when a certain attribute in the node uses the responsive data, so as long as the responsive data changes, the electronic device will automatically The properties are recalculated, and then the electronic device can determine which nodes have been recalculated to determine the nodes whose properties have changed and directly determine the nodes that call the responsive data through the binding relationship, thereby realizing the monitoring of property changes in nodes. Modified nodes can be monitored through changes in responsive data. Then, in the interface display, only the nodes whose attributes have changed are re-rendered, and there is no need to determine the nodes whose attributes have changed by comparing the original VDOM with the new VDOM.
此外,本申请还在每个节点中都添加了一个用于表示是否显示该节点的显示属性,显示属性的值表示是否在界面中显示该节点,进而电子设备能根据该显示属性值的和界面是否显示该节点的组件确定是否有节点的增删。In addition, the application also adds a display attribute to each node to indicate whether to display the node, and the value of the display attribute indicates whether to display the node in the interface, and then the electronic device can Whether to display the components of this node determines whether there are additions and deletions of nodes.
其中,如果显示属性的值表示显示该节点时,若电子设备确定在上一次界面显示中显示了该节点,则说明该节点的显示属性没有改变,若电子设备将确定在上一次界面显示中没有显示该节点,则说明该节点是新创建的,界面将显示该节点对应的组件。当显示属性的值表示不显示该节点时,若电子设备确定在上一次界面显示中也没有显示该节点,则说明该节点的显示属性没有改变,若电子设备确定在上一次界面显示中显示了该节点,则说明该节点是本次删除的,界面将不显示该节点对应的组件,并销毁该节点及其子节点。Among them, if the value of the display attribute indicates that the node is displayed, if the electronic device determines that the node was displayed in the last interface display, it means that the display attribute of the node has not changed. If the node is displayed, it means that the node is newly created, and the interface will display the components corresponding to the node. When the value of the display attribute indicates that the node is not displayed, if the electronic device determines that the node was not displayed in the last interface display, it means that the display attribute of the node has not changed. This node means that the node is deleted this time, the interface will not display the corresponding component of the node, and the node and its sub-nodes will be destroyed.
这样,通过本申请提供的界面编程方法,能根据响应式数据确定有属性变化的节点,通过显示属性的值能确定节点的删除和增加,进而电子设备能获取到所有有变化的节点,然后对有变化的节点在界面中重新进行渲染。无需进行原始VDOM树和新的VDOM树的比较,就能确定有变化的节点,无需因为比较VDOM树给处理器带来较大开销。并且,本方法是根据响应式数据的绑定关系和显示属性的值来确定的有变化的节点的,不会存在原始VDOM树和新的VDOM树节点比较出错的问题,提升了界面更新的效率。In this way, through the interface programming method provided by this application, the nodes with attribute changes can be determined according to the responsive data, the deletion and addition of nodes can be determined by displaying the value of the attributes, and then the electronic device can obtain all the changed nodes, and then Changed nodes are re-rendered in the interface. Nodes with changes can be determined without comparing the original VDOM tree with the new VDOM tree, and there is no need to bring a large overhead to the processor due to the comparison of the VDOM tree. Moreover, this method determines the changed nodes based on the binding relationship of the responsive data and the value of the display attribute, and there will be no problem of comparing the original VDOM tree with the new VDOM tree node, which improves the efficiency of interface update .
举例来说,如图3中(A)所示,VDOM树中更改了节点1中的属性或者数值,节点1更改后记为节点8。采用VDOM的方法时,将先比对原始VDOM树和新的VDOM树中各个节点的对应关系,确定原始VDOM中节点1变更为了节点8,然后才能对节点1(节点8)进行重新渲染。然而,通过本申请提供的界面编程方法,如图3中的(B)所示,将节点1调用的数据的类型确定为响应式数据,在节点1中调用的数据发生变化时,电子设备就能获取到节点1发生了修改。For example, as shown in (A) in FIG. 3 , the attribute or value in
再比如说,如图4中的(A)所示,VDOM树中删除了节点1及其子节点,在节点2下新建子节点7。电子设备要先比对原始VDOM树和新的VDOM树中各个节点的属性等,才能确定节点的对应关系,进而确定出节点1被删除,在节点2下新建一个节点7。然而通过本申请提供的方法,通过修改节点1和节点2的显示属性的值,电子设备就能知道哪些节点有增加和删除。例如,如图4中(B)所示,显示属性用vif来表示,vif默认值为true,即每个节点默认是会显示该节点及其子节点的,而vif的值为false表示不显示该节点及其子节点,当节点1的vif值变为了false,则表示该节点在界面中不会显示,即该节点不展开,电子设备在界面渲染中将不显示节点1及其子节点5和子节点6对应的部分。而电子设备检测到新增了节点7的vif值为true,即可在界面显示中对应显示节点7的内容。For another example, as shown in (A) in FIG. 4 ,
在一些实施例中,显示属性的值默认为显示该节点。对于显示属性的值为不显示该节点时,VDOM中也会在该节点处保留一个虚拟节点,只是在界面渲染中并不会显示该节点,该虚拟节点的属性为不会显示该节点,以使电子设备能根据该节点的显示属性与界面中是否有显示该节点对应的组件,来确定该节点及其组件是要被删除的。In some embodiments, the value of the display property defaults to displaying the node. When the value of the display attribute is not to display the node, a virtual node will also be reserved at the node in the VDOM, but the node will not be displayed in the interface rendering, and the property of the virtual node will not be displayed. The electronic device can determine that the node and its components are to be deleted according to the display attribute of the node and whether there is a component corresponding to the node displayed in the interface.
下面结合图5介绍本申请提供的界面编程系统。如图5所示,该界面编程系统包括开发者提供的组件化编程,将组件化编程转换为VDOM树的声明式引擎,其中声明式引擎包括组件解析模块、定位数据变化节点模块、定位增删节点模块以及构建VDOM树模块,以及该系统还包括进行生成视图的UI渲染模块,UI渲染模块包括渲染可视DOM树模块。The interface programming system provided by the present application will be introduced below with reference to FIG. 5 . As shown in Figure 5, the interface programming system includes componentized programming provided by developers, and converts componentized programming into a declarative engine for VDOM trees. module and a module for constructing a VDOM tree, and the system also includes a UI rendering module for generating a view, and the UI rendering module includes a module for rendering a visual DOM tree.
开发者可以通过组件化编程进行声明式的UI开发,然后开发者的代码将被加载到声明式引擎中,声明式引擎将把开发者编写的代码进行解析,生成VDOM树,然后VDOM树可以被UI渲染模块转换为可视化的节点树(可视DOM树),进而通过可视DOM树得到界面视图。其中,组件化编程中会将数据定义为响应式数据,在声明式引擎中会给每个节点添加显示属性,显示属性缺省值可以为true,即默认节点会被显示。Developers can perform declarative UI development through component programming, and then the developer's code will be loaded into the declarative engine, which will parse the code written by the developer to generate a VDOM tree, and then the VDOM tree can be The UI rendering module is converted into a visual node tree (visual DOM tree), and then the interface view is obtained through the visual DOM tree. Among them, data is defined as responsive data in component programming, and display attributes are added to each node in a declarative engine. The default value of the display attribute can be true, that is, the default node will be displayed.
当组件化编程中提供了要删除、添加或者修改节点的代码时,或者界面中获取到了用户操作要更改界面时,声明式引擎将通过定位数据变化模块对有修改的节点进行定位,具体是通过响应式数据与节点的绑定关系确定的。声明式引擎还将通过定位增删节点模块确定每个节点是否要展开,即每个节点是否会被显示,具体是通过节点的显示属性的值来确定的。然后基于定位数据变化模块和定位增删节点模块确定有修改的节点之后,就能获取到新的可视DOM树,然后根据新的可视DOM树通过UI渲染模块就能渲染得到新的界面。When the code to delete, add, or modify nodes is provided in component programming, or when the interface obtains user operations to change the interface, the declarative engine will locate the modified nodes through the positioning data change module, specifically through The binding relationship between responsive data and nodes is determined. The declarative engine will also determine whether each node is to be expanded by locating the addition and deletion node module, that is, whether each node will be displayed, specifically determined by the value of the display attribute of the node. Then, after the modified node is determined based on the positioning data change module and the positioning addition and deletion node module, a new visual DOM tree can be obtained, and then a new interface can be rendered by the UI rendering module according to the new visual DOM tree.
在一些实施例中,该界面编程系统也可以应用于命令式编程的UI开发,其中,命令式编程的UI开发是直接编写调用对应接口的代码,命令式编程的代码可以对应为一个渲染树。该方法还需要将命令式编程的语句通过属性化封装,转换为声明式编程。如图6所示,该装置还包括属性化封装模块,该模块用于将命令式编程进行属性化封装,进而可以将命令式编程对应的渲染树解析为声明式引擎的VDOM树,其余模块可参考上述图5及其相关描述,此处不再赘述。举例来说,在命令式编程中,控制文本显示内容的接口可以为TextUI.setText(std::string const&text),经过属性化封装,可以被抽象为属性化的控制,即声明式编程对应的代码为Text(text=“…”),其中,省略号用于表示显示的具体内容。当属性text属性变更后,属性化封装就可以自动调用对应的setText命令,将变更的属性更新到界面中。In some embodiments, the interface programming system can also be applied to UI development of imperative programming, wherein the UI development of imperative programming is to directly write the code that calls the corresponding interface, and the code of imperative programming can correspond to a rendering tree. This method also needs to transform the statements of imperative programming into declarative programming through attribute encapsulation. As shown in Figure 6, the device also includes an attribute-based encapsulation module, which is used to attribute-encapsulate the imperative programming, and then parse the rendering tree corresponding to the imperative programming into the VDOM tree of the declarative engine, and the other modules can be Refer to the foregoing FIG. 5 and its related descriptions, and details are not repeated here. For example, in imperative programming, the interface to control text display content can be TextUI.setText(std::string const&text), which can be abstracted into attribute-based control after attribute-based encapsulation, that is, the code corresponding to declarative programming It is Text (text="..."), where the ellipsis is used to indicate the specific content displayed. When the attribute text attribute is changed, the attribute encapsulation can automatically call the corresponding setText command to update the changed attribute to the interface.
在另一些实施例中,该界面编程系统也可以应用于DOM模型上,由于本方案不涉及新的VDOM和原始VDOM的比对,因此可以直接适用于DOM模型。如图7所示,根据组件化编程解析得到的VDOM可以直接用于UI渲染模块进行渲染。In some other embodiments, the interface programming system can also be applied to the DOM model. Since this solution does not involve the comparison between the new VDOM and the original VDOM, it can be directly applied to the DOM model. As shown in FIG. 7 , the VDOM obtained through component-based programming analysis can be directly used for rendering by the UI rendering module.
下面对本申请提供的界面编程方法进行详细描述,如图8所示,该界面编程方法可以包括以下步骤:The interface programming method provided by the present application is described in detail below, as shown in Figure 8, the interface programming method may include the following steps:
S810:加载组件并构建VDOM树。S810: Load components and build a VDOM tree.
电子设备将先获取开发者通过声明式编程完成编译的组件,然后在声明式引擎解析各个组件,进而将各个组件在VDOM中生成对应的节点,最终得到包含各个节点及其节点之间的关系的VDOM树。The electronic device will first obtain the components compiled by the developer through declarative programming, and then parse each component in the declarative engine, and then generate corresponding nodes for each component in VDOM, and finally obtain a file containing each node and the relationship between nodes. VDOM tree.
其中,该组件可接收外部传入的数据或者属性,例如该组件可以为一个按钮,该按钮能基于获取到的用户点击操作,对个别显示进行调整。并且电子设备还会给组件创建生命周期事件中的创建前事件(beforecreate),其中,生命周期指一个组件从创建到销毁过程的一些关键事件,开发者可自由选择在这些时期是否进行相应的业务处理,常用的事件包括“创建完成”(created)或“销毁完成”(destroyed)两个事件。Wherein, the component can receive data or attributes passed in from the outside. For example, the component can be a button, and the button can adjust individual displays based on the obtained user click operation. And the electronic device will also create a pre-create event (beforecreate) in the life cycle event for the component. The life cycle refers to some key events in the process of a component from creation to destruction. Developers can freely choose whether to carry out corresponding business during these periods Processing, commonly used events include "created" (created) or "destroyed completed" (destroyed) two events.
S820:监听节点数据变化,确定有数据变化的节点。S820: Monitor node data changes, and determine nodes with data changes.
电子设备将节点的属性在赋值中使用到的数据定义为响应式数据,进而该节点自动和该响应式数据建立绑定关系,当响应式数据发生了变化时,电子设备能自动去重算该节点的属性,进而通过进行了重算的数据就能直接确定有属性变更的节点,进而实现节点中属性变化的监控。电子设备通过响应式数据的变化就能监听到属性有修改的节点。The electronic device defines the data used in the assignment of the node's attributes as responsive data, and then the node automatically establishes a binding relationship with the responsive data. When the responsive data changes, the electronic device can automatically recalculate the data. The attributes of the nodes, and then through the recalculated data, the nodes with attribute changes can be directly determined, and then the monitoring of attribute changes in nodes can be realized. The electronic device can monitor the nodes whose attributes have been modified through the change of the responsive data.
举例来说,如图9所示,图9中的第2行和第3行将字符串name和字体大小myFontSize都定义为了响应式数据,组件BUILD在第8行定义了将名字(name)按myFontSize的大小进行显示以及在第9行定义了显示字符串name。因此,该组件BUILD使用了响应式数据字符串name和数值myFontSize,上述响应式数据将与组件BUILD建立绑定关系。并且,在组件BUILD中还定义一个可以更改myFontSize的值的按钮,当该按钮被按下时,myFontSize的值就会被更改,与myFontSize绑定的组件BUILD对应的节点则属于有数据变化的节点。For example, as shown in Figure 9, the second and third lines in Figure 9 define both the string name and the font size myFontSize as responsive data, and the component BUILD defines the name (name) in line myFontSize The size is displayed and the display string name is defined in
S830:根据节点的显示属性判定有增加和删除的节点。S830: Determine whether there are added or deleted nodes according to the display attributes of the nodes.
电子设备为每个节点增加了显示属性,电子设备将根据显示属性与该组件是否在界面中有被显示,来确定是否有新增加和删除的节点。当电子设备确定节点的显示属性表示为该节点会显示时,且界面中没有显示该节点对应的组件,那么该节点为新增的节点。当电子设备确定节点的显示属性为该节点不会显示时,且界面中有显示该节点对应的组件,那么该节点为删除的节点。The electronic device adds a display attribute to each node, and the electronic device will determine whether there is a newly added or deleted node according to the display attribute and whether the component is displayed in the interface. When the electronic device determines that the display attribute of the node indicates that the node will be displayed, and the component corresponding to the node is not displayed in the interface, then the node is a newly added node. When the electronic device determines that the display attribute of the node is that the node will not be displayed, and there is a component corresponding to the node displayed in the interface, then the node is a deleted node.
其中,当电子设备要删除某个节点时,不会直接将该节点在VDOM中删除,而会保留一个虚拟的节点,该节点的显示属性为不会显示该节点,以使电子设备能根据该节点的显示属性和界面是否有显示该节点对应的组件,来确定该节点是要被删除的。如果电子设备直接将该节点删除了,由于本方法不会将VDOM和原始VDOM进行比对,那么电子设备无法获取已被删除的节点,该节点对应的组件将一直在界面中显示。Wherein, when the electronic device wants to delete a certain node, it will not directly delete the node in the VDOM, but will retain a virtual node, and the display attribute of the node is not to display the node, so that the electronic device can Whether the display attribute of the node and the interface has a component corresponding to the node is displayed to determine whether the node is to be deleted. If the electronic device directly deletes the node, since this method does not compare the VDOM with the original VDOM, the electronic device cannot obtain the deleted node, and the component corresponding to the node will always be displayed on the interface.
举例来说,在一些实施中,给节点添加显示属性的具体代码可以参考图10。其中,参考图10中的第3行,定义了一个布尔变量showName,该变量默认值为true。然后参考第7行,将该变量作为显示属性添加到了组件BUILD中,并在第12行和第13行定了一个按钮,当该按钮被点击时,showName的值会改变,进而影响代码第8行和第9行中定义的内容的显示。其中,当showName的值为true的时候,会显示“Name:‘字符串name’”,当按下按钮“ToggleName”的时候,showName的值变为false,则“Name:‘字符串name’”将不会显示。For example, in some implementations, reference may be made to FIG. 10 for specific codes for adding display attributes to nodes. Wherein, referring to
在另一些实施例中,上述代码也可以按如图11所示的方式进行编写,其中,如图11中的第5行,通过if语句来判断是否显示对应的内容。该编写方式,在组件还有其他内容需要显示的情况下,还能通过添加else语句来定义其他功能。In some other embodiments, the above code can also be written in the manner shown in FIG. 11 , where, as in
S840:根据有数据变化的节点和有增加和删除的节点,渲染得到新的界面。S840: Render and obtain a new interface according to nodes with data changes and nodes with addition and deletion.
电子设备根据数据变化的节点和有增加和删除的节点,进而得到了VDOM中所有有更新的节点,然后通过调用这些节点API获取节点的数据,然后将有更新的节点在界面中渲染出来。The electronic device obtains all the updated nodes in the VDOM according to the nodes with data changes and the nodes that have been added and deleted, and then obtains the node data by calling the API of these nodes, and then renders the updated nodes in the interface.
综上所述,通过本申请提供的界面编程方法,能根据响应式数据确定有属性变化的节点,通过显示属性的值能确定节点的删除和增加,进而电子设备能获取到所有有变化的节点,然后对有变化的节点在界面中重新进行渲染。无需进行原始VDOM树和新的VDOM树的比较,就能确定有变化的节点,无需因为比较VDOM树给处理器带来较大开销。并且,本方法是根据响应式数据的绑定关系和显示属性的值来确定的有变化的节点的,不会存在原始VDOM树和新的VDOM树节点比较出错的问题,提升了界面更新的效率。To sum up, through the interface programming method provided by this application, the nodes with attribute changes can be determined according to the responsive data, the deletion and addition of nodes can be determined by displaying the value of the attributes, and then the electronic device can obtain all the changed nodes , and then re-render the changed nodes in the interface. Nodes with changes can be determined without comparing the original VDOM tree with the new VDOM tree, and there is no need to bring a large overhead to the processor due to the comparison of the VDOM tree. Moreover, this method determines the changed nodes based on the binding relationship of the responsive data and the value of the display attribute, and there will be no problem of comparing the original VDOM tree with the new VDOM tree node, which improves the efficiency of interface update .
在一些实施例中,如图12所示,该界面编程方法可以包括以下步骤:In some embodiments, as shown in Figure 12, the interface programming method may include the following steps:
S1201:加载组件。S1201: Load a component.
电子设备将先获取开发者通过声明式编程完成编译的组件,然后通过声明式引擎解析各个组件。The electronic device will first obtain the components compiled by the developer through declarative programming, and then parse each component through the declarative engine.
S1202:创建组件虚拟节点。S1202: Create a component virtual node.
电子设备通过各个组件的解析结果,将各个组件在VDOM中生成对应的节点,最终得到包含各个节点及其节点之间关系的VDOM树。The electronic device generates corresponding nodes for each component in the VDOM through the analysis results of each component, and finally obtains a VDOM tree including each node and the relationship between the nodes.
S1203:接收组件传入数据。S1203: Receive the incoming data from the component.
组件可接收外部传入的数据或者属性,例如该组件可以为一个按钮,该按钮能基于获取到的用户点击操作,对个别显示进行调整。A component can receive data or attributes passed in from the outside. For example, the component can be a button that can adjust individual displays based on the user's click operation obtained.
S1204:为节点创建生命周期。S1204: Create a life cycle for the node.
电子设备还会给组件创建生命周期事件中的创建前事件(beforecreate)。Electron also creates a beforecreate event in the lifecycle events for the component.
应理解,上述步骤S1201至步骤S1204的具体内容还可参考前述图8中关于步骤S810的相关描述,此处不再赘述。It should be understood that, for the specific content of the above step S1201 to step S1204, reference may also be made to the relevant description about step S810 in FIG. 8 , and details are not repeated here.
S1205:监听数据变化。S1205: Monitor data changes.
电子设备将节点的属性在赋值中使用到的数据定义为响应式数据,进而该节点自动将和该响应式数据建立绑定关系,电子设备将监听响应式数据是否发生了变化。The electronic device defines the data used in the assignment of the node's attributes as responsive data, and then the node will automatically establish a binding relationship with the responsive data, and the electronic device will monitor whether the responsive data has changed.
S1206:确定数据变化的节点。S1206: Determine the node where the data changes.
在电子设备监听到响应式数据发生了变化,电子设备能直接通过节点与响应式数据之间的绑定关系确定调用了该响应式数据的节点,进而实现节点中属性变化的监控。电子设备通过响应式数据的变化就能监听到属性有修改的节点。When the electronic device detects that the responsive data has changed, the electronic device can directly determine the node that calls the responsive data through the binding relationship between the node and the responsive data, thereby realizing the monitoring of the attribute change in the node. The electronic device can monitor the nodes whose attributes have been modified through the change of the responsive data.
S1207:对数据变化的节点进行重算。S1207: Recalculate the nodes whose data changes.
电子设备将把发生了变化的响应式数据代入节点中,重新确定节点的属性。The electronic device will substitute the changed responsive data into the node, and re-determine the attribute of the node.
S1208:开始监听节点数据使用。S1208: Start monitoring node data usage.
电子设备将在节点对属性进行赋值时开始监听节点数据使用,保证数据监听只在属性赋值过程中产生。The electronic device will start to monitor the use of node data when the node assigns a value to the attribute, so as to ensure that data monitoring is only generated during the attribute assignment process.
S1209:获取节点属性赋值。S1209: Obtain node attribute assignment.
电子设备将把更改后的数据赋值给节点的属性。其中,任何地方只要对响应式数据进行了修改,都将直接导致节点属性的异步重算,此处不使用同步重算是因为开发者可能同时变更多个数据,如果变更一次数据就重新运算一次节点,会产生较大开销。而在使用异步重算后,开发者就可以将需要变更的数据处理完后,一次性计算出受影响的所有节点,界面也只要一次就可以响应开发者的多个数据变更。Electronics will assign the changed data to the node's properties. Among them, as long as the responsive data is modified anywhere, it will directly lead to the asynchronous recalculation of the node attributes. Synchronous recalculation is not used here because the developer may change multiple data at the same time. If the data is changed once, it will be recalculated once. Nodes will incur a large overhead. After using asynchronous recalculation, the developer can calculate all the affected nodes at once after processing the data that needs to be changed, and the interface can respond to multiple data changes of the developer only once.
S1210:结束监听节点数据使用。S1210: End the data usage of the monitoring node.
电子设备将所有需要变更的数据都在节点的属性中对应完成重算后,就将结束监听节点数据使用。其中,完成计算后的数据也将用于下一次的数据监听以及用于本次界面更新,即用于步骤S1205和步骤S1220。After the electronic device has correspondingly recalculated all the data that needs to be changed in the properties of the node, it will end the use of the monitoring node data. Wherein, the calculated data will also be used for the next data monitoring and this interface update, that is, for step S1205 and step S1220.
应理解,上述步骤S1205至步骤S1207的具体内容还可参考前述图8中关于步骤S820的相关描述,此处不再赘述。It should be understood that, for the specific content of the above step S1205 to step S1207, reference may also be made to the related description of step S820 in FIG. 8 , which will not be repeated here.
S1211:确定是否显示该节点对应的组件。S1211: Determine whether to display the component corresponding to the node.
电子设备为每个节点增加了显示属性,电子设备将根据显示属性确定是否显示节点对应的组件。当显示属性表示不显示该节点对应的组件,即不展开该节点的时候,将执行步骤S1212。当显示属性表示显示该节点对应的组件,即展开该节点的时候,将执行步骤S1216。The electronic device adds a display attribute to each node, and the electronic device will determine whether to display the component corresponding to the node according to the display attribute. When the display attribute indicates that the component corresponding to the node is not displayed, that is, the node is not expanded, step S1212 will be executed. When the display attribute indicates to display the component corresponding to the node, that is, to expand the node, step S1216 will be executed.
例如,用vif表示显示属性,当“vif=true”时,表示该节点需要进行展开,即显示该节点,执行步骤S1216。当“vif=false”时,表示不会展开该节点,即在界面中不会显示该节点,即执行步骤S1212。For example, vif is used to indicate the display attribute, and when "vif=true", it means that the node needs to be expanded, that is, the node is displayed, and step S1216 is executed. When "vif=false", it means that the node will not be expanded, that is, the node will not be displayed in the interface, that is, step S1212 is executed.
S1212:确定该不显示的组件是否已经在界面中显示。S1212: Determine whether the component not to be displayed has already been displayed in the interface.
电子设备将先确定不会被展开的节点,即不显示的组件,是否在上一次渲染的界面中有显示。当该不被显示的组件没有在界面中显示时,表示该节点上一次也是没有展开的,即上一次界面渲染中就没有显示该组件,则认为该节点没有更新过显示属性。当该不被显示的组件在上一次界面渲染中有显示,表示该节点上一次是有展开的,该组件在界面中也有显示,则认为该节点更新过显示属性,将执行步骤S1213。The electronic device will first determine whether the nodes that will not be expanded, that is, the components that are not displayed, are displayed in the interface rendered last time. When the component that is not displayed is not displayed in the interface, it means that the node was not expanded last time, that is, the component was not displayed in the last interface rendering, and it is considered that the display property of the node has not been updated. When the component that is not displayed is displayed in the last interface rendering, it means that the node was expanded last time, and the component is also displayed in the interface, it is considered that the node has updated the display attribute, and step S1213 will be executed.
S1213:销毁可视节点。S1213: Destroy the visible node.
电子设备在确定该不被展开的节点上一次是有被展开时,即上一下界面中显示了该组件时,电子设备就将先删除该节点对应在界面上的可视节点,而在VDOM中可以保留该虚拟节点。When the electronic device determines that the node that is not to be expanded was expanded last time, that is, when the component is displayed in the previous interface, the electronic device will first delete the visible node corresponding to the node on the interface, and in the VDOM The virtual node can be reserved.
S1214:销毁该节点的子孙节点。S1214: Destroy the descendant nodes of the node.
由于该节点已被删除,则节点下的子孙节点也会一并被删除掉。Since the node has been deleted, the descendant nodes under the node will also be deleted.
S1215:结束该节点的生命周期。S1215: End the life cycle of the node.
同时,电子设备会在该节点的生命周期中产生生命周期事件“destroyed”。At the same time, the electronic device will generate a life cycle event "destroyed" in the life cycle of the node.
S1216:确定该需要显示的组件是否已经在界面中显示。S1216: Determine whether the component to be displayed has already been displayed in the interface.
电子设备在确定该节点时需要被展开,即会生成可视节点时,还会去确认该节点在上一次界面中是否有显示。如果已经有显示,表示该节点的显示属性没有发生变化,则直接执行步骤S1220:根据节点属性值显示节点内容。如果该节点在上一次界面中没有显示,则表示该节点是新添加的。The electronic device needs to be expanded when determining the node, that is, when a visible node is generated, it is also checked whether the node is displayed in the previous interface. If it has already been displayed, it means that the display attribute of the node has not changed, then directly execute step S1220: display the node content according to the node attribute value. If the node was not displayed in the previous interface, it means that the node is newly added.
S1217:创建可视节点。S1217: Create a visible node.
电子设备会对应创建一个该节点对应的可视节点,该可视节点时会在界面中显示的节点。The electronic device will correspondingly create a visible node corresponding to the node, and the visible node will be a node displayed in the interface.
S1218:加载虚拟子节点。S1218: Load the virtual child node.
电子设备在创建可视节点后,还将在VDOM中添加该节点的子节点等。After the electronic device creates a visible node, it will also add child nodes of the node to the VDOM.
S1219:为该节点创建生命周期。S1219: Create a lifecycle for the node.
当所有节点加载完毕之后,电子设备还将产生组件生命周期事件“created”。When all nodes are loaded, the electronic device will also generate a component lifecycle event "created".
应理解,上述步骤S1211至步骤S1219的具体内容还可参考前述图8中关于步骤S830的相关描述,此处不再赘述。It should be understood that, for the specific content of the above step S1211 to step S1219, reference may also be made to the related description of step S830 in FIG. 8 , which will not be repeated here.
S1220:根据节点属性值显示节点内容。S1220: Display node content according to the node attribute value.
电子设备根据数据变化的节点和有增加和删除的节点,进而得到了VDOM中所有更新的节点,然后通过调用这些节点API获取节点的数据,然后将有更新的节点在界面中渲染出来。The electronic device obtains all the updated nodes in the VDOM according to the nodes with data changes and the nodes with additions and deletions, and then obtains the data of the nodes by calling APIs of these nodes, and then renders the updated nodes in the interface.
应理解,上述步骤S1220的具体内容还可参考前述图8中关于步骤S840的相关描述,此处不再赘述。It should be understood that, for the specific content of the above step S1220, reference may also be made to the related description of the step S840 in FIG. 8 above, which will not be repeated here.
综上所述,通过本申请提供的界面编程方法,能根据响应式数据确定有属性变化的节点,通过显示属性的值能确定节点的删除和增加,进而电子设备能获取到所有有变化的节点,然后对有变化的节点在界面中重新进行渲染。无需进行原始VDOM树和新的VDOM树的比较,就能确定有变化的节点,无需因为比较VDOM树给处理器带来较大开销。并且,本方法是根据响应式数据的绑定关系和显示属性的值来确定的有变化的节点的,不会存在原始VDOM树和新的VDOM树节点比较出错的问题,提升了界面更新的效率。To sum up, through the interface programming method provided by this application, the nodes with attribute changes can be determined according to the responsive data, the deletion and addition of nodes can be determined by displaying the value of the attributes, and then the electronic device can obtain all the changed nodes , and then re-render the changed nodes in the interface. Nodes with changes can be determined without comparing the original VDOM tree with the new VDOM tree, and there is no need to bring a large overhead to the processor due to the comparison of the VDOM tree. Moreover, this method determines the changed nodes based on the binding relationship of the responsive data and the value of the display attribute, and there will be no problem of comparing the original VDOM tree with the new VDOM tree node, which improves the efficiency of interface update .
其中,如图13所示,图13示例性展示了一种情况下将界面编程方法监听节点数据变化监听节点数据变化,然后更新到视图,与原始VDOM模型的方法执行上述步骤进行性能测试,得到图13中的测试结果,其中,该界面编程方法触发界面数据改变事件(例如emit)的时间为0.073毫秒,重新计算当前节点的数值以及更新界面等(例如rebind、setnodevalue)操作的时间需花费0.093毫秒,即共耗时0.166毫秒。而原始VDOM模型触发界面数据改变的事件及其他操作(例如incoker、CallwithAsynchanding)需耗时0.78毫秒,比较VDOM树以及更新界面等操作(例如run)耗时0.88毫秒,即共耗时1.66毫秒。也即是说,本申请提高了界面更新的效率。Among them, as shown in Figure 13, Figure 13 exemplarily shows a situation where the interface programming method monitors node data changes, monitors node data changes, and then updates to the view, and performs the above steps with the original VDOM model method for performance testing, and obtains The test results in Figure 13, where the interface programming method triggers an interface data change event (such as emit) for 0.073 milliseconds, recalculating the value of the current node and updating the interface (such as rebind, setnodevalue) takes 0.093 milliseconds Milliseconds, that is, a total time of 0.166 milliseconds. The original VDOM model triggers interface data change events and other operations (such as incoker, CallwithAsynchanding) take 0.78 milliseconds, compares the VDOM tree and updates the interface and other operations (such as run) takes 0.88 milliseconds, that is, a total of 1.66 milliseconds. That is to say, the present application improves the efficiency of updating the interface.
下面再结合图14对显示属性变化引起的视图伸展和收缩进行详细描述,即对上述步骤S830以及步骤S1211至步骤S1219中进行详细描述,其中,视图伸展对应节点展开,显示节点对应的组件,视图收缩则对应节点销毁,不显示节点对应的组件。其中,以显示属性为vif,vif默认为true,vif更改后为false为例。Next, we will describe in detail the view stretching and shrinking caused by the change of display properties in conjunction with Fig. 14, that is, the above step S830 and step S1211 to step S1219 will be described in detail. Shrinking corresponds to the destruction of the node, and does not display the components corresponding to the node. Among them, the display attribute is vif, vif is true by default, and vif is changed to false as an example.
S1401:创建界面视图。电子设备先根据创建一个视图应用,即定义一个view。S1401: Create an interface view. The electronic device first creates a view application, that is, defines a view.
S1402:构建根组件。在view中定义出一个根组件,根组件用于挂载组件。S1402: Build the root component. A root component is defined in the view, and the root component is used to mount components.
S1403:创建组件。组件在创建之后,每个组件对应的节点即可绑定属性相关的数据,其中因为数据被定义为响应式数据,所以节点与数据之间能建立绑定关系。S1403: Create a component. After the component is created, the node corresponding to each component can bind the data related to the attribute. Since the data is defined as responsive data, a binding relationship can be established between the node and the data.
S1404:判断vif的值是否为true。vif默认为true,表示显示该组件,vif更改后为false,表示不显示该组件。当vif的值为true时,执行步骤S1407:逐个构建子节点。当vif的值为false时,执行步骤S1405:判断节点是否已创建可视节点。S1404: Determine whether the value of vif is true. The default value of vif is true, indicating that the component is displayed, and vif is changed to false, indicating that the component is not displayed. When the value of vif is true, step S1407 is executed: building child nodes one by one. When the value of vif is false, execute step S1405: determine whether the node has created a visible node.
S1405:判断节点是否已创建可视节点。电子设备将先确定不会被展开的节点,即不显示的组件,是否在上一次渲染的界面中有显示。当节点已创建可视节点,则执行步骤S1406:销毁所有子孙可视节点。S1405: Determine whether the node has created a visible node. The electronic device will first determine whether the nodes that will not be expanded, that is, the components that are not displayed, are displayed in the interface rendered last time. When the node has created visible nodes, execute step S1406: destroy all descendant visible nodes.
S1406:销毁所有子孙可视节点。电子设备在确定该不被展开的节点上一次是有被展开时,即上一下界面中显示了该组件时,电子设备就将先删除该节点对应在界面上的可视节点,而在VDOM中可以保留该虚拟节点。S1406: Destroy all descendant visible nodes. When the electronic device determines that the node that is not to be expanded was expanded last time, that is, when the component is displayed in the previous interface, the electronic device will first delete the visible node corresponding to the node on the interface, and in the VDOM The virtual node can be reserved.
S1407:逐个构建子节点。当vif的值为true时,表示该组件将被展开,电子设备将逐个构建该组件下的各个子节点。S1407: Construct child nodes one by one. When the value of vif is true, it means that the component will be expanded, and the electronic device will build each child node under the component one by one.
S1408:判断子节点是否为组件。当子节点也为组件时,将按组件的创建方式进行处理,即执行步骤S1403及其后续操作,当子节点不是组件时,将执行步骤S1409:判断子节点的vif的值是否为true。S1408: Determine whether the child node is a component. When the child node is also a component, it will be processed according to the creation method of the component, that is, step S1403 and its subsequent operations will be executed. When the child node is not a component, step S1409 will be performed: determine whether the value of vif of the child node is true.
S1409:判断子节点的vif的值是否为true。当子节点的vif为true时,则执行步骤S1410:更新可视节点。当子节点的vif为false时,则执行步骤S1411:判断子节点是否已创建可视节点。S1409: Determine whether the value of vif of the child node is true. When the vif of the child node is true, step S1410 is performed: updating the visible node. When the vif of the child node is false, execute step S1411: determine whether the child node has created a visible node.
S1410:更新可视节点。根据数据变化给节点赋值,并在界面中更新该节点。S1410: Update the visible nodes. Assign values to nodes according to data changes, and update the nodes in the interface.
S1411:判断子节点是否已创建可视节点。电子设备将先确定子节点是否在上一次渲染的界面中有显示。当子节点已创建可视节点,则执行步骤S1412:销毁子可视节点。S1411: Determine whether a child node has created a visible node. The electronic device will first determine whether the child node is displayed in the last rendered interface. When the child node has created a visible node, execute step S1412: destroy the child visible node.
S1412:销毁子可视节点。电子设备在确定该子节点上一次是有被展开时,即上一下界面中显示了该节点时,电子设备就将先删除该节点对应在界面上的可视节点,而在VDOM中可以保留该虚拟节点。S1412: Destroy child visual nodes. When the electronic device determines that the child node was expanded last time, that is, when the node is displayed in the previous interface, the electronic device will first delete the visible node corresponding to the node on the interface, and the VDOM can retain the node. virtual node.
下面对上述显示属性变化引起的视图伸展和收缩进行举例说明。The stretching and shrinking of the view caused by the change of the above-mentioned display properties is illustrated below with an example.
如图15所示,图15示出了一种父组件中包含子组件的视图伸缩代码。其中,图15中第3行,定义了显示属性showSub,并给父组件的name("hello world")添加了该显示属性。父组件还定义了按钮Toggle Sub,该按钮可以改变showSub的值。子组件定义了父组件name("hello world")的显示大小,并定义了按钮"+FontSize"可以更改字体大小。As shown in Figure 15, Figure 15 shows a view scaling code in which a parent component contains a child component. Among them, the third line in Figure 15 defines the display attribute showSub, and adds this display attribute to the name ("hello world") of the parent component. The parent component also defines the button Toggle Sub, which can change the value of showSub. The child component defines the display size of the parent component name("hello world"), and defines the button "+FontSize" to change the font size.
因此,上述代码的VDOM树如图16所示,在默认情况下,SubComp的值为true,SubComp节点会展开,对应于该视图伸展,即显示"hello world"、按钮+FontSize以及按钮Toggle Sub。而在点击按钮Toggle Sub后,SubComp的值变为false,SubComp节点不会展开,对应于该视图收缩,只显示按钮Toggle Sub。在再次点击按钮Toggle Sub后,SubComp的值又变回为true,SubComp节点会展开,对应于该视图伸展,即再次显示显示"hello world"、按钮+FontSize以及按钮Toggle Sub。Therefore, the VDOM tree of the above code is shown in Figure 16. By default, the value of SubComp is true, and the SubComp node will be expanded, corresponding to the view expansion, that is, "hello world", button +FontSize and button Toggle Sub will be displayed. After clicking the button Toggle Sub, the value of SubComp becomes false, and the SubComp node will not expand, corresponding to the contraction of the view, only the button Toggle Sub is displayed. After clicking the button Toggle Sub again, the value of SubComp returns to true, and the SubComp node will be expanded, corresponding to the view extension, that is, "hello world", the button +FontSize and the button Toggle Sub will be displayed again.
这样,通过本申请提供的界面编程方法,通过显示属性的值能确定节点的删除和增加,进而电子设备能获取到有变化的节点,然后对有变化的节点在界面中重新进行渲染。无需进行原始VDOM树和新的VDOM树的比较,就能确定有变化的节点,无需因为比较VDOM树给处理器带来较大开销。并且,本方法是根据响应式数据的绑定关系和显示属性的值来确定的有变化的节点的,不会存在原始VDOM树和新的VDOM树节点比较出错的问题,提升了界面更新的效率。In this way, through the interface programming method provided by this application, the deletion and addition of nodes can be determined by displaying the value of the attribute, and then the electronic device can obtain the changed nodes, and then re-render the changed nodes in the interface. Nodes with changes can be determined without comparing the original VDOM tree with the new VDOM tree, and there is no need to bring a large overhead to the processor due to the comparison of the VDOM tree. Moreover, this method determines the changed nodes based on the binding relationship of the responsive data and the value of the display attribute, and there will be no problem of comparing the original VDOM tree with the new VDOM tree node, which improves the efficiency of interface update .
为了解决上述比对VDOM节点会花费较多时间,占用电子设备处理器的较多资源,且容易出现判断错误的问题,本申请基于VDOM提供了一种界面编程装置1700,包括显示单元1710、获取单元1720以及确定单元1730。In order to solve the above problems that comparing VDOM nodes will take more time, occupy more resources of the processor of the electronic device, and be prone to misjudgment, the present application provides an interface programming device 1700 based on VDOM, including a
显示单元1710用于显示第一页面,其中第一页面包括多个组件,多个组件中的每个组件至少对应一个节点,每个节点具有各自的属性值;获取单元1720用于获取到界面更新请求,确定单元1730用于确定出第一页面属性值发生变化的节点;显示单元1710还用于将属性值发生变化的节点进行更新,得到第二页面。The
在一些实施例中,节点的属性包括显示属性,显示属性用于指示是否显示节点对应的第一组件。In some embodiments, the attribute of the node includes a display attribute, and the display attribute is used to indicate whether to display the first component corresponding to the node.
在另一些实施例中,确定单元1730还用于确定出显示属性与第一页面不对应的节点,其中,显示属性与第一页面不对应包括:显示属性指示显示第一组件且第一页面中未显示第一组件;或者,显示属性指示不显示第一组件且第一页面中显示了第一组件。In some other embodiments, the determining
在另一些实施例中,还包括,确定单元1730还用于确定出第一属性发生变化的节点,其中,第一属性是根据第一变量确定的,第一变量关联第一属性的计算。In some other embodiments, the determining
在另一些实施例中,确定单元1730还用于基于节点中第一属性发生变化,自动重新计算节点的第一属性;确定单元1730还用于基于显示属性指示显示第一组件,根据重新计算第一属性后的节点,显示单元1710还用于在第二页面中显示节点对应的组件。In some other embodiments, the determining
在另一些实施例中,确定单元1730还用于根据多个节点的属性,创建可视节点树,可视节点树包括多个可视节点,多个可视节点中的每个可视节点都对应一个节点;显示单元1710还用于根据多个可视节点,显示第一页面。In some other embodiments, the determining
在另一些实施例中,显示单元1710还用于基于第一页面已显示第一组件,在第二视图中保持第一组件的显示;显示单元1710还用于基于第一页面未显示第一组件,在可视节点树中创建节点对应的可视节点,并根据可视节点在第二页面中显示第一组件。In some other embodiments, the
在另一些实施例中,在显示属性指示不显示第一组件的情况下,显示单元1710还用于基于第一页面未显示第一组件,在第二页面中保持第一页面的显示;显示单元1710还用于基于第一页面显示了第一组件,在可视节点树中删除节点对应的可视节点,并在第二页面中不显示第一组件。In some other embodiments, when the display attribute indicates that the first component is not displayed, the
在另一些实施例中,第一节点具有子节点,且显示属性指示显示第一组件的情况下,还包括:确定单元1730还用于基于子节点的显示属性,确定是否显示子节点对应的第一组件;显示单元1710还用于基于第一页面未显示第一组件且子节点的显示属性指示显示子节点对应的第二组件,在可视节点树中创建第一节点和子节点对应的可视节点,并根据第一可视节点在第二页面中显示第一组件和第二组件。In some other embodiments, when the first node has child nodes, and the display attribute indicates to display the first component, the determining
在另一些实施例中,第一节点具有子节点,且显示属性指示不显示第一组件的情况下,显示单元1710还用于基于第一页面未显示第一组件和子节点对应的第二组件,在第二页面中保持第一页面的显示;显示单元1710还用于基于第一页面显示了第一组件和第二组件,在可视节点树中删除第一节点和第二节点对应的可视节点,并在第二页面中不显示第一组件和第二组件。In some other embodiments, when the first node has child nodes, and the display attribute indicates that the first component is not displayed, the
这样,通过本申请提供的界面编程装置,能根据响应式数据确定有属性变化的节点,通过显示属性的值能确定节点的删除和增加,进而电子设备能获取到所有有变化的节点,然后对有变化的节点在界面中重新进行渲染。无需进行原始VDOM树和新的VDOM树的比较,就能确定有变化的节点,无需因为比较VDOM树给处理器带来较大开销。并且,本方法是根据响应式数据的绑定关系和显示属性的值来确定的有变化的节点的,不会存在原始VDOM树和新的VDOM树节点比较出错的问题,提升了界面更新的效率。In this way, through the interface programming device provided by this application, the nodes with attribute changes can be determined according to the responsive data, and the deletion and addition of nodes can be determined by displaying the value of the attributes, and then the electronic device can obtain all the nodes with changes, and then Changed nodes are re-rendered in the interface. Nodes with changes can be determined without comparing the original VDOM tree with the new VDOM tree, and there is no need to bring a large overhead to the processor due to the comparison of the VDOM tree. Moreover, this method determines the changed nodes based on the binding relationship of the responsive data and the value of the display attribute, and there will be no problem of comparing the original VDOM tree with the new VDOM tree node, which improves the efficiency of interface update .
上述详细阐述了本申请实施例的方法,为了便于更好的实施本申请实施例上述方案,相应地,下面还提供用于配合实施上述方案的相关设备。The method in the embodiment of the present application has been described in detail above. In order to facilitate better implementation of the above-mentioned solution in the embodiment of the present application, correspondingly, related equipment for cooperating with implementing the above-mentioned solution is also provided below.
图18是本申请提供的一种计算设备1800的结构示意图,该计算设备1800可以是前述内容中的界面编程装置800。如图18所示,计算设备1800包括:处理器1810、通信接口1820以及存储器1830。其中,处理器1810、通信接口1820以及存储器1830可以通过内部总线1840相互连接,也可通过无线传输等其他手段实现通信。本申请实施例以通过总线1840连接为例,总线1840可以是快捷外围部件互连标准(peripheral component interconnectExpress,PCIe)总线,或扩展工业标准结构(extended industry standard architecture,EISA)总线、统一总线(unified bus,Ubus或UB)、计算机快速链接(compute express link,CXL)、缓存一致互联协议(cache coherent interconnect for accelerators,CCIX)等。总线1840可以分为地址总线、数据总线、控制总线等。总线1840除包括数据总线之外,还可以包括电源总线、控制总线和状态信号总线等。但是为了清楚说明起见,在图中将各种总线都标为总线1840。FIG. 18 is a schematic structural diagram of a
处理器1810可以由至少一个通用处理器构成,例如中央处理器(CentralProcessing Unit,CPU),或者CPU和硬件芯片的组合。上述硬件芯片可以是专用集成电路(Application-Specific Integrated Circuit,ASIC)、可编程逻辑器件(ProgrammableLogic Device,PLD)或其组合。上述PLD可以是复杂可编程逻辑器件(ComplexProgrammable Logic Device,CPLD)、现场可编程门阵列(Field-Programmable GateArray,FPGA)、通用阵列逻辑(Generic Array Logic,GAL)或其任意组合。处理器1810执行各种类型的数字存储指令,例如存储在存储器1830中的软件或者固件程序,它能使计算设备1800提供多种服务。The
存储器1830用于存储程序代码,并由处理器1810来控制执行,以执行上述实施例中界面编程方法的处理步骤。程序代码中可以包括一个或多个软件模块,这一个或多个软件模块可以为图17实施例中提供的软件模块。The
需要说明的是,本实施例可以是通用的物理服务器实现的,例如,ARM服务器或者X86服务器,也可以是基于通用的物理服务器结合NFV技术实现的虚拟机实现的,虚拟机指通过软件模拟的具有完整硬件系统功能的、运行在一个完全隔离环境中的完整计算机系统,本申请不作具体限定。It should be noted that this embodiment can be implemented by a general physical server, for example, an ARM server or an X86 server, or it can be realized based on a general physical server combined with a virtual machine implemented by NFV technology. A virtual machine refers to a virtual machine simulated by software A complete computer system with complete hardware system functions and running in a completely isolated environment is not specifically limited in this application.
存储器1830可以包括易失性存储器(volatile memory),例如随机存取存储器(random access memory,RAM);存储器1830也可以包括非易失性存储器(non-volatilememory),例如只读存储器(read-only memory,ROM)、快闪存储器(flash memory)、硬盘(hard disk drive,HDD)或固态硬盘(solid-state drive,SSD);存储器1830还可以包括上述种类的组合。存储器1830可以存储有程序代码,具体执行图8实施例中的S810-步骤S840及其可选步骤,或者执行图12实施例中的S1201-步骤S1220及其可选步骤,这里不再进行赘述。The
通信接口1820可以为有线接口(例如以太网接口),可以为内部接口(例如高速串行计算机扩展总线(peripheral component interconnect express,PCIe)总线接口)、有线接口(例如以太网接口)或无线接口(例如蜂窝网络接口或使用无线局域网接口),用于与其他设备或模块进行通信。The
需要说明的,图18仅仅是本申请实施例的一种可能的实现方式,实际应用中,计算设备1800还可以包括更多或更少的部件,这里不作限制。关于本申请实施例中未示出或未描述的内容,可参见前述图8或者图12实施例中的相关阐述,这里不再赘述。It should be noted that FIG. 18 is only a possible implementation of the embodiment of the present application. In practical applications, the
应理解,图18所示的计算设备还可以是至少一个服务器构成的计算机集群,本申请不作具体限定。It should be understood that the computing device shown in FIG. 18 may also be a computer cluster composed of at least one server, which is not specifically limited in this application.
本申请实施例还提供一种计算机可读存储介质,计算机可读存储介质中存储有指令,当其在处理器上运行时,图8或者图12所示的方法流程得以实现。The embodiment of the present application also provides a computer-readable storage medium, where instructions are stored in the computer-readable storage medium, and when the instructions are run on a processor, the method flow shown in FIG. 8 or FIG. 12 is implemented.
本申请实施例还提供一种计算机程序产品,当计算机程序产品在处理器上运行时,图8或者图12所示的方法流程得以实现。An embodiment of the present application further provides a computer program product, and when the computer program product is run on a processor, the flow of the method shown in FIG. 8 or FIG. 12 is implemented.
上述实施例,可以全部或部分地通过软件、硬件、固件或其他任意组合来实现。当使用软件实现时,上述实施例可以全部或部分地以计算机程序产品的形式实现。所述计算机程序产品包括一个或多个计算机指令。在计算机上加载或执行所述计算机程序指令时,全部或部分地产生按照本发明实施例所述的流程或功能。所述计算机可以为通用计算机、专用计算机、计算机网络、或者其他可编程装置。所述计算机指令可以存储在计算机可读存储介质中,或者从一个计算机可读存储介质向另一个计算机可读存储介质传输,例如,所述计算机指令可以从一个网站站点、计算机、服务器或数据中心通过有线(例如同轴电缆、光纤、数字用户线(digital subscriber line,DSL)或无线(例如红外、无线、微波等)方式向另一个网站站点、计算机、服务器或数据中心进行传输。所述计算机可读存储介质可以是计算机能够存取的任何可用介质或者是包含一个或多个可用介质集合的服务器、数据中心等数据存储设备。所述可用介质可以是磁性介质(例如,软盘、硬盘、磁带)、光介质(例如,高密度数字视频光盘(digital video disc,DVD)、或者半导体介质。半导体介质可以是SSD。The above-mentioned embodiments may be implemented in whole or in part by software, hardware, firmware or other arbitrary combinations. When implemented using software, the above-described embodiments may be implemented in whole or in part in the form of computer program products. The computer program product includes one or more computer instructions. When the computer program instructions are loaded or executed on the computer, all or part of the processes or functions according to the embodiments of the present invention will be generated. The computer may be a general purpose computer, a special purpose computer, a computer network, or other programmable devices. The computer instructions may be stored in or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instructions may be transmitted from a website, computer, server or data center Transmission to another website site, computer, server or data center via wired (such as coaxial cable, optical fiber, digital subscriber line (DSL) or wireless (such as infrared, wireless, microwave, etc.). The computer The readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server, data center, etc. that contains one or more sets of available media. The available medium can be a magnetic medium (for example, a floppy disk, a hard disk, a magnetic tape, etc.) ), an optical medium (for example, a high-density digital video disc (digital video disc, DVD), or a semiconductor medium. The semiconductor medium may be an SSD.
以上所述,仅为本发明的具体实施方式,但本发明的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本发明揭露的技术范围内,可轻易想到各种等效的修改或替换,这些修改或替换都应涵盖在本发明的保护范围之内。因此,本发明的保护范围应以权利要求的保护范围为准。The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any person familiar with the technical field can easily think of various equivalents within the technical scope disclosed in the present invention. Modifications or replacements shall all fall within the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.
Claims (12)
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202211215395.8A CN115586897A (en) | 2022-09-30 | 2022-09-30 | An interface programming method, device and related equipment |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202211215395.8A CN115586897A (en) | 2022-09-30 | 2022-09-30 | An interface programming method, device and related equipment |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| CN115586897A true CN115586897A (en) | 2023-01-10 |
Family
ID=84773226
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202211215395.8A Pending CN115586897A (en) | 2022-09-30 | 2022-09-30 | An interface programming method, device and related equipment |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN115586897A (en) |
Citations (6)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20030188299A1 (en) * | 2001-08-17 | 2003-10-02 | Broughton Jeffrey M. | Method and apparatus for simulation system compiler |
| US20070097138A1 (en) * | 2005-11-01 | 2007-05-03 | Peter Sorotokin | Virtual view tree |
| US20080242295A1 (en) * | 2004-04-28 | 2008-10-02 | Zte Corporation | System and Method for Accomplishing Mobile Management of Fixed Network Switching Node |
| CN110262948A (en) * | 2019-04-26 | 2019-09-20 | 阿里巴巴集团控股有限公司 | Monitor method, device and the equipment of page data |
| CN114443108A (en) * | 2022-01-28 | 2022-05-06 | 中国建设银行股份有限公司 | Page updating method, device, equipment, medium and computer program product |
| CN114996619A (en) * | 2022-06-27 | 2022-09-02 | 平安科技(深圳)有限公司 | Page display method and device, computer equipment and storage medium |
-
2022
- 2022-09-30 CN CN202211215395.8A patent/CN115586897A/en active Pending
Patent Citations (6)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20030188299A1 (en) * | 2001-08-17 | 2003-10-02 | Broughton Jeffrey M. | Method and apparatus for simulation system compiler |
| US20080242295A1 (en) * | 2004-04-28 | 2008-10-02 | Zte Corporation | System and Method for Accomplishing Mobile Management of Fixed Network Switching Node |
| US20070097138A1 (en) * | 2005-11-01 | 2007-05-03 | Peter Sorotokin | Virtual view tree |
| CN110262948A (en) * | 2019-04-26 | 2019-09-20 | 阿里巴巴集团控股有限公司 | Monitor method, device and the equipment of page data |
| CN114443108A (en) * | 2022-01-28 | 2022-05-06 | 中国建设银行股份有限公司 | Page updating method, device, equipment, medium and computer program product |
| CN114996619A (en) * | 2022-06-27 | 2022-09-02 | 平安科技(深圳)有限公司 | Page display method and device, computer equipment and storage medium |
Non-Patent Citations (1)
| Title |
|---|
| 田力: "嵌入式可视化开发工具源代码编辑技术研究" * |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| CN104636139B (en) | One kind visualizes cross-platform mobile application exploitation and generation system | |
| CA2653887C (en) | Test script transformation architecture | |
| US7797627B2 (en) | Method and apparatus for providing a graphical user interface for creating and editing a mapping of a first structural description to a second structural description | |
| US10915585B2 (en) | Data store interface that facilitates distribution of application functionality across a multi-tier client-server architecture | |
| US20110131555A1 (en) | External programmatic interface for ios cli compliant routers | |
| US20150205778A1 (en) | Reducing programming complexity in applications interfacing with parsers for data elements represented according to a markup languages | |
| US20120110437A1 (en) | Style and layout caching of web content | |
| US20090077091A1 (en) | System for development and hosting of network applications | |
| US7739691B2 (en) | Framework for declarative expression of data processing | |
| CN113126990A (en) | Page development method, device, equipment and storage medium | |
| US20110314456A1 (en) | System and Method for Mapping Structured Document to Structured Data of Program Language and Program for Executing Its Method | |
| US20230060787A1 (en) | System and Method for Real-Time, Dynamic Creation, Delivery, and Use of Customizable Web Applications | |
| CN106354483B (en) | Data processing method and device and electronic equipment | |
| CN114077430A (en) | Interface generation method, device, electronic device and storage medium | |
| CN114995859A (en) | Page hot updating method, device, equipment and storage medium | |
| US7698694B2 (en) | Methods and systems for transforming an AND/OR command tree into a command data model | |
| US20170371852A1 (en) | System and method for in-browser editing | |
| EP2105837B1 (en) | Test script transformation analyzer with change guide engine | |
| CN110032694A (en) | Form of general use control implementation method suitable for network auditing system | |
| CN103593188B (en) | System and method for managing what-you-see-is-what-you-get menus of instrument | |
| CN120029606A (en) | Packaging method and system based on zero-code platform | |
| CN112988278B (en) | Meta file modification method and device of resource file, electronic equipment and storage medium | |
| CN115586897A (en) | An interface programming method, device and related equipment | |
| CN114661279A (en) | Method, system and computer equipment for extracting source code of page components | |
| CN112380142A (en) | Interface document management method and device and test 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 | ||
| RJ01 | Rejection of invention patent application after publication | ||
| RJ01 | Rejection of invention patent application after publication |
Application publication date: 20230110 |