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.1.tar.gz
.
File metadata
- Download URL: gso-2.0.1.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 | e968853dfd83069283803a6a225ce2e511e8572f5e5c0054eeb65fc1271777c7 |
|
MD5 | 0e496f2621dadff533dbfe2471220937 |
|
BLAKE2b-256 | 632d666aabb1ca8fac7cbed49b6c86b41ba21a1cad64d646d268c04e655c75e1 |
File details
Details for the file gso-2.0.1-py3-none-any.whl
.
File metadata
- Download URL: gso-2.0.1-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 | f2cd5d94d26b773bb5a767f491f2961850993db1c2169c71fed3048cf2f566f4 |
|
MD5 | 34203f39a248298cfe20159196ccb32c |
|
BLAKE2b-256 | e32f30eeffe848865bdfd284fcb8e30d9ad01e15b3db7b4370f9d92b24dedd63 |