Skip to content

Commit

Permalink
Fix subscriptions that dispatch synchronously
Browse files Browse the repository at this point in the history
Fixes #28
  • Loading branch information
uniphil committed Jun 16, 2016
1 parent 04bf6b5 commit 0b71059
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "spindle-ui",
"version": "0.0.4",
"version": "0.0.5",
"description": "A tiny helper for structuring React components in a way that's easy to create, maintain, reuse, and scale",
"main": "spindle.dist.js",
"scripts": {
Expand Down
8 changes: 6 additions & 2 deletions spindle.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,21 +106,25 @@ const createSpindle = () => {
updateSubs: (component, subs) => {
subs.forEach(([ s, Tag ]) => {
const k = s.get('key');
let go;
if (!subscriptions.has(k)) {
const go = (state, msg) => {
go = (state, msg) => {
subscriptions
.getIn([k, 'subscribers'])
.forEach(suber => suber(msg));
subscriptions = subscriptions.setIn([k, 'state'], state);
};
subscriptions = subscriptions.set(k, Immutable.Map({
msg: go,
state: s.start(go),
state: null,
subscribers: Immutable.Map(),
}));
}
subscriptions = subscriptions.setIn([k, 'subscribers', Tag],
payload => component._dispatch(Tag(payload)));
if (go) {
subscriptions = subscriptions.setIn([k, 'state'], s.start(go));
}
});
},
};
Expand Down
1 change: 1 addition & 0 deletions time.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const seconds = Sub({
key: Symbol('SECONDS'),
start: msg => {
let state = setInterval(t => msg(state, new Date()), 1000)
msg(state, new Date());
return state;
},
stop: clearInterval,
Expand Down

0 comments on commit 0b71059

Please sign in to comment.