Repository navigation
Conversation
DataController builds its data pipeline the first time anything reads or writes data, and resolveDataStages was only called at that moment. A plugin that tapped resolveDataStages after another plugin had already read data from its own dataController tap was silently left out of the pipeline. Rebuild the pipeline whenever a stage is tapped after it was built. The data itself lives in the base LocalModel, and the PipelinedDataModel instance and its hooks are kept, so nothing written earlier is lost.
…ata model Add @player-ui/streaming-data-plugin. A flow declares a collection with a `source` on its schema entry: the name of a source the app registers, a status binding, and params. Content starts a load with loadStreamingData(binding). The plugin appends each batch to one frozen array, serves it by reference at the collection's binding through a data middleware, keeps the binding read-only and out of serialize(), and writes progress to the status binding. Change notices name only what changed, so a view resolves again only the nodes that read it. Saves run in `commit-records` EXTERNAL states through a handler the app adds to its ExternalStatePlugin. The handler collects the changes (eachRow expressions over selected records, a draft to create or update, keys to remove), calls the source's commit, merges the returned records by key, and transitions with saved, partial, or failed. While the save runs, it keeps the view that started it current, so the view can show the save's progress.
2 of 7 tasks
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
@player-ui/streaming-data-plugin, a core plugin for collections too large to keep in the data model: thousands of records that arrive in pages from a backend, are shown in something like a table, and are edited in place.It builds on the idea in #943, with a declarative API: a flow declares its collections in the schema, content decides when loading starts, and saves go through
EXTERNALstates. It would supersede #943.Depends on #963, which lets the plugin's data middleware join the pipeline whatever order plugins are registered in. This branch includes that change, so the diff shows it until it merges.
How it works
source: { ref, status, params }declares a collection.refnames a source the app registers with the plugin,statusis where the plugin writes progress (by default<binding>Status), andparamsare templates resolved when loading starts.loadStreamingData(binding), usually in a navigationonStart; reads never start one. A source'sloadreturns an async iterable of batches. Loading again with the same params does nothing, new params start over,retryStreamingData(binding)retries after a failure, and loads abort when the flow ends.serialize(). Change notices are narrow: appends announce<binding>.lengthand a replaced record its own index, so a view resolves again only the nodes that read what changed. Code that keeps derived state, such as a table's sort keys, cansubscribeto changes throughgetCollection(binding).commit-recordsEXTERNALstates save throughcommitRecordsHandler, which the app adds to itsExternalStatePlugin. The handler collects the changes (expressions ineachRowrun on each selected record, a draft to create or update, keys to remove), calls the source'scommit, merges the returned records by key, and transitions withsaved,partial, orfailed. It never throws.eachRowsits besideparamrather than in it, because Player resolves the templates inparamwhen the state starts.Open question: keeping a view on screen during a save
When the flow enters a state that isn't a
VIEW, Player setsViewController.currentViewtoundefined, so nothing is on screen while a save'sEXTERNALstate runs. So that the view that started the save can show its progress, the handler puts it back:For a save started from an overlay, such as a modal that closes when the flow leaves it, the handler shows the last view that isn't an overlay instead (the
isOverlayoption says which views are). This writes a public field and works with how Player behaves today, but it isn't a supported API. A core way to keep a view current through anEXTERNALstate would replace it. I'd rather settle that API separately than hold this PR for it, and I'm happy to hear other ideas.Tests
47 tests in five files:
StreamingDataPlugin.test.tsruns the plugin on a plainPlayerwith a source the test feeds one batch at a time. It covers loading only on request with resolved params, serving by reference, ignored writes and deletes, declaration errors, narrow change notices, reloading with new params, retrying after a failure, cancelling when the flow ends, and saves:eachRowupdates, removals, nothing to save, partial, rejected, and a source withoutcommit. It also covers the view kept during a save (including from an overlay) and a misplacedeachRow. One test registers a plugin that reads data before this one taps the pipeline; it fails without fix(core): run data stages tapped after the pipeline is built #963.RecordCollection,collectChanges,findCollectionDeclarations, andtoCommitRequest.The plugin's vitest, eslint, typecheck, and build targets pass. The lockfile change adds only the new package's importer entry, and
pnpm install --frozen-lockfileaccepts it.Change Type (required)
Indicate the type of change your pull request is:
patchminormajorN/ADoes your PR have any documentation updates?
Adds a docs page at
plugins/core/streaming-data.Release Notes
New
@player-ui/streaming-data-pluginloads large collections in batches outside the data model and saves changes to them throughcommit-recordsEXTERNALstates. See the Streaming Data plugin docs.