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

Adding exceptions #16

Open
peteruithoven opened this issue Nov 25, 2016 · 2 comments
Open

Adding exceptions #16

peteruithoven opened this issue Nov 25, 2016 · 2 comments

Comments

@peteruithoven
Copy link

peteruithoven commented Nov 25, 2016

As mentioned in reduxjs/redux#125 (comment) there are issues when batching updates and using controlled components. For example when using controlled input fields, when the user edits something (not at the end of the line / text) the cursor always jumps to the end.
For this reason I'd like to add exceptions to which notifications are batched or have a way to enable / disable the batcher.
I'm going to work on a PR, but comments are more than welcome.

I'm also reading through: petehunt/react-raf-batching#8

@peteruithoven
Copy link
Author

So our old batcher would work something like:

let rafID;
export default function rafUpdateBatcher(notify) {
  if (rafID) return;

  rafID = raf(() => {
    rafID = null;
    notify();
  });
}
const store = createStore(reducer, initialState, batchedSubscribe(rafUpdateBatcher));

Now I'd like to add exceptions, for example like:

let rafID;
export default function rafUpdateBatcher(notify, action, getState) {
  // batch exceptions
  switch(action.type) {
    case ADD_NOW:
      notify();
      raf.cancel(rafID)
      rafID = null;
      return;
  }
  if (rafID) return;

  rafID = raf(() => {
    rafID = null;
    notify();
  });
}
const store = createStore(reducer, initialState, batchedSubscribe(rafUpdateBatcher));

@peppesilletti
Copy link

peppesilletti commented Feb 3, 2017

Hello @peteruithoven , I was just looking for how to add exceptions to the enhancers and I found this thread. I don't really understand how to set some exceptions and I really need those because I'm using redux-form and I don't want its changes to debounce :)

My current script looks like:
const debounceNotify = _.debounce(notify => notify(), 100)
const batched = batchedSubscribe(debounceNotify)
const enhancers = [batched]

Thanks in advance for your help!

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