penumbra-zone / web

Apache License 2.0
12 stars 15 forks source link

Update auctions in place #1298

Closed jessepinho closed 3 months ago

jessepinho commented 3 months ago

Previously, ZQuery provided no way to update items in place when a stream was restarted. Instead, when a stream was restarted, ZQuery would set the state to undefined, then start processing streaming responses again.

With this PR's change, we can now handle streams a bit more intelligently. ZQuery no longer sets the state to undefined when restarting a stream; instead, it calls a new onStart() reducer (if it's passed to createZQuery()). Similarly, when a stream ends, errors, or is aborted, it calls handlers for those. It also calls an onValue() reducer when a value is received from the stream.

All those reducers are now returned by a stream function that consumers pass to createZQuery(), which allows consumers to maintain a JavaScript scope over the life of a stream. This allows you to update streamed items in place, and — in combination with onEnd() — discard any items from a previous stream that aren't present in the current stream. (See the implementation and docs for more detail.)

Before

https://github.com/penumbra-zone/web/assets/1121544/bc55c820-3cc9-4a9c-acdc-ba6ddea0fa75

After

https://github.com/penumbra-zone/web/assets/1121544/d67538c4-4f05-4033-be28-1b26b60952ad

Closes #1090

changeset-bot[bot] commented 3 months ago

🦋 Changeset detected

Latest commit: ddbb3cfb2a7a4929450d05cde3600d39512efa0f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages | Name | Type | | --------------------- | ----- | | @penumbra-zone/zquery | Major | | minifront | Minor |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR