Open peteruithoven opened 7 years ago
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));
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!
As mentioned in https://github.com/reactjs/redux/issues/125#issuecomment-119381649 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: https://github.com/petehunt/react-raf-batching/issues/8