Download spectrum/shared/graphql/subscriptions/utils.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.15 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/spectrum/shared/graphql/subscriptions/utils.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/spectrum/shared/graphql/subscriptions/utils.js
-
curl -L -o utils.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/spectrum/shared/graphql/subscriptions/utils.js
1.15 kB
| // @flow | |
| // used to update feed caches with new threads in real time | |
| // takes an array of existing threads in the cache and figures out how to insert the newly updated thread | |
| export const parseRealtimeThreads = ( | |
| prevThreads: Array<any>, | |
| updatedThread: Object | |
| ) => { | |
| // get an array of thread ids based on the threads already in cache | |
| const prevThreadIds = prevThreads.map(thread => thread.node.id); | |
| // determine if the newly updated thread exists in the cache or not | |
| // if it doesn't exist in cache, it's a new thread! if it does exist in cache, it just means its | |
| // been updated with a new message | |
| const hasNewThread = prevThreadIds.indexOf(updatedThread.id) < 0; | |
| return hasNewThread | |
| ? [ | |
| { | |
| node: updatedThread, | |
| cursor: '__this-is-a-cursor__', | |
| __typename: 'Thread', | |
| }, | |
| ...prevThreads, | |
| ] | |
| : [ | |
| ...prevThreads.map(thread => { | |
| if (thread.node.id !== updatedThread.id) return thread; | |
| return { | |
| node: updatedThread, | |
| cursor: '__this-is-a-cursor__', | |
| __typename: 'Thread', | |
| }; | |
| }), | |
| ]; | |
| }; | |