Skip to content

Commit

Permalink
tweak dispatch
Browse files Browse the repository at this point in the history
  • Loading branch information
walterra committed May 7, 2024
1 parent 958cf18 commit 13a77e9
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions x-pack/packages/ml/response_stream/client/use_fetch_stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,14 @@ export function useFetchStream<B extends object, R extends Reducer<any, any>>(
setIsRunning(false);
};

// This custom dispatch function allows us to update the `dataRef` value and will
// then trigger an update of `data` right away as we don't want to have the
// throttling in place for these types of updates.
const dispatch = (action: ReducerAction<FetchStreamCustomReducer<R>['reducer']>) => {
dataRef.current = reducerWithFallback.reducer(dataRef.current, action) as ReducerState<
CustomReducer<R>
>;
setData(dataRef.current);
};

const cancel = () => {
Expand Down

0 comments on commit 13a77e9

Please sign in to comment.