-
Notifications
You must be signed in to change notification settings - Fork 124
feat: Fetcher updates #1090
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
feat: Fetcher updates #1090
Changes from 1 commit
cc38cb1
2a41fc6
1f54d95
3398d8a
fb1f87c
650a918
a9e9469
8dcf01c
573c195
7306663
e0a327a
73e9bd8
f8e080d
d9da99f
04ed13a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,12 +45,16 @@ export default function useWorkflowHistoryFetcher( | |
|
|
||
| useEffect(() => { | ||
| if (!fetcherRef.current) return; | ||
|
|
||
| let lastFlattenedPagesCount: number = 0; | ||
| const unsubscribe = fetcherRef.current.onChange((state) => { | ||
| const pagesCount = state.data?.pages?.length || 0; | ||
| onEventsChange( | ||
| state.data?.pages?.flatMap((page) => page.history?.events || []) || [] | ||
| ); | ||
| // if the pages count is greater than the last flattened pages count, then we need to flatten the pages and call the onEventsChange callback | ||
| if (pagesCount > lastFlattenedPagesCount) { | ||
| lastFlattenedPagesCount = pagesCount; | ||
| onEventsChange( | ||
| state.data?.pages?.flatMap((page) => page.history?.events || []) || [] | ||
| ); | ||
| } | ||
|
Comment on lines
+53
to
+58
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I must be missing something. My understanding:
I would have expected:
I'm a bit confused why we don't pass The hook, as currently implemented, knows too much about the fetcher internals.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if this is a follow up question on this or the message didn't show up for you as it was outdated. We can continue the discussion there. |
||
| // immediately set if there is the first page without throttling other wise throttle | ||
| const executeImmediately = pagesCount <= 1; | ||
| setHistoryQuery(() => state, executeImmediately); | ||
|
|
@@ -62,8 +66,6 @@ export default function useWorkflowHistoryFetcher( | |
| }, [setHistoryQuery, onEventsChange]); | ||
|
|
||
| useEffect(() => { | ||
| if (!fetcherRef.current) return; | ||
|
|
||
| return () => { | ||
| fetcherRef.current?.destroy(); | ||
| }; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I follow.
It sounds like
historyQueryis throttled.On the other hand, the unthrottled flow is...
onChange, then getstate.stateand flatten it (for what purpose?)onEventsChange(why?)I'm probably missing something obvious with grouping in the history page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, history queue is throttled. Since it seems hard to understand this pattern i moved
lastFlattenedPagesCountto be arefoutside the component.The reason why we flatten is that
Pagesis areact-queryconstruct. But helpers and other components accepts arrays of events. It made sense to send events here since the method name isonEventsChange. If we didn't do in this hook we would need to do it in the parent.