1.1.1 • Published 8 years ago

uluru v1.1.1

Weekly downloads
2
License
Unlicense
Repository
github
Last release
8 years ago

Quick Example

interface State {
    count: number;
}
interface Actions {
    "increment": void;
    "add": number;
    "delay-add": { delay: number, n: number };
}
let state: State = {
    count: 0,
};

const dispatcher = new Uluru.Dispatcher<Actions, State>(reduce => {
    const reduced = reduce(state);
    console.log(reduced);
    state = reduced;
});

dispatcher.subscribe("increment")(apply => () => {
    apply(prev => ({ ...prev, count: prev.count + 1 }));
});
dispatcher.subscribe("add")(apply => n => {
    apply(prev => ({ ...prev, count: prev.count + n }));
});
dispatcher.subscribe("delay-add")(apply => payload => {
    setTimeout(() => {
        apply(prev => ({ ...prev, count: prev.count + payload.n }));        
    }, payload.delay);
});

dispatcher.dispatch("delay-add")({ delay: 2000, n: 100 });
dispatcher.dispatch("increment")();
// { count: 1 }
dispatcher.dispatch("delay-add")({ delay: 1000, n: 20 });
dispatcher.dispatch("add")(5);
// { count: 6 }
// { count: 26 }
// { count: 126 }
1.1.1

8 years ago

1.1.0

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago

0.1.1

9 years ago

0.1.0

9 years ago