An open-source Python library for managing application state.
Project description
GSO (Global State Observer)
GSO is an open-source Python library for managing application state. It uses a modified version of the Observer pattern to sync UI state with application state.
GSO was originally designed to work with PySide/ PyQt, but it works well with pretty much every class-based UI library out there.
How to use
You will find a lot of examples that can help you get started. The examples are very simple, they are all focused on the pattern that works best with GSO.
You are encouraged to clone the ones that use the UI library you are working with and have a closer look.
Flow
In GSO, application state is encapsulated in observables.
An observable is like a wrapper around the actual state or variable.
All an observable brings to the table is that it keeps references to objects (usually UI components) that are interested in knowing when the wrapped state changes.
Observables force notification of observers when encapsulated state changes, so whenever application state changes, UI components can instantly update accordingly.
All UI components that depend on at least one variable in
application state should implement the Observer
interface,
and each of these variables should be encapsulated in
an Observable
.
That was the O in GSO, the Observer pattern.
You might be thinking, how do UI components reach state? Well, that's where the GS comes to play.
The GlobalState
class is used to group all application state variables
and make them globally available everywhere in your code,
so that UI components can easily request state updates
and observe application state. It acts as a singleton, and stores
all the observables in a Python dict
.
As you already know, an observable can have multiple observers, and an observer can observe multiple observables.
In other words, one variable in application state
can have multiple UI components depending on it,
and one UI component can have it's state depend on multiple
variables in application state, which is why
the notify_state_changed()
method on Observer
s
accepts the parameter action
.
If you are familiar with Redux, you probably already have an idea what actions are, they are pretty similar in GSO, but they are not the same.
In both Redux and GSO, actions are objects that describe what kind of update should take place in application state.
In Redux, every action has a unique name, and a payload that has all what is needed to make the corresponding update properly.
However, in GSO, actions are distinct objects that encapsulate
state update logic. They are used by Observable
s in their apply()
method to update encapsulated state using the encapsulated logic.
If you found any of this confusing or unclear, please refer to the examples.
How to install
Make sure you have pip
installed, then open a terminal window, and type:
pip install gso
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file gso-2.0.0.tar.gz
.
File metadata
- Download URL: gso-2.0.0.tar.gz
- Upload date:
- Size: 3.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8044bdce782774c6fd4cf0037d0ecf0baad6dff5ccbcf58341187d62fe0621d4 |
|
MD5 | 3ba1a742a8c697561f6640de494efb48 |
|
BLAKE2b-256 | e7f20903b5fcf8ed0769312e5cc8cba9c6592bc7f554cedafab6fbab12a2cf09 |
File details
Details for the file gso-2.0.0-py3-none-any.whl
.
File metadata
- Download URL: gso-2.0.0-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 175ddb32113f5afd64e5d222cf37d1196b9faaa380db71cdf3a50b12786c8eeb |
|
MD5 | 097e6ddc6cbdc34cbe1dac4b7c7e6a85 |
|
BLAKE2b-256 | 5847a3cfc72e434f17b181ea779cb20009a4bca6bc3246f40c71f79589f3beb2 |