Provides simple interfaces that helps manage and centralize application state.
Project description
Global State Observer
GSO is an open-source Python library for managing state. It provides simple interfaces that application data objects and UI elements can easily implement to facilitate syncing them together. It is based on the Observer pattern, and it is inspired by Redux.js.
GSO was originally designed to be used with GUIs built using PySide/PyQt, but it should work with any class-based UI thanks to its abstractness.
How to use
-
UI elements should implement the
Observer
interface, and override thenotify(action)
method, to update their UI state based on theaction
. -
Application state should be encapsulated in a class called
State
. It should hold all observable pieces of data and have a single method:dispatch(action)
. -
The
dispatch(action)
method on theState
class should be called from the UI elements as a result of a user interaction. -
An
Action
is an object that describes a UI event that is fired with the intent of changing application state. -
An observable piece of data is any value (or collection of values) in the application state that UI elements depend on.
-
Any piece of observable data should be encapsulated in a class that implements the
Observable
interface, and have any number of methods for updating its values. -
Every update method on an observable piece of data should use the protected member
_value
in updating, and the protected method of theObservable
interface:notify(action)
, to notify all the attached observers with the update. -
UI elements should observe the observable pieces of data they depend on, this should be done by calling the
attach_observer(observer)
method onObservable
s and passing the UI elements as arguments.
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-0.0.2.tar.gz
.
File metadata
- Download URL: gso-0.0.2.tar.gz
- Upload date:
- Size: 2.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 08229ede5c6ab1e0d207f110fc808517025d1fe49e4ba63f1b9ff55fe3be0568 |
|
MD5 | b43e4cd82db275b84ba2b79b384264d9 |
|
BLAKE2b-256 | 8d0dbfbe4d31cf846878ccc6859e1c15eb9dd2b08ffc245fb3095ac37364c3af |
File details
Details for the file gso-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: gso-0.0.2-py3-none-any.whl
- Upload date:
- Size: 3.2 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 | 731b7171721e7cdd28043c6f126e8c843b820f2af4989937f6f153a61129fcda |
|
MD5 | 9701803abf3f44c97ba869ed9db08741 |
|
BLAKE2b-256 | f3d9e9666dc656a5869dedd26d2fb18171cf7b7f2fe18930959e3c264b18ebed |