-
Notifications
You must be signed in to change notification settings - Fork 5
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
✨ listeners #23
✨ listeners #23
Conversation
expect(spyFilter.mock.calls[0]).toMatchSnapshot() | ||
}) | ||
|
||
it('should catch and dispatch a new action', () => { |
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.
This is one good exemple how to use listeners
, inspiration from redux-saga
src/createStore/createStore.js
Outdated
if (enhancer) enhancer = compose(enhancer, applyMiddleware(middleware)) | ||
enhancer = applyMiddleware(middleware) | ||
} | ||
|
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.
Maybe something like that seems simplier to read :
let listen
let { enhancer, listeners } = innerOptions
if (listeners) {
listen = listenFactory(listeners)
// add this middleware to enhancer
const middleware = applyMiddleware(listen.middleware)
enhancer = enhancer ? compose(enhancer, middleware) : middleware
}
isRegExp(match) && | ||
action.type.match(match) | ||
) | ||
) |
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.
I think it could be useful if we could give an array of actions to match :
take(['ACTION1', 'ACTION2'] console.log),
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.
import { isRegExp, isString, isFunction } from 'lodash' | ||
|
||
const take = (match, callback) => (action, store) => { | ||
const isMatching = ( // test matching |
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.
The matcher should have it's own file, because if you want to create other listeners (like takeLatest...), you will reuse it.
also, src/take.js
may should be in src/listeners/take.js
But it can be done later, when you will have other listeners...
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.
Yes we will do that later, and we can override take
like I did on k-mst-onaction
: https://github.com/alakarteio/k-mst-onaction/blob/master/src/helpers/take.js#L27
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.
"ok"
fixes #22