Skip to content
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

Merged
merged 4 commits into from
Jan 22, 2018
Merged

✨ listeners #23

merged 4 commits into from
Jan 22, 2018

Conversation

fabienjuif
Copy link
Member

@fabienjuif fabienjuif commented Jan 22, 2018

fixes #22

@coveralls
Copy link

coveralls commented Jan 22, 2018

Coverage Status

Coverage remained the same at 100.0% when pulling 6c5982d on listen into 38258c3 on master.

expect(spyFilter.mock.calls[0]).toMatchSnapshot()
})

it('should catch and dispatch a new action', () => {
Copy link
Member Author

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

if (enhancer) enhancer = compose(enhancer, applyMiddleware(middleware))
enhancer = applyMiddleware(middleware)
}

Copy link
Collaborator

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)
)
)
Copy link
Collaborator

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),

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#25

import { isRegExp, isString, isFunction } from 'lodash'

const take = (match, callback) => (action, store) => {
const isMatching = ( // test matching
Copy link
Collaborator

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...

Copy link
Member Author

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

@fabienjuif fabienjuif mentioned this pull request Jan 22, 2018
Copy link
Member

@guillaumecrespel guillaumecrespel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"ok"

@fabienjuif fabienjuif merged commit eb4e52a into master Jan 22, 2018
@fabienjuif fabienjuif deleted the listen branch January 22, 2018 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

own listen middleware
4 participants