-
I have a text editor with live saving, similar to Google Docs. The current model uses urql as unique data layer, so each keystroke triggers a mutation associated with an optimistic update. Of course, when writing large documents it wastes a lot of bandwidth, so I want to offset this by debouncing the http query to only submit data once the user stopped typing for N seconds. On the other hand those entities have other fields, and some of them (for instance whether the document is public or private) have to be persisted immediately. So a blanket debounce would be problematic as well. The way I see it I have two options:
What would you recommend? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I don't think an additional layer makes much sense given that the state of modifications would have to be duplicated for such a simple case. I'd opt for queueing up changes in local state and would just buffer or denounce them to combine them as needed or determine when it'd immediately have to be sent off as this would like be a small hook with a queue and a It's totally possible to use an exchange too and I could cobble some code examples together here if you have some specific description of what needs to be sent ASAP vs denounced. But a wrapper around the mutation hook is likely much easier to achieve given that this sounds like a UI state Problem for a single mutation, right? |
Beta Was this translation helpful? Give feedback.
I don't think an additional layer makes much sense given that the state of modifications would have to be duplicated for such a simple case.
I'd opt for queueing up changes in local state and would just buffer or denounce them to combine them as needed or determine when it'd immediately have to be sent off as this would like be a small hook with a queue and a
setTimeout
attached to state changes.It's totally possible to use an exchange too and I could cobble some code examples together here if you have some specific description of what needs to be sent ASAP vs denounced. But a wrapper around the mutation hook is likely much easier to achieve given that this sounds like a UI state Problem…