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

Undesired Actions Notifications #4

Open
pjago opened this issue Jan 2, 2016 · 1 comment
Open

Undesired Actions Notifications #4

pjago opened this issue Jan 2, 2016 · 1 comment

Comments

@pjago
Copy link

pjago commented Jan 2, 2016

Hi. I've designed a custom redux middleware in a attempt to really push all side-effects away from my view code by means of redux-saga. I am basically appending a FIFO "TaskReducer" to my single redux store, and handling any QUEUE actions with it:

//queue action creator
function queue( task ){
  return {
    type: 'QUEUE',
    payload: task
  };
};
//taskMiddleware
export default store => next => action => {
  const result = next(queue(action));
  return result;
}
//and a TaskReducer that merges repeated tasks in a meaningful way (e.g. a FIFO queue) ...

I find this way of delegating tasks quite convenient for performance reasons. However, since the QUEUE action plays as any other action in redux, any store listeners (e.g. hundreds of connected components) will eventually waste time on it, and even DevTools won't work properly since I am not interested in replaying side-effects...

So I was wondering if this situation is of any interest for this repository, as it seems to me that this is the correct place to implement a solution for "undesired action subscriptions".

Perhaps passing the dispatched action as an argument for the batch function would solve this? That way we could easily check for the action type and decide whether we should notify the listeners or not:

const store = batchedSubscribe((notify, action) => {
  if(action.type !== QUEUE)
    requestAnimationFrame(notify);
})(createStore)(reducers)

Anyways, is this worth pull requesting?

@pjago pjago changed the title Conditional Notification Undesired Actions Notifications Jan 2, 2016
@tappleby
Copy link
Owner

tappleby commented Jan 2, 2016

I think this could be of some value, conditional notifications is a topic that has come up a few times; there is even @tshelburne package redux-skip-by-action who's code could be simplified by having something like this.

With that being said I do wonder if conditional subscriber notifications is a case of premature optimization, I could see it causing some difficult to debug situations. See reduxjs/redux#580 for a similar issue.

I dont mind adding support for this as I do believe why waste cycles if you don't need to, my only concern is it getting misused.

@gaearon do you have any thoughts on this?

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

No branches or pull requests

2 participants