-
-
Notifications
You must be signed in to change notification settings - Fork 927
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scan with halt #1957
Scan with halt #1957
Conversation
Generated by 🚫 dangerJS |
From an API standpoint, I'm not so sure. I'd rather not prevent stateful reducers like these: function update(store, {type, value}) {
switch (type) {
case UNDO: store.undo(); return store
case REDO: store.redo(); return store
case INSERT: store.insert(value); return store
case FLUSH: return history()
default: return stream.HALT
}
}
Stream.scan(update, new Store(), dispatch) I personally hardly ever use streams, though (since Mithril core doesn't have any idea of streams), so I'm not super invested in anything. |
Thanks @isiahmeadows, that seems reasonable. So perhaps function scan(reducer, seed, stream) {
var newStream = combine(function (s) {
var next = reducer(seed, s._state.value)
if (next !== HALT) return seed = next
return HALT
}, [stream])
if (newStream._state.state === 0) newStream(seed)
return newStream
} Then behaviour is the same, except reducers can return |
That seems better to me. |
a833b27
to
997ed18
Compare
Agreed. Updated as discussed, and rebased against the latest. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Updated docs with a few notes on this change |
* HALT if scan reducer doesn't change value * Updated docs to reflect new scan behaviour with HALT
Description
If the reducer function doesn't change the value, then don't call the dependant streams.
Types of changes
Checklist
Does this seem like reasonable expectation for
scan
? Feedback greatly appreciated.Test case provided, and style guide followed :)