CN118276856B - Application state management method and device, electronic equipment and storage medium - Google Patents
Application state management method and device, electronic equipment and storage medium Download PDFInfo
- Publication number
- CN118276856B CN118276856B CN202410703384.7A CN202410703384A CN118276856B CN 118276856 B CN118276856 B CN 118276856B CN 202410703384 A CN202410703384 A CN 202410703384A CN 118276856 B CN118276856 B CN 118276856B
- Authority
- CN
- China
- Prior art keywords
- application state
- event
- view
- application
- state management
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR 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; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/70—Software maintenance or management
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- General Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Human Computer Interaction (AREA)
- Stored Programmes (AREA)
Abstract
Description
技术领域Technical Field
本公开涉及软件开发技术领域,尤其涉及一种应用状态管理方法、装置、电子设备及存储介质。The present disclosure relates to the field of software development technology, and in particular to an application state management method, device, electronic device and storage medium.
背景技术Background Art
随着移动应用和桌面应用的复杂性增加,对应用状态管理的需求也随之增长。应用状态管理作为一种编程范式,可以让开发者更方便地管理应用的状态,即应用的数据和界面。应用状态管理的目的是让应用状态的变化更可预测,更易于追踪,更容易测试和调试。As the complexity of mobile and desktop applications increases, the need for application state management also grows. Application state management, as a programming paradigm, allows developers to more easily manage the state of the application, that is, the data and interface of the application. The purpose of application state management is to make the changes of application state more predictable, easier to track, and easier to test and debug.
现有技术如Vuex、Redux、SwiftUI、Combine等,在应用状态管理和响应式编程方面提供了强大的工具,但它们也存在一些局限性:Existing technologies such as Vuex, Redux, SwiftUI, Combine, etc. provide powerful tools for application state management and responsive programming, but they also have some limitations:
第一,语言和系统版本限制,SwiftUI和Combine是为Swift语言和较新的Apple操作系统版本设计的,这限制了它们在旧版本系统或非Swift环境中的应用,这意味着开发者在跨平台或支持旧版本系统时可能无法使用这些工具;First, language and system version restrictions. SwiftUI and Combine are designed for the Swift language and newer Apple operating system versions, which limits their application in older versions of the system or non-Swift environments. This means that developers may not be able to use these tools when cross-platform or supporting older versions of the system;
第二,状态管理的复杂性,Vuex和Redux提供了集中管理状态的能力,但在大型应用中,状态树可能变得庞大和复杂,增加了维护和追踪状态变化的难度,这种复杂性可能导致开发者在理解和维护状态逻辑时遇到困难;Second, the complexity of state management. Vuex and Redux provide the ability to centrally manage state, but in large applications, the state tree may become large and complex, increasing the difficulty of maintaining and tracking state changes. This complexity may cause developers to have difficulties in understanding and maintaining state logic;
第三,模板代码和样板代码:使用Vuex和Redux等库时,开发者经常需要编写大量的模板代码和样板代码,这不仅增加了开发时间,也可能导致代码冗余和难以维护;Third, template code and boilerplate code: When using libraries such as Vuex and Redux, developers often need to write a lot of template code and boilerplate code, which not only increases development time, but also may lead to code redundancy and difficulty in maintenance;
第四,性能限制,在处理大量数据或高频率更新时,Vuex和Redux等库可能会遇到性能瓶颈,因为每次状态更新都需要通过整个状态树,这可能导致不必要的渲染和性能下降。Fourth, performance limitations. Libraries such as Vuex and Redux may encounter performance bottlenecks when processing large amounts of data or high-frequency updates, because each state update needs to pass through the entire state tree, which may lead to unnecessary rendering and performance degradation.
总之,现有的应用状态管理框架或库往往过于复杂,使得开发者在理解和维护代码时面临挑战。In short, existing application state management frameworks or libraries are often too complex, making it challenging for developers to understand and maintain the code.
发明内容Summary of the invention
本公开提供一种应用状态管理方法、装置、电子设备及存储介质,以解决现有技术中,状态管理的效率低、开发流程复杂的技术问题。The present disclosure provides an application state management method, device, electronic device and storage medium to solve the technical problems of low state management efficiency and complex development process in the prior art.
本公开提供该发明内容部分以便以简要的形式介绍构思,这些构思将在后面的具体实施方式部分进行详细描述。该发明内容部分并不旨在标识要求保护的技术方案的关键特征或必要特征,也不旨在用于限制所要求保护的技术方案的范围。The present disclosure provides this invention summary section to introduce concepts in a brief form, which will be described in detail in the detailed implementation section below. This invention summary section is not intended to identify the key features or essential features of the technical solution claimed for protection, nor is it intended to be used to limit the scope of the technical solution claimed for protection.
为了解决上述技术问题,本公开提供一种应用状态管理方法,包括:In order to solve the above technical problems, the present disclosure provides an application state management method, including:
获取应用状态,其中,所述应用状态只能通过事件来触发更新;Get the application status, where the application status can only be updated by events;
创建一个或多个所述事件,定义所述事件的类型和处理逻辑;Create one or more events, and define the type and processing logic of the events;
响应于用户在视图中的操作,执行所述操作触发的所述事件;In response to the user's operation in the view, executing the event triggered by the operation;
更新所述应用状态,并渲染所述视图的界面。Update the application state and render the interface of the view.
为了解决上述技术问题,本公开还提供一种应用状态管理装置,所述应用状态管理装置包括:In order to solve the above technical problems, the present disclosure further provides an application state management device, the application state management device comprising:
事件分发器,用于响应用户在视图中的操作,触发对应的事件;Event dispatcher, used to respond to user operations in the view and trigger corresponding events;
状态变化器,用于接收所述事件,更新应用状态;A state mutator, used to receive the event and update the application state;
渲染器,用于根据更新后的所述应用状态,渲染所述视图的界面。A renderer is used to render the interface of the view according to the updated application state.
为了解决上述技术问题,本公开还提供一种电子设备,采用了如下所述的技术方案,包括:第二存储器和处理器,所述第二存储器中存储有计算机程序,所述处理器执行所述计算机程序时实现如前所述的方法。In order to solve the above technical problems, the present disclosure also provides an electronic device, which adopts the following technical solution, including: a second memory and a processor, wherein the second memory stores a computer program, and the processor implements the above method when executing the computer program.
为了解决上述技术问题,本公开还提供一种计算机可读存储介质,采用了如下所述的技术方案,包括:所述计算机可读存储介质上存储有计算机程序,所述计算机程序被处理器执行时实现如前所述的方法。In order to solve the above technical problems, the present disclosure also provides a computer-readable storage medium, which adopts the following technical solution, including: a computer program is stored on the computer-readable storage medium, and the computer program implements the above method when executed by a processor.
本公开的积极进步效果:The positive and progressive effects of this disclosure:
本公开的技术方案中,应用状态只能通过事件来触发更新,能够避免应用状态的共享和变异,提高应用状态的安全性和可测试性;通过定义事件,来对用户在视图中的操作进行响应;通过事件的执行更新应用状态,并根据应用状态的变化,对视图的界面进行渲染。本公开的应用状态管理方法的执行效率较高、开发流程较简单。In the technical solution disclosed in the present invention, the application state can only be updated by triggering events, which can avoid the sharing and mutation of the application state and improve the security and testability of the application state; by defining events, respond to the user's operations in the view; update the application state through the execution of events, and render the interface of the view according to the changes in the application state. The application state management method disclosed in the present invention has high execution efficiency and simple development process.
附图说明BRIEF DESCRIPTION OF THE DRAWINGS
图1为本公开一实施例提供的应用状态管理方法的流程图;FIG1 is a flow chart of an application state management method provided by an embodiment of the present disclosure;
图2为本公开一实施例提供的应用状态管理装置的示意图;FIG2 is a schematic diagram of an application state management device provided by an embodiment of the present disclosure;
图3为本公开一实施例提供的电子设备的示意图。FIG. 3 is a schematic diagram of an electronic device provided according to an embodiment of the present disclosure.
结合附图并参考以下具体实施方式,本公开各实施例的上述和其他特征、优点及方面将变得更加明显。贯穿附图中,相同或相似的附图标记表示相同或相似的元素。应当理解附图是示意性的,元件和元素不一定按照比例绘制。The above and other features, advantages and aspects of the embodiments of the present disclosure will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. Throughout the accompanying drawings, the same or similar reference numerals represent the same or similar elements. It should be understood that the drawings are schematic and that components and elements are not necessarily drawn to scale.
具体实施方式DETAILED DESCRIPTION
除非另有定义,本文所使用的所有的技术和科学术语与属于本公开的技术领域的技术人员通常理解的含义相同;本文中在申请的说明书中所使用的术语只是为了描述具体的实施例的目的,不是旨在于限制本公开;本公开的说明书和权利要求书及上述附图说明中的术语“包括”以及相应的任何变形,意图在于覆盖不排他的包含。本公开的说明书和权利要求书或上述附图中的术语“第一”、“第二”等是用于区别不同对象,而不是用于描述特定顺序。Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which the present disclosure belongs; the terms used in the specification of the application herein are only for the purpose of describing specific embodiments and are not intended to limit the present disclosure; the term "including" and any corresponding variations in the specification and claims of the present disclosure and the above-mentioned drawings are intended to cover non-exclusive inclusions. The terms "first", "second", etc. in the specification and claims of the present disclosure or the above-mentioned drawings are used to distinguish different objects, not to describe a specific order.
在本文中提及“实施例”意味着,结合实施例描述的特定特征、结构或特性可以包含在本公开的至少一个实施例中。在说明书中的各个位置出现该短语并不一定均是指相同的实施例,也不是与其它实施例互斥的独立的或备选的实施例。本领域技术人员显式地和隐式地理解的是,本文所描述的实施例可以与其它实施例相结合。Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present disclosure. The appearance of the phrase in various places in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
为了使本技术领域的人员更好地理解本公开的技术方案,下面将结合附图,对本公开实施例中的技术方案进行清楚、完整地描述。In order to enable those skilled in the art to better understand the technical solution of the present disclosure, the technical solution in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the accompanying drawings.
下面介绍本公开实施例的第一方面:应用状态管理方法。The following introduces the first aspect of the embodiment of the present disclosure: an application state management method.
图1为本公开实施例提供的应用状态管理方法的流程图。如图1所示,应用状态管理方法包括步骤S101-S104。Fig. 1 is a flow chart of an application state management method provided by an embodiment of the present disclosure. As shown in Fig. 1, the application state management method includes steps S101-S104.
S101,获取应用状态,其中,所述应用状态只能通过事件来触发更新。S101, obtaining application status, wherein the application status can only be updated by triggering an event.
本公开的实施例在该处需要说明的是,应用状态表示应用程序在某一时刻的数据状态。应用状态管理是指在软件开发中对应用状态(数据)的管理方法,包括应用状态的存储、更新和监控。应用状态可以是一个结构体,一个类,一个枚举,或者一个基本类型等。应用状态遵循值语义,即每次更新后都应该返回一个新的应用状态,而不是修改原来的应用状态,且应用状态只能通过事件来触发更新。由此,可以避免应用状态的共享和变异,提高应用状态的安全性和可测试性。即,本实施例中的应用状态被设计为只读,任何应用状态的变化都通过事件来触发更新,保证了应用状态的不可变性和函数式更新。It should be noted here that the embodiment of the present disclosure is that the application state represents the data state of the application at a certain moment. Application state management refers to the management method of application state (data) in software development, including the storage, update and monitoring of application state. The application state can be a structure, a class, an enumeration, or a basic type, etc. The application state follows value semantics, that is, a new application state should be returned after each update instead of modifying the original application state, and the application state can only be updated through events. In this way, the sharing and mutation of the application state can be avoided, and the security and testability of the application state can be improved. That is, the application state in this embodiment is designed to be read-only, and any change in the application state is triggered by an event to update, which ensures the immutability and functional update of the application state.
S102,创建一个或多个所述事件,定义所述事件的类型和处理逻辑。S102: Create one or more events, and define the type and processing logic of the events.
本公开的实施例在该处需要说明的是,事件是一个遵循事件协议的类型,可以是一个结构体,一个类,一个枚举,或者一个闭包等。事件可以分为两种类型,分别是更新应用状态的事件和执行操作的事件。更新应用状态的事件只用来更新应用状态,不执行任何其他操作。执行操作的事件可以执行一些异步或同步的操作,然后再更新应用状态。The embodiments of the present disclosure need to explain that an event is a type that complies with the event protocol, which can be a structure, a class, an enumeration, or a closure. Events can be divided into two types, namely events that update the application state and events that perform operations. Events that update the application state are only used to update the application state and do not perform any other operations. Events that perform operations can perform some asynchronous or synchronous operations and then update the application state.
S103,响应于用户在视图中的操作,执行所述操作触发的所述事件。S103: In response to the user's operation in the view, execute the event triggered by the operation.
本公开的实施例在该处需要说明的是,用户在视图中输入操作,例如,点击按钮或在输入框编辑文字等,触发对应的事件,并通过对事件进行处理,返回新的应用状态。It should be noted here that the embodiment of the present disclosure is that the user inputs an operation in the view, such as clicking a button or editing text in an input box, triggers a corresponding event, and returns to a new application state by processing the event.
S104,更新所述应用状态,并渲染所述视图的界面。S104, updating the application state and rendering the interface of the view.
本公开的实施例在该处需要说明的是,应用状态更新后,需要将更新后的应用状态通过视图反馈给用户。采用视图渲染技术将动态数据渲染到视图界面,能够为用户提供更为直观的响应结果。The embodiment of the present disclosure needs to explain that after the application state is updated, the updated application state needs to be fed back to the user through the view. Using the view rendering technology to render dynamic data to the view interface can provide users with a more intuitive response result.
进一步的,在本公开的一些实施例中,在执行步骤所述创建一个或多个所述事件,定义所述事件的类型和处理逻辑,可以通过但不局限于以下的方法实现,包括:Further, in some embodiments of the present disclosure, creating one or more events in the execution step and defining the type and processing logic of the event may be implemented by, but not limited to, the following methods, including:
定义第一类事件,用于接收所述应用状态,并返回更新后的所述应用状态;和/或,defining a first type of event for receiving the application state and returning an updated application state; and/or,
定义第二类事件,用于接收所述应用状态,执行附加处理,并返回更新后的所述应用状态。A second type of event is defined to receive the application state, perform additional processing, and return the updated application state.
本公开的实施例在该处需要说明的是,第一类事件可以通过事件变化器实现,事件变化器可以是一个纯函数,用于接收当前的应用状态,返回一个新的应用状态。第二类事件可以通过事件行为器实现,事件行为器可以是一个副作用函数,用于接收当前的应用状态和存储器的引用,执行一些额外的操作,例如,调用API,发送通知,存储数据等。The embodiments of the present disclosure need to explain that the first type of event can be implemented by an event mutator, which can be a pure function for receiving the current application state and returning a new application state. The second type of event can be implemented by an event actor, which can be a side effect function for receiving the current application state and a reference to a memory and performing some additional operations, such as calling an API, sending a notification, storing data, etc.
进一步的,在本公开的一些实施例中,所述应用状态管理方法还包括:Furthermore, in some embodiments of the present disclosure, the application state management method further includes:
响应于所述用户在所述视图中的所述操作,触发所述操作对应的中间件;In response to the operation of the user in the view, triggering middleware corresponding to the operation;
所述中间件接收所述应用状态和所述操作触发的所述事件,并配合实现所述应用状态的更新。The middleware receives the application state and the event triggered by the operation, and cooperates to implement the update of the application state.
本公开的实施例在该处需要说明的是,中间件是指在处理数据流或事件流程中插入的额外处理逻辑。中间件可以设定为一个可选的函数,用于接收当前的应用状态和事件作为参数,返回一个新的应用状态。中间件允许在处理数据或事件流程中插入额外的处理逻辑,而不需要修改主要的处理逻辑。在应用状态管理中,中间件通常用于在应用状态变化的过程中执行一些附加操作,如日志记录、错误处理、异步操作等。例如,在创建日志中间件时,可以定义loggingMiddleware函数,其接收两个参数:当前的应用状态和发生的事件,其作用是在应用状态变化之前打印出相关的信息,然后返回新的应用状态,此中间件不会改变应用状态,只是添加了日志记录的功能。在实际使用中,中间件会被插入到应用状态管理流程中的适当位置。例如,在状态管理库如Redux中,中间件会在派发事件和执行状态变化器之间被调用。由此,每当一个事件被派发,中间件就有机会在应用状态更新之前执行其逻辑。此外,中间件的优势在于可插拔性和可组合性。开发者可以根据需要选择添加或移除中间件,或者将多个中间件组合在一起,以增强应用的功能。这种模式提高了代码的可维护性和可扩展性,同时保持了核心逻辑的简洁性。The embodiments of the present disclosure need to be explained here that middleware refers to additional processing logic inserted in the processing data flow or event flow. Middleware can be set as an optional function for receiving the current application state and event as parameters and returning a new application state. Middleware allows additional processing logic to be inserted in the processing data or event flow without modifying the main processing logic. In application state management, middleware is usually used to perform some additional operations such as logging, error handling, asynchronous operations, etc. during the application state change process. For example, when creating a logging middleware, a loggingMiddleware function can be defined, which receives two parameters: the current application state and the event that occurred. Its function is to print out relevant information before the application state changes, and then return the new application state. This middleware does not change the application state, but only adds the logging function. In actual use, the middleware will be inserted into the appropriate position in the application state management process. For example, in a state management library such as Redux, the middleware will be called between dispatching events and executing state changers. Thus, whenever an event is dispatched, the middleware has the opportunity to execute its logic before the application state is updated. In addition, the advantages of middleware are pluggability and composability. Developers can choose to add or remove middleware as needed, or combine multiple middleware together to enhance the functionality of the application. This model improves the maintainability and scalability of the code while keeping the core logic simple.
进一步的,在本公开的一些实施例中,在执行步骤所述更新所述应用状态,并渲染所述视图的界面时,可以通过但不局限于以下的方法实现,包括:Further, in some embodiments of the present disclosure, when updating the application state and rendering the interface of the view in the execution step, it can be implemented by but not limited to the following methods, including:
将所述应用状态与所述视图双向绑定,以进行所述应用状态与所述视图之间的自动更新。The application state is bidirectionally bound to the view to perform automatic update between the application state and the view.
本公开的实施例在该处需要说明的是,应用状态和视图的双向绑定和自动更新,能够提高应用程序的响应性和用户体验。此外,在一些实施例中,还可以设置可观察对象,在响应式编程中,可观察对象是可以被订阅的,以便在应用状态变化时通知订阅者。The embodiments of the present disclosure need to be explained here that the two-way binding and automatic update of the application state and view can improve the responsiveness and user experience of the application. In addition, in some embodiments, an observable object can also be set. In responsive programming, an observable object can be subscribed to so as to notify the subscriber when the application state changes.
具体地,为实现应用状态和视图的双向绑定和自动更新,可引入响应式组件,使视图能够自动响应应用状态的变化,进而实现应用状态与视图之间的响应式更新。响应式组件的主要特性包括:第一,自动同步,当状态对象(如SVObservable)的值发生变化时,所有绑定到该状态的UI组件会自动更新,无需手动调用更新函数;第二,双向绑定,即不仅UI组件会响应应用状态的变化,用户对UI组件的操作也能反过来更新应用状态;第三,解耦合,应用状态管理逻辑与UI逻辑分离,使得代码更加清晰和易于维护。响应式组件的组件结构,例如,SVReactive和SVObservable。其中,SVReactive为一个泛型结构体,为任何对象提供响应式扩展的能力,其包含一个基础对象,并允许开发者定义与该对象相关的响应式属性;SVObservable为一个核心类,用于创建可观察的状态对象,其允许观察者订阅应用状态变化,并在应用状态更新时通知所有订阅者。采用响应式组件的优势至少包括:第一,响应式编程,通过响应式编程简化了状态到UI的同步过程,提高了开发效率;第二,泛型设计,泛型设计使得组件可以灵活地用于不同类型的应用状态管理,增强了组件的通用性;第三,协议遵循,通过遵循特定协议,确保了应用状态和事件的一致性和可预测性。Specifically, in order to achieve two-way binding and automatic update of application state and view, responsive components can be introduced to enable the view to automatically respond to changes in application state, thereby achieving responsive updates between application state and view. The main features of responsive components include: first, automatic synchronization, when the value of a state object (such as SVObservable) changes, all UI components bound to the state will be automatically updated without manually calling the update function; second, two-way binding, that is, not only will the UI components respond to changes in application state, but the user's operations on the UI components can also update the application state in turn; third, decoupling, the application state management logic is separated from the UI logic, making the code clearer and easier to maintain. The component structure of responsive components, for example, SVReactive and SVObservable. Among them, SVReactive is a generic structure that provides responsive extension capabilities for any object. It contains a base object and allows developers to define responsive properties related to the object; SVObservable is a core class used to create observable state objects, which allows observers to subscribe to application state changes and notify all subscribers when the application state is updated. The advantages of using responsive components include at least: first, responsive programming, which simplifies the synchronization process from state to UI and improves development efficiency; second, generic design, which allows components to be flexibly used for different types of application state management, enhancing the versatility of components; third, protocol compliance, which ensures the consistency and predictability of application states and events by following specific protocols.
下面对响应式组件的部分工作原理进行说明。The following is an explanation of some of the working principles of responsive components.
第一,数据流的响应式原理。响应式编程是一种面向数据流和变化传播的编程范式,在这种范式中,数据被视为随时间变化的流,而响应式组件的目的是对这些数据流进行监听和响应,当数据流中的数据发生变化时,所有依赖于这些数据的操作会自动执行,从而更新应用的状态和UI。First, the responsive principle of data flow. Responsive programming is a programming paradigm oriented towards data flow and change propagation. In this paradigm, data is regarded as a stream that changes over time, and the purpose of responsive components is to monitor and respond to these data streams. When the data in the data stream changes, all operations that depend on this data are automatically executed, thereby updating the application status and UI.
第二,SVObservable的核心。SVObservable类是响应式组件的核心,其封装了应用状态的当前值,并提供了订阅机制。开发者可以创建一个SVObservable实例来代表应用中的某个状态,然后通过订阅这个实例来监听应用状态的变化。Second, the core of SVObservable. The SVObservable class is the core of the responsive component, which encapsulates the current value of the application state and provides a subscription mechanism. Developers can create an SVObservable instance to represent a state in the application, and then subscribe to this instance to monitor changes in the application state.
第三,订阅和通知机制。当SVObservable的value属性被设置一个新值时,它会触发一个通知过程,此过程会遍历所有订阅者,并调用它们的更新函数。如此,任何绑定到这个SVObservable的UI组件都会收到应用状态变化的通知,并进行自动更新。Third, the subscription and notification mechanism. When the value property of SVObservable is set to a new value, it triggers a notification process, which traverses all subscribers and calls their update functions. In this way, any UI component bound to this SVObservable will receive notifications of application state changes and automatically update.
第四,绑定到UI组件。通过扩展UI组件,如UILabel或UIButton,响应式组件允许将SVObservable直接绑定到这些组件的属性上。这样,当SVObservable的值发生变化时,绑定的UI组件会自动更新其显示内容。当支持双向绑定时,不仅UI组件会响应应用状态的变化,用户对UI组件的操作也能反过来更新应用状态,此种方式适用在表单输入和实时数据展示等场景中,但并不局限于此。Fourth, bind to UI components. By extending UI components such as UILabel or UIButton, responsive components allow SVObservable to be directly bound to the properties of these components. In this way, when the value of SVObservable changes, the bound UI component will automatically update its display content. When two-way binding is supported, not only will the UI component respond to changes in the application state, but the user's operations on the UI component can also in turn update the application state. This method is applicable to scenarios such as form input and real-time data display, but it is not limited to this.
在一个或多个实施例中,例如通过一个微服务架构,其中每个服务负责应用的一个特定部分的状态管理,使用事件总线来传递状态更新,以实现异步更新状态,减少性能瓶颈。首先,确定应用程序的不同部分,并为每个部分创建一个微服务,每个微服务都有自己的责任范围和状态管理逻辑;为系统中可能发生的每种类型的状态变化定义一个事件,这里,事件应该包含所有必要的信息,以便其他服务可以理解和响应;选择一个适合的事件总线技术,配置事件总线以支持高吞吐量和可靠的消息传递;微服务不应该直接调用彼此,而是应该通过事件总线发布和订阅事件,当一个服务需要更新状态时,它会发布一个事件到事件总线;每个微服务都应该有一个事件处理器来监听事件总线上的事件,当事件处理器接收到一个事件时,它会根据事件的类型和内容更新本地状态;微服务之间的状态同步应该通过事件来完成,当一个服务的状态更新后,发布一个事件来通知其他服务;事件处理通常应该是异步的,这样可以避免阻塞操作和减少延迟,异步处理也有助于提高系统的整体性能和可伸缩性。In one or more embodiments, for example, through a microservice architecture, each service is responsible for the state management of a specific part of the application, and an event bus is used to transmit state updates to achieve asynchronous state updates and reduce performance bottlenecks. First, identify the different parts of the application and create a microservice for each part, each microservice has its own scope of responsibility and state management logic; define an event for each type of state change that may occur in the system, where the event should contain all the necessary information so that other services can understand and respond; select a suitable event bus technology and configure the event bus to support high throughput and reliable messaging; microservices should not call each other directly, but should publish and subscribe to events through the event bus. When a service needs to update the state, it publishes an event to the event bus; each microservice should have an event processor to listen to events on the event bus. When the event processor receives an event, it updates the local state according to the type and content of the event; state synchronization between microservices should be completed through events. When the state of a service is updated, an event is published to notify other services; event processing should usually be asynchronous, which can avoid blocking operations and reduce delays. Asynchronous processing also helps improve the overall performance and scalability of the system.
在一个或多个实施例中,例如通过实现状态快照功能,允许开发者在任何时间点捕获应用状态,以及开发时间旅行调试工具,使开发者能够回溯到状态变化的历史,以便更容易地追踪和调试。在应用的状态管理系统中,引入快照服务,可以在任何给定时间点捕获和存储应用的完整状态。这里,快照例如包含所有权限内合法的相关状态信息,如用户数据、应用设置、UI状态等;通过提供一个API或界面,允许开发者手动或自动创建状态快照,通过时间旅行调试工具,可以让开发者浏览和加载之前创建的状态快照,该工具提供一个用户友好的界面,显示状态变化的时间线和详细信息,通过选择一个特定的快照,应用程序将恢复到该时间点的状态,以便进行调试;将状态快照和时间旅行调试功能集成到开发环境中,在开发过程中,开发者可以随时创建快照,并在出现问题时使用时间旅行调试工具。In one or more embodiments, for example, by implementing a state snapshot function, developers are allowed to capture the application state at any point in time, and by developing a time travel debugging tool, developers are able to trace back to the history of state changes for easier tracking and debugging. In the application's state management system, a snapshot service is introduced to capture and store the complete state of the application at any given point in time. Here, the snapshot, for example, contains all legal relevant state information within all permissions, such as user data, application settings, UI status, etc.; by providing an API or interface, developers are allowed to manually or automatically create state snapshots, and through the time travel debugging tool, developers can browse and load previously created state snapshots. The tool provides a user-friendly interface that displays the timeline and details of state changes. By selecting a specific snapshot, the application will be restored to the state at that point in time for debugging; the state snapshot and time travel debugging functions are integrated into the development environment. During the development process, developers can create snapshots at any time and use the time travel debugging tool when problems arise.
在一个或多个实施例中,例如使用声明式编程范式来定义状态和视图的关系,使状态的变化自动反映在视图上,并且开发一个状态绑定库,允许开发者以声明方式将应用状态绑定到视图组件。这里,在声明式编程中,只需描述应用的状态和界面应该如何根据这些状态展示,而不需要指定如何从一个状态转换到另一个状态,状态的变化自动反映在视图上,因为视图是状态的直接映射;通过创建一个库,提供一套API,允许开发者声明状态变量,并将它们绑定到视图组件;这里,状态变量的任何更改都应该自动触发视图的更新;这里还需要确保库能够处理组件的响应式更新,当状态变化时,只有依赖于这些状态的组件会更新,避免不必要的渲染。In one or more embodiments, for example, a declarative programming paradigm is used to define the relationship between states and views, so that changes in states are automatically reflected in views, and a state binding library is developed to allow developers to bind application states to view components in a declarative manner. Here, in declarative programming, it is only necessary to describe how the application state and interface should be displayed based on these states, without specifying how to convert from one state to another. Changes in state are automatically reflected in the view because the view is a direct mapping of the state; by creating a library, a set of APIs are provided to allow developers to declare state variables and bind them to view components; here, any changes in state variables should automatically trigger updates to the view; it is also necessary to ensure that the library can handle responsive updates of components. When the state changes, only components that depend on these states will be updated to avoid unnecessary rendering.
下面介绍本公开实施例的第二方面:应用状态管理装置。The second aspect of the embodiment of the present disclosure is introduced below: an application state management device.
图2为本公开实施例提供的应用状态管理装置的示意图。如图2所示,应用状态管理装置设置于第一存储器200内,所述应用状态管理装置包括:FIG2 is a schematic diagram of an application state management device provided by an embodiment of the present disclosure. As shown in FIG2 , the application state management device is set in the first memory 200, and the application state management device includes:
事件分发器202,用于响应用户在视图201中的操作,触发对应的事件205;An event dispatcher 202 is used to respond to a user's operation in the view 201 and trigger a corresponding event 205;
状态变化器206,用于接收所述事件205,更新应用状态208;A state changer 206, configured to receive the event 205 and update the application state 208;
渲染器209,用于根据更新后的所述应用状态208,渲染所述视图201的界面。The renderer 209 is used to render the interface of the view 201 according to the updated application state 208 .
本公开的实施例在该处需要说明的是,在状态管理中,第一存储器200是一个集中管理应用状态208的容器,能够确保应用状态208的一致性和可追踪性。第一存储器200是一个泛型类,能够接受两个类型的参数,分别为应用状态208和事件205。第一存储器200通过调用事件分发器202进行操作,事件分发器202能够接收事件205等作为参数,然后调用状态变化器206。其中,状态变化器206为一个可选的函数,用于接收当前的应用状态208和事件205作为参数,并返回一个新的应用状态208。状态变化器206可以用来实现一些通用的状态变化逻辑,比如合并,过滤,排序等。状态变化器206能够在应用状态208变化时提供一致和可预测的逻辑,有助于简化状态管理逻辑,使其更容易理解和维护。执行完事件205后返回更新后的应用状态208,并调用渲染器209根据更新后的应用状态208来更新视图201的界面。其中,渲染器209为一个可选的函数,用于接收当前的应用状态208和事件205作为参数,并根据应用状态208的变化,更新视图201的界面显示。渲染器209可以使用任何的视图框架或库,如UIKit,SwiftUI,React Native等,来实现界面的渲染。本公开的应用状态管理装置的工作流程确保了数据流是单向的,从视图201到第一存储器200,再通过应用状态208更新回到视图201,形成一个整体的闭环。这种模式有助于维护应用状态208的一致性,便于开发者理解和追踪应用状态208的变化,同时也便于对应用状态管理装置进行测试和调试。进一步地,本实施例中的渲染器209和状态变化器206被设计为允许开发者以声明式的方式描述应用状态208的变化和视图201的更新。此外,本实施例提供的应用状态管理装置是一个独立的装置,有利于增强代码的可移植性和在不同环境下的适用性。It should be noted here that in the embodiment of the present disclosure, in state management, the first storage 200 is a container for centrally managing the application state 208, which can ensure the consistency and traceability of the application state 208. The first storage 200 is a generic class that can accept two types of parameters, namely the application state 208 and the event 205. The first storage 200 operates by calling the event distributor 202, which can receive the event 205 and the like as parameters, and then calls the state mutator 206. Among them, the state mutator 206 is an optional function for receiving the current application state 208 and the event 205 as parameters, and returning a new application state 208. The state mutator 206 can be used to implement some common state change logic, such as merging, filtering, sorting, etc. The state mutator 206 can provide consistent and predictable logic when the application state 208 changes, which helps to simplify the state management logic and make it easier to understand and maintain. After executing event 205, the updated application state 208 is returned, and the renderer 209 is called to update the interface of view 201 according to the updated application state 208. Among them, renderer 209 is an optional function for receiving the current application state 208 and event 205 as parameters, and updating the interface display of view 201 according to the change of application state 208. Renderer 209 can use any view framework or library, such as UIKit, SwiftUI, React Native, etc., to implement interface rendering. The workflow of the application state management device disclosed in the present invention ensures that the data flow is unidirectional, from view 201 to the first memory 200, and then updated back to view 201 through the application state 208, forming an overall closed loop. This mode helps to maintain the consistency of application state 208, facilitates developers to understand and track changes in application state 208, and also facilitates testing and debugging of the application state management device. Furthermore, the renderer 209 and the state mutator 206 in this embodiment are designed to allow developers to describe the changes of the application state 208 and the updates of the view 201 in a declarative manner. In addition, the application state management device provided in this embodiment is an independent device, which is conducive to enhancing the portability of the code and the applicability in different environments.
进一步的,在本公开的一些实施例中,所述应用状态管理装置还包括:Furthermore, in some embodiments of the present disclosure, the application state management device further includes:
事件变化器204,用于接收所述应用状态208,并返回更新后的所述应用状态208;An event mutator 204, configured to receive the application state 208 and return the updated application state 208;
事件行为器203,用于接收所述应用状态208,执行附加处理,并返回更新后的所述应用状态208。The event actor 203 is used to receive the application state 208 , perform additional processing, and return the updated application state 208 .
本公开的实施例在该处需要说明的是,事件变化器204可以是一个纯函数,用于接收当前的应用状态208,返回一个新的应用状态208。事件行为器203可以是一个副作用函数,用于接收当前的应用状态208和第一存储器200的引用,执行一些额外的操作,例如,调用API,发送通知,存储数据等。It should be noted here that the embodiment of the present disclosure is that the event mutator 204 can be a pure function, which is used to receive the current application state 208 and return a new application state 208. The event actor 203 can be a side effect function, which is used to receive the current application state 208 and a reference to the first memory 200, and perform some additional operations, such as calling an API, sending a notification, storing data, etc.
进一步的,在本公开的一些实施例中,所述应用状态管理装置还包括:Furthermore, in some embodiments of the present disclosure, the application state management device further includes:
中间件207,用于接收所述应用状态208和所述操作触发的所述事件205,并配合实现所述应用状态208的更新。The middleware 207 is used to receive the application state 208 and the event 205 triggered by the operation, and cooperate to implement the update of the application state 208.
本公开的实施例在该处需要说明的是,中间件207在软件架构中,允许在处理数据或事件205流程中插入额外的处理逻辑,而不需要修改主要的处理逻辑。中间件207为一个可选的函数,用于接收当前的应用状态208和事件205作为参数,返回一个新的应用状态208。中间件207可以用来实现一些额外的功能,例如,日志、缓存、异步操作等。在实际使用中,中间件207会被插入到状态管理流程中的适当位置。例如,在状态管理装置中,中间件207会在派发事件205和执行状态变化器206之间被调用,这样,每当一个事件205被派发,中间件207就有机会在状态更新之前执行其逻辑。中间件207的优势在于它的可插拔性和可组合性。开发者可以根据需要选择添加或移除中间件207,或者将多个中间件207组合在一起,以增强应用的功能。这种模式提高了代码的可维护性和可扩展性,同时保持了核心逻辑的简洁性。The embodiment of the present disclosure needs to be explained here that the middleware 207 allows the insertion of additional processing logic in the process of processing data or event 205 in the software architecture without modifying the main processing logic. The middleware 207 is an optional function for receiving the current application state 208 and event 205 as parameters and returning a new application state 208. The middleware 207 can be used to implement some additional functions, such as logging, caching, asynchronous operations, etc. In actual use, the middleware 207 will be inserted into the appropriate position in the state management process. For example, in the state management device, the middleware 207 will be called between the dispatch event 205 and the execution state changer 206, so that whenever an event 205 is dispatched, the middleware 207 has the opportunity to execute its logic before the state is updated. The advantage of the middleware 207 is its pluggability and composability. Developers can choose to add or remove the middleware 207 as needed, or combine multiple middleware 207 together to enhance the functionality of the application. This pattern improves code maintainability and extensibility while keeping the core logic concise.
进一步的,在本公开的一些实施例中,所述应用状态管理装置还包括:Furthermore, in some embodiments of the present disclosure, the application state management device further includes:
响应式组件,用于将所述应用状态208与所述视图201双向绑定,以进行所述应用状态208与所述视图201之间的自动更新。A responsive component is used to bidirectionally bind the application state 208 to the view 201 to perform automatic update between the application state 208 and the view 201.
本公开的实施例在该处需要说明的是,响应式组件允许UI组件(例如,UILabel和UIButton)自动响应应用状态208的变化。通过将状态对象(例如,SVObservable)与UI组件绑定,开发者可以实现应用状态208和视图201的双向绑定和自动更新,从而提高应用程序的响应性和用户体验。It should be noted here that the embodiments of the present disclosure allow UI components (e.g., UILabel and UIButton) to automatically respond to changes in the application state 208. By binding a state object (e.g., SVObservable) to a UI component, a developer can implement two-way binding and automatic updating of the application state 208 and the view 201, thereby improving the responsiveness and user experience of the application.
本公开的应用状态管理装置可以让开发者方便地管理应用状态208,使用事件205驱动的方式来更新应用状态208,还可以使用中间件207来增加额外的功能。应用状态管理装置具有高度的复用性和灵活性,可以适应不同的应用场景和需求。应用状态管理装置采用了单向数据流的应用状态管理模式,可以保证应用状态208的变化是可控的,可追踪的,可测试的,可调试的。此外,应用状态管理装置可以使用swift的语法规范,使用协议和泛型来提高代码的复用性和灵活性。The application state management device disclosed in the present invention allows developers to conveniently manage the application state 208, update the application state 208 in an event 205 driven manner, and use middleware 207 to add additional functions. The application state management device is highly reusable and flexible, and can adapt to different application scenarios and requirements. The application state management device adopts an application state management mode of unidirectional data flow, which can ensure that the changes of the application state 208 are controllable, traceable, testable, and debuggable. In addition, the application state management device can use the syntax specification of Swift, and use protocols and generics to improve the reusability and flexibility of the code.
本公开实施例的应用状态管理装置的设计理念可以简要概括为以下几个方面:第一,单一数据源,即整个应用状态208被存储在一个单一的第一存储器200内,确保了应用状态208的一致性和可预测性;第二,应用状态208只读,即应用状态208作为不可变数据,只能通过事件205来请求更新,而不能直接被修改;第三,状态变化器206、事件205、中间件207执行更新,即应用状态208的更新是通过事件205触发的状态变化器206来完成的,中间件207提供了一个扩展点来增强或修改此过程。The design concept of the application state management device of the embodiment of the present disclosure can be briefly summarized as follows: first, a single data source, that is, the entire application state 208 is stored in a single first memory 200, which ensures the consistency and predictability of the application state 208; second, the application state 208 is read-only, that is, the application state 208, as immutable data, can only be requested to be updated through events 205, and cannot be directly modified; third, the state mutator 206, event 205, and middleware 207 perform updates, that is, the update of the application state 208 is completed by the state mutator 206 triggered by event 205, and the middleware 207 provides an extension point to enhance or modify this process.
此外,本公开实施例的应用状态管理装置的优势至少包括以下几个方面:第一,可预测性,由于所有的应用状态208的更新都是通过状态变化器206处理的,使得应用状态208的变化是可预测的,便于调试和测试;第二,模块化,第一存储器200、应用状态208和事件205的设计使得代码易于模块化,便于分离关注点,提高代码的可维护性;第三,中间件207的灵活性,中间件207不仅可以用于日志记录、异步操作等,还可以用于实现如撤销或重做等复杂的功能;第四,响应式绑定,通过将应用状态208绑定到视图201,可以实现应用状态208的响应式更新,当应用状态208变化时,视图201能够自动更新。In addition, the advantages of the application state management device of the embodiment of the present disclosure include at least the following aspects: First, predictability. Since all updates of the application state 208 are processed by the state mutator 206, the changes of the application state 208 are predictable, which is convenient for debugging and testing; Second, modularity. The design of the first memory 200, the application state 208 and the event 205 makes the code easy to modularize, which is convenient for separating concerns and improving the maintainability of the code; Third, the flexibility of the middleware 207. The middleware 207 can be used not only for logging, asynchronous operations, etc., but also for implementing complex functions such as undo or redo; Fourth, responsive binding. By binding the application state 208 to the view 201, the responsive update of the application state 208 can be realized. When the application state 208 changes, the view 201 can be automatically updated.
下面,对本公开的应用状态管理装置的具体应用进行举例说明,例如,通过应用状态管理装置实现一种计数器应用,能够增加、减少、重置计数器的值。首先,定义一个表示计数器的应用状态208的结构体,遵循值语义,实现Equatable协议,方便比较应用状态208的变化。然后,定义一个表示计数器的事件205的枚举,遵循事件协议,实现事件205的类型和行为,以及如何根据事件205来修改应用状态208。该枚举包含三种事件205,分别是增加,减少,重置计数器的值。每种事件205都定义了一个事件变化器204,用于接收当前的应用状态208,返回一个新的应用状态208。每种事件205也定义了一个事件行为器203,用于接收当前的应用状态208和第一存储器200的引用,执行一些额外的操作,比如打印日志,发送通知等。最后,创建第一存储器200的实例,传入初始的应用状态208,定义一个渲染器209来更新视图201的界面,定义一个状态变化器206来处理应用状态208的变化。在视图201中,根据用户的交互,触发相应的事件205,调用第一存储器200中的事件分发器202来更新应用状态208和视图201的界面。Below, the specific application of the application state management device disclosed in the present invention is illustrated by example. For example, a counter application is implemented through the application state management device, which can increase, decrease, and reset the value of the counter. First, a structure representing the application state 208 of the counter is defined, which follows the value semantics and implements the Equatable protocol to facilitate the comparison of changes in the application state 208. Then, an enumeration of events 205 representing the counter is defined, which follows the event protocol, implements the type and behavior of the event 205, and how to modify the application state 208 according to the event 205. The enumeration contains three types of events 205, which are to increase, decrease, and reset the value of the counter. Each event 205 defines an event mutator 204 for receiving the current application state 208 and returning a new application state 208. Each event 205 also defines an event actor 203 for receiving the current application state 208 and a reference to the first memory 200, and performing some additional operations, such as printing logs, sending notifications, etc. Finally, an instance of the first storage 200 is created, the initial application state 208 is passed in, a renderer 209 is defined to update the interface of the view 201, and a state mutator 206 is defined to handle the change of the application state 208. In the view 201, according to the user's interaction, the corresponding event 205 is triggered, and the event dispatcher 202 in the first storage 200 is called to update the application state 208 and the interface of the view 201.
在本公开实施例的应用状态管理装置的创建及执行过程中,第一存储器200的初始化是一个准备步骤,涉及到设置初始状态和配置状态管理的环境,虽然此步骤在应用启动时必须执行,但其不是每次状态变化时都需要进行的。中间件207的设置是一个辅助步骤,用于增强应用状态管理的功能,如添加日志记录或异步处理,这些通常在应用初始化时配置好,并不限定为数据处理的核心步骤。定义如何根据事件205更新应用状态208的逻辑是一个准备步骤,确保了状态变化的一致性和可预测性,此逻辑在应用开发阶段被定义,并在运行时被调用。将应用状态208绑定到UI的声明式更新可以为一个辅助步骤,用于确保UI能够响应应用状态208的变化,此步骤在组件创建时进行,而不是在每次数据处理中。实现事件协议并定义事件205如何触发应用状态208的变化可以是一个准备步骤,其为应用状态208的变化提供了规则和逻辑。应用状态208和事件205的测试是一个善后步骤,确保应用状态管理逻辑的正确性和稳定性,通常在开发过程中和应用发布前进行,而不是在实际的数据处理过程中,这是为了在应用发布前发现和修复潜在的问题,确保应用的质量。这些步骤虽然对于整个状态管理系统的建立和维护至关重要,但它们并不是每次应用状态变化或数据处理时都需要执行的步骤。相反,这些步骤为应用状态管理提供了必要的支持和基础设施,以确保核心的数据处理流程能够顺利进行。In the creation and execution process of the application state management device of the embodiment of the present disclosure, the initialization of the first memory 200 is a preparatory step, which involves setting the initial state and configuring the state management environment. Although this step must be performed when the application is started, it is not required to be performed every time the state changes. The setting of the middleware 207 is an auxiliary step used to enhance the function of application state management, such as adding logging or asynchronous processing, which are usually configured when the application is initialized and are not limited to the core steps of data processing. Defining the logic of how to update the application state 208 according to the event 205 is a preparatory step, which ensures the consistency and predictability of the state change. This logic is defined in the application development phase and called at runtime. The declarative update of binding the application state 208 to the UI can be an auxiliary step to ensure that the UI can respond to the change of the application state 208. This step is performed when the component is created, not in each data processing. Implementing the event protocol and defining how the event 205 triggers the change of the application state 208 can be a preparatory step, which provides rules and logic for the change of the application state 208. The testing of application state 208 and event 205 is a post-processing step to ensure the correctness and stability of the application state management logic. It is usually performed during the development process and before the application is released, rather than during the actual data processing process. This is to discover and fix potential problems before the application is released to ensure the quality of the application. Although these steps are crucial to the establishment and maintenance of the entire state management system, they are not steps that need to be performed every time the application state changes or data is processed. On the contrary, these steps provide the necessary support and infrastructure for application state management to ensure that the core data processing process can proceed smoothly.
下面介绍本公开实施例的第三方面和第四方面:电子设备和计算机可读存储介质。The third and fourth aspects of the embodiments of the present disclosure are introduced below: an electronic device and a computer-readable storage medium.
电子设备,包括第二存储器和处理器,所述第二存储器中存储有计算机程序,所述处理器执行所述计算机程序时实现上文所述的应用状态管理方法。The electronic device includes a second memory and a processor, wherein the second memory stores a computer program, and the processor implements the above-mentioned application state management method when executing the computer program.
计算机可读存储介质,所述计算机可读存储介质上存储有计算机程序,所述计算机程序被处理器执行时实现上文所述的应用状态管理方法。A computer-readable storage medium having a computer program stored thereon, wherein the computer program implements the above-mentioned application state management method when executed by a processor.
如图3所示,其示出了适于用来实现本公开实施例的电子设备的示意图。本公开实施例中的电子设备仅仅是一个示例,不应对本公开实施例的功能和使用范围带来任何限制。As shown in Figure 3, it shows a schematic diagram of an electronic device suitable for implementing the embodiment of the present disclosure. The electronic device in the embodiment of the present disclosure is only an example and should not bring any limitation to the function and scope of use of the embodiment of the present disclosure.
继续参照图3,电子设备包括处理装置301、存储装置302、传感器装置303、总线304、输入/输出(I/O)接口305、多媒体装置306、电源装置307以及通信装置308等。3 , the electronic device includes a processing device 301 , a storage device 302 , a sensor device 303 , a bus 304 , an input/output (I/O) interface 305 , a multimedia device 306 , a power supply device 307 , a communication device 308 , and the like.
处理装置301(例如中央处理器、图形处理器等),用于控制电子设备的整体操作。处理装置301可以包括一个或多个处理器来执行指令,以完成上述的方法的全部或部分步骤。此外,处理装置301还可以包括一个或多个模块,用于处理和其他装置之间的交互。The processing device 301 (e.g., a central processing unit, a graphics processing unit, etc.) is used to control the overall operation of the electronic device. The processing device 301 may include one or more processors to execute instructions to complete all or part of the steps of the above method. In addition, the processing device 301 may also include one or more modules for processing and interacting with other devices.
存储装置302,用于存储各种类型的数据,存储装置302可以是包括各种类型的计算机可读存储介质或者它们的组合,例如可以是电、磁、光、电磁、红外线、或半导体的系统、装置或器件,或者任意以上的组合。The storage device 302 is used to store various types of data. The storage device 302 may include various types of computer-readable storage media or a combination thereof, such as an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or component, or any combination of the above.
其中,计算机可读存储介质的更具体的例子可以包括但不限于:具有一个或多个导线的电连接、便携式计算机磁盘、硬盘、随机访问存储器(RAM)、只读存储器(ROM)、可擦式可编程只读存储器(EPROM或闪存)、光纤、便携式紧凑磁盘只读存储器(CD-ROM)、光存储器件、磁存储器件、或者上述的任意合适的组合。在本公开中,计算机可读存储介质可以是任何包含或存储程序的有形介质,该程序可以被指令执行系统、装置或者器件使用或者与其结合使用。Among them, more specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present disclosure, a computer-readable storage medium can be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, apparatus, or device.
传感器装置303,用于感受规定的被测量的信息并按照一定的规律转换成可用输出信号,可以包括一个或多个传感器。例如,其可以包括加速度传感器,陀螺仪传感器,磁传感器,压力传感器或温度传感器等,用于检测电子设备的打开/关闭状态、相对定位、加速/减速、温度、湿度和光线等的变化。The sensor device 303 is used to sense the specified measured information and convert it into a usable output signal according to a certain rule, and may include one or more sensors. For example, it may include an acceleration sensor, a gyroscope sensor, a magnetic sensor, a pressure sensor or a temperature sensor, etc., for detecting changes in the opening/closing state, relative positioning, acceleration/deceleration, temperature, humidity and light of the electronic device.
处理装置301、存储装置302以及传感器装置303通过总线304彼此相连。输入/输出(I/O)接口305也连接至总线304。The processing device 301 , the storage device 302 , and the sensor device 303 are connected to each other via a bus 304 . An input/output (I/O) interface 305 is also connected to the bus 304 .
多媒体装置306,可以包括触摸屏、触摸板、键盘、鼠标、摄像头、麦克风等的输入装置用以接收来自用户的输入信号,在各种输入装置可以与上述传感器装置的各种传感器配合完成例如手势操作输入、图像识别输入、距离检测输入等;多媒体装置还可以包括例如液晶显示器(LCD)、扬声器、振动器等的输出装置。The multimedia device 306 may include input devices such as a touch screen, a touchpad, a keyboard, a mouse, a camera, a microphone, etc. for receiving input signals from a user. The various input devices may cooperate with various sensors of the above-mentioned sensor devices to complete, for example, gesture operation input, image recognition input, distance detection input, etc. The multimedia device may also include output devices such as a liquid crystal display (LCD), a speaker, a vibrator, etc.
电源装置307,用于为电子设备中的各种装置提供电力,可以包括电源管理系统、一个或多个电源及为其他装置分配电力的组件。The power supply device 307 is used to provide power to various devices in the electronic device, and may include a power management system, one or more power supplies, and components for distributing power to other devices.
通信装置308,可以允许电子设备与其他设备进行无线或有线通信以交换数据。The communication device 308 may allow the electronic device to communicate with other devices wirelessly or by wire to exchange data.
上述各项装置也均可以连接至I/O接口305以实现电子设备的应用。The above-mentioned devices can also be connected to the I/O interface 305 to realize the application of the electronic device.
虽然图中示出了具有各种装置的电子设备,但是应理解的是,并不要求实施或具备所有示出的装置。可以替代地实施或具备更多或更少的装置。Although the electronic device with various devices is shown in the figure, it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead.
特别地,根据本公开的实施例,上文参考流程图描述的过程可以被实现为计算机软件程序。例如,本公开的实施例包括一种计算机程序产品,其包括承载在非暂态计算机可读介质上的计算机程序,该计算机程序包含用于执行流程图所示的方法的程序代码。在这样的实施例中,该计算机程序可以通过通信装置从网络上被下载和安装,或者从存储装置被安装。在该计算机程序被处理装置执行时,执行本公开实施例的方法中限定的上述功能。In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a non-transitory computer-readable medium, and the computer program contains a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device. When the computer program is executed by a processing device, the above-mentioned functions defined in the method of the embodiment of the present disclosure are executed.
在本公开的上下文中,机器可读介质可以是有形的介质,其可以包含或存储以供指令执行系统、装置或设备使用或与指令执行系统、装置或设备结合地使用的程序。In the context of the present disclosure, a machine-readable medium may be a tangible medium that can contain or store a program for use by or in connection with an instruction execution system, apparatus, or device.
要说明的是,本公开上述的计算机可读介质可以是计算机可读信号介质或者计算机可读存储介质或者是上述两者的任意组合。而在本公开中,计算机可读信号介质可以包括在基带中或者作为载波一部分传播的数据信号,其中承载了计算机可读的程序代码。这种传播的数据信号可以采用多种形式,包括但不限于电磁信号、光信号或上述的任意合适的组合。计算机可读信号介质还可以是计算机可读存储介质以外的任何计算机可读介质,该计算机可读信号介质可以发送、传播或者传输用于由指令执行系统、装置或者器件使用或者与其结合使用的程序。计算机可读介质上包含的程序代码可以用任何适当的介质传输,包括但不限于:电线、光缆、RF(射频)等等,或者上述的任意合适的组合。It should be noted that the computer-readable medium disclosed above may be a computer-readable signal medium or a computer-readable storage medium or any combination of the two. In the present disclosure, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. The computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate, or transmit a program for use by or in combination with an instruction execution system, device, or device. The program code contained on the computer-readable medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.
上述计算机可读介质可以是上述电子设备中所包含的;也可以是单独存在,而未装配入该电子设备中。The computer-readable medium may be included in the electronic device, or may exist independently without being installed in the electronic device.
进一步地,可以以一种或多种程序设计语言或其组合来编写用于执行本公开的操作的计算机程序代码,上述程序设计语言包括但不限于面向对象的程序设计语言,诸如Java、Python、C++,还包括常规的过程式程序设计语言,诸如“C”语言或类似的程序设计语言。程序代码可以完全地在用户计算机上执行、部分地在用户计算机上执行、作为一个独立的软件包执行、部分在用户计算机上部分在远程计算机上执行、或者完全在远程计算机或服务器上执行。在涉及远程计算机的情形中,远程计算机可以通过任意种类的网络连接到用户计算机,或者,可以连接到外部计算机(例如利用因特网服务提供商来通过因特网连接)。Further, computer program code for performing the operations of the present disclosure may be written in one or more programming languages or combinations thereof, including but not limited to object-oriented programming languages, such as Java, Python, C++, and conventional procedural programming languages, such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer via any type of network, or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
附图中的流程图和框图,图示了按照本公开各种实施例的系统、方法和计算机程序产品的可能实现的体系架构、功能和操作。在这点上,流程图或框图中的每个方框可以代表一个模块、程序段、或代码的一部分,该模块、程序段、或代码的一部分包含一个或多个用于实现规定的逻辑功能的可执行指令。也应当注意,在有些作为替换的实现中,方框中所标注的功能也可以以不同于附图中所标注的顺序发生。例如,两个接连地表示的方框实际上可以基本并行地执行,它们有时也可以按相反的顺序执行,这依所涉及的功能而定。也要注意的是,框图和/或流程图中的每个方框、以及框图和/或流程图中的方框的组合,可以用执行规定的功能或操作的专用的基于硬件的系统来实现,或者可以用专用硬件与计算机指令的组合来实现。The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some implementations as replacements, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and/or flow chart, and the combination of the square boxes in the block diagram and/or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
描述于本公开实施例中所涉及到的单元可以通过软件的方式实现,也可以通过硬件的方式来实现。其中,单元的名称在某种情况下并不构成对该单元本身的限定。The units involved in the embodiments described in the present disclosure may be implemented by software or hardware, wherein the name of a unit does not, in some cases, constitute a limitation on the unit itself.
本文中以上描述的功能可以至少部分地由一个或多个硬件逻辑部件来执行。例如,非限制性地,可以使用的示范类型的硬件逻辑部件包括:现场可编程门阵列(FPGA)、专用集成电路(ASIC)、专用标准产品(ASSP)、片上系统(SOC)、复杂可编程逻辑设备(CPLD)等等。The functions described above herein may be performed at least in part by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chip (SOCs), complex programmable logic devices (CPLDs), and the like.
下面,简要总结和列出上述根据本公开的实施例的特征。Below, the features of the above-mentioned embodiments according to the present disclosure are briefly summarized and listed.
根据本公开的一个或多个实施例,提供了一种应用状态管理方法,采用了如下所述的技术方案,包括:According to one or more embodiments of the present disclosure, a method for managing application status is provided, which adopts the following technical solution, including:
获取应用状态,其中,所述应用状态只能通过事件来触发更新;Get the application status, where the application status can only be updated by events;
创建一个或多个所述事件,定义所述事件的类型和处理逻辑;Create one or more events, and define the type and processing logic of the events;
响应于用户在视图中的操作,执行所述操作触发的所述事件;In response to the user's operation in the view, executing the event triggered by the operation;
更新所述应用状态,并渲染所述视图的界面。Update the application state and render the interface of the view.
根据本公开的一个或多个实施例,提供了一种应用状态管理方法,采用了如下所述的技术方案,所述创建一个或多个所述事件,定义所述事件的类型和处理逻辑,包括:According to one or more embodiments of the present disclosure, a method for managing application status is provided, which adopts the following technical solution, wherein the step of creating one or more events and defining the type and processing logic of the events includes:
定义第一类事件,用于接收所述应用状态,并返回更新后的所述应用状态;和/或,defining a first type of event for receiving the application state and returning an updated application state; and/or,
定义第二类事件,用于接收所述应用状态,执行附加处理,并返回更新后的所述应用状态。A second type of event is defined to receive the application state, perform additional processing, and return the updated application state.
根据本公开的一个或多个实施例,提供了一种应用状态管理方法,采用了如下所述的技术方案,所述应用状态管理方法还包括:According to one or more embodiments of the present disclosure, an application state management method is provided, which adopts the following technical solution, and the application state management method further includes:
响应于所述用户在所述视图中的所述操作,触发所述操作对应的中间件;In response to the operation of the user in the view, triggering middleware corresponding to the operation;
所述中间件接收所述应用状态和所述操作触发的所述事件,并配合实现所述应用状态的更新。The middleware receives the application state and the event triggered by the operation, and cooperates to implement the update of the application state.
根据本公开的一个或多个实施例,提供了一种应用状态管理方法,采用了如下所述的技术方案,所述更新所述应用状态,并渲染所述视图的界面,包括:According to one or more embodiments of the present disclosure, a method for managing application status is provided, which adopts the following technical solution, wherein updating the application status and rendering the interface of the view include:
将所述应用状态与所述视图双向绑定,以进行所述应用状态与所述视图之间的自动更新。The application state is bidirectionally bound to the view to perform automatic update between the application state and the view.
根据本公开的一个或多个实施例,提供了一种应用状态管理装置,采用了如下所述的技术方案,包括:According to one or more embodiments of the present disclosure, an application state management device is provided, which adopts the following technical solution, including:
事件分发器,用于响应用户在视图中的操作,触发对应的事件;Event dispatcher, used to respond to user operations in the view and trigger corresponding events;
状态变化器,用于接收所述事件,更新应用状态;A state mutator, used to receive the event and update the application state;
渲染器,用于根据更新后的所述应用状态,渲染所述视图的界面。A renderer is used to render the interface of the view according to the updated application state.
根据本公开的一个或多个实施例,提供了一种应用状态管理装置,采用了如下所述的技术方案,所述应用状态管理装置还包括:According to one or more embodiments of the present disclosure, an application state management device is provided, which adopts the following technical solution, and the application state management device also includes:
事件变化器,用于接收所述应用状态,并返回更新后的所述应用状态;An event mutator, configured to receive the application state and return the updated application state;
事件行为器,用于接收所述应用状态,执行附加处理,并返回更新后的所述应用状态。An event actor is used to receive the application state, perform additional processing, and return the updated application state.
根据本公开的一个或多个实施例,提供了一种应用状态管理装置,采用了如下所述的技术方案,所述应用状态管理装置还包括:According to one or more embodiments of the present disclosure, an application state management device is provided, which adopts the following technical solution, and the application state management device also includes:
中间件,用于接收所述应用状态和所述操作触发的所述事件,并配合实现所述应用状态的更新。The middleware is used to receive the application state and the event triggered by the operation, and cooperate to implement the update of the application state.
根据本公开的一个或多个实施例,提供了一种应用状态管理装置,采用了如下所述的技术方案,所述应用状态管理装置还包括:According to one or more embodiments of the present disclosure, an application state management device is provided, which adopts the following technical solution, and the application state management device also includes:
响应式组件,用于将所述应用状态与所述视图双向绑定,以进行所述应用状态与所述视图之间的自动更新。A responsive component is used to bidirectionally bind the application state to the view to perform automatic update between the application state and the view.
根据本公开的一个或多个实施例,提供了一种电子设备,包括第二存储器和处理器,所述第二存储器中存储有计算机程序,所述处理器执行所述计算机程序时实现如前所述的方法。According to one or more embodiments of the present disclosure, an electronic device is provided, including a second memory and a processor, wherein a computer program is stored in the second memory, and the processor implements the aforementioned method when executing the computer program.
根据本公开的一个或多个实施例,提供了一种计算机可读存储介质,所述计算机可读存储介质上存储有计算机程序,所述计算机程序被处理器执行时实现如前所述的方法。According to one or more embodiments of the present disclosure, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the method described above is implemented.
以上描述仅为本公开的较佳实施例以及对所运用技术原理的说明。本领域技术人员应当理解,本公开中所涉及的公开范围,并不限于上述技术特征的特定组合而成的技术方案,同时也应涵盖在不脱离上述公开构思的情况下,由上述技术特征或其等同特征进行任意组合而形成的其它技术方案。例如上述特征与本公开中公开的(但不限于)具有类似功能的技术特征进行互相替换而形成的技术方案。The above description is only a preferred embodiment of the present disclosure and an explanation of the technical principles used. Those skilled in the art should understand that the scope of disclosure involved in the present disclosure is not limited to the technical solutions formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above disclosed concept. For example, the above features are replaced with the technical features with similar functions disclosed in the present disclosure (but not limited to) by each other.
此外,虽然采用特定次序描绘了各操作,但是这不应当理解为要求这些操作以所示出的特定次序或以顺序次序来执行。在一定环境下,多任务和并行处理可能是有利的。同样地,虽然在上面论述中包含了若干具体实现细节,但是这些不应当被解释为对本公开的范围的限制。在单独的实施例的上下文中描述的某些特征还可以组合地实现在单个实施例中。相反地,在单个实施例的上下文中描述的各种特征也可以单独地或以任何合适的子组合的方式实现在多个实施例中。In addition, although each operation is described in a specific order, this should not be understood as requiring these operations to be performed in the specific order shown or in a sequential order. Under certain circumstances, multitasking and parallel processing may be advantageous. Similarly, although some specific implementation details are included in the above discussion, these should not be interpreted as limiting the scope of the present disclosure. Some features described in the context of a separate embodiment can also be implemented in a single embodiment in combination. On the contrary, the various features described in the context of a single embodiment can also be implemented in multiple embodiments individually or in any suitable sub-combination mode.
尽管已经采用特定于结构特征和/或方法逻辑动作的语言描述了本主题,但是应当理解所附权利要求书中所限定的主题未必局限于上面描述的特定特征或动作。相反,上面所描述的特定特征和动作仅仅是实现权利要求书的示例形式。Although the subject matter has been described in language specific to structural features and/or methodological logical actions, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. On the contrary, the specific features and actions described above are merely example forms of implementing the claims.
Claims (8)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202410703384.7A CN118276856B (en) | 2024-05-31 | 2024-05-31 | Application state management method and device, electronic equipment and storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202410703384.7A CN118276856B (en) | 2024-05-31 | 2024-05-31 | Application state management method and device, electronic equipment and storage medium |
Publications (2)
Publication Number | Publication Date |
---|---|
CN118276856A CN118276856A (en) | 2024-07-02 |
CN118276856B true CN118276856B (en) | 2024-09-13 |
Family
ID=91643800
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202410703384.7A Active CN118276856B (en) | 2024-05-31 | 2024-05-31 | Application state management method and device, electronic equipment and storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN118276856B (en) |
Citations (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN104123219A (en) * | 2013-04-28 | 2014-10-29 | 国际商业机器公司 | Method and device for testing software |
Family Cites Families (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US8285499B2 (en) * | 2009-03-16 | 2012-10-09 | Apple Inc. | Event recognition |
WO2015118454A1 (en) * | 2014-02-04 | 2015-08-13 | ZeroTurnaround AS | System and method for providing runtime diagnostics of executing applications |
CN106951239B (en) * | 2017-03-10 | 2020-10-30 | 广州三星通信技术研究有限公司 | Method and device for setting display of application program |
-
2024
- 2024-05-31 CN CN202410703384.7A patent/CN118276856B/en active Active
Patent Citations (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN104123219A (en) * | 2013-04-28 | 2014-10-29 | 国际商业机器公司 | Method and device for testing software |
Also Published As
Publication number | Publication date |
---|---|
CN118276856A (en) | 2024-07-02 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US5822585A (en) | System and method for cooperative processing using object-oriented framework | |
CN109643252B (en) | Middleware interface and middleware interface generator | |
US20180113799A1 (en) | Model generation for model-based application testing | |
US10970052B2 (en) | System and method for enhancing component based development models with auto-wiring | |
US8924931B2 (en) | Method and system for determining dependencies in a mainframe development environment | |
CN113396393A (en) | Dynamic auto-configuration of multi-tenant PAAS components | |
US8589864B2 (en) | Automating the creation of an application provisioning model | |
US9218100B2 (en) | Method and system for partitioning asset management plugins | |
EP3030969A1 (en) | Automated application test system | |
US20100042972A1 (en) | Developmental tool and method for automating detection and construction of notification-based component applications | |
US11422777B2 (en) | System and methods with reduced complexity in the integration of exposed information models with applications | |
CN110489323B (en) | Visual RPC API debugging method, device, medium and equipment | |
CN110716720A (en) | A method and apparatus for implementing application hot deployment | |
CN112698824B (en) | View element state management method, device, electronic equipment and storage medium | |
Nikolov et al. | Conceptualization and scalable execution of big data workflows using domain-specific languages and software containers | |
Goetz et al. | Storm blueprints: patterns for distributed real-time computation | |
CN111752581A (en) | Distributed system upgrading method and device and computer system | |
US20080229274A1 (en) | Automating Construction of a Data-Source Interface For Component Applications | |
CN112612460B (en) | Interface encapsulation and calling method, electronic device and storage medium | |
US8997116B2 (en) | Event logging application programming interface (API) | |
CN107608691A (en) | A kind of method for updating pages and device | |
CN111290818B (en) | Operation method for creating application program and operation method for application program | |
CN113656001A (en) | Platform component development method and device, computer equipment and storage medium | |
CN114756227A (en) | A method and device for processing resource release | |
CN118276856B (en) | Application state management method and device, electronic equipment and storage medium |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
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 |