python implementation of the redux library
Project description
Python port of redux library
Simple example app:
```
from pyredux import create_store, actiontypes, frozenbunch
action_types = actiontypes('myapp', 'increment decrement')
def app_reducer(state, action):
if state is None:
return frozenbunch(counter=0)
if action.type == action_types.increment:
return state.copy(counter=state.counter + 1)
elif action.type == action_types.decrement:
return state.copy(counter=state.counter - 1)
return state
store = create_store(app_reducer)
```
The frozenbunch type is an immutable version of the Bunch pattern, whose members can be accessed by item or by attribute. For example:
```
x = frozenbunch(foo=12, bar=7)
x['foo']
x.foo
x['foo'] = 17
x.foo = 17
x = x.copy(bar=17)
```
Simple example app:
```
from pyredux import create_store, actiontypes, frozenbunch
action_types = actiontypes('myapp', 'increment decrement')
def app_reducer(state, action):
if state is None:
return frozenbunch(counter=0)
if action.type == action_types.increment:
return state.copy(counter=state.counter + 1)
elif action.type == action_types.decrement:
return state.copy(counter=state.counter - 1)
return state
store = create_store(app_reducer)
```
The frozenbunch type is an immutable version of the Bunch pattern, whose members can be accessed by item or by attribute. For example:
```
x = frozenbunch(foo=12, bar=7)
x['foo']
x.foo
x['foo'] = 17
x.foo = 17
x = x.copy(bar=17)
```
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
py-redux-0.1.0.tar.gz
(4.7 kB
view hashes)
Built Distribution
Close
Hashes for py_redux-0.1.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64342161f452f251d0e1cb7ab2efc41f5fad325aa3a16691228bdc1936843be4 |
|
MD5 | 7e395a50fdfa986a7e46e72982cfb971 |
|
BLAKE2b-256 | 8c7eb4624f48d04fdaf3fb9432649e46e1789f481d3573e8e4c0ddaf38c88371 |