Created
March 17, 2017 19:30
-
-
Save amirouche/3ff396f0f5ccc9dd0c316add0873fd7d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import wraps | |
import leloop | |
def mount(scene, init, view): | |
state = init() | |
def spawn(timeout, callback, *args, **kwargs): | |
# spawn is easier to test that leloop.call_later | |
leloop.call_later(lambda : yield from callback(*args, **kwargs), timeout) | |
def make_reducer(func): # called make action in forward project | |
"""This calls `func` with the current `state` as argument and `spawn`""" | |
@wraps(func) | |
def wrapped(*args, **kwargs): | |
new = func(state, spawn, *args, **kwargs) | |
if new != state: | |
state = new | |
render() | |
return wrapped | |
def render(): | |
new = view(state) | |
new.update_callback(make_reducer) | |
scene.patch(new) | |
return new | |
def change(func, *args, **kwargs): | |
func(state, spawn, *args, **kwargs) | |
return make_reducer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment