Skip to content

feat(streaming-data): load large collections in batches outside the data model - #964

Closed
shahabdsh wants to merge 4 commits into
player-ui:mainfrom
shahabdsh:feat/streaming-data-collections
Closed

shahabdsh wants to merge 4 commits into
player-ui:mainfrom
shahabdsh:feat/streaming-data-collections

Conversation

@shahabdsh

Copy link
Copy Markdown
Contributor

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 EXTERNAL states. 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

  • Declaring: A schema entry with source: { ref, status, params } declares a collection. ref names a source the app registers with the plugin, status is where the plugin writes progress (by default <binding>Status), and params are templates resolved when loading starts.
  • Loading: Content starts a load with loadStreamingData(binding), usually in a navigation onStart; reads never start one. A source's load returns 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.
  • Serving: A data middleware serves the plugin's one frozen array, by reference, at the collection's binding. The binding is read-only and stays out of serialize(). Change notices are narrow: appends announce <binding>.length and 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, can subscribe to changes through getCollection(binding).
  • Saving: commit-records EXTERNAL states save through commitRecordsHandler, which the app adds to its ExternalStatePlugin. The handler collects the changes (expressions in eachRow run on each selected record, 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. It never throws. eachRow sits beside param rather than in it, because Player resolves the templates in param when the state starts.
  • Scope: The plugin doesn't sort, search, filter, or page. Whatever shows the collection does.

Open question: keeping a view on screen during a save

When the flow enters a state that isn't a VIEW, Player sets ViewController.currentView to undefined, so nothing is on screen while a save's EXTERNAL state runs. So that the view that started the save can show its progress, the handler puts it back:

if (lastViewState && this.isOverlay(lastViewState)) {
  if (backgroundState) viewController.onView(backgroundState);
} else if (lastView) {
  viewController.currentView = lastView;
}

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 isOverlay option 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 an EXTERNAL state 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.ts runs the plugin on a plain Player with 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: eachRow updates, removals, nothing to save, partial, rejected, and a source without commit. It also covers the view kept during a save (including from an overlay) and a misplaced eachRow. 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.
  • Unit tests for RecordCollection, collectChanges, findCollectionDeclarations, and toCommitRequest.

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-lockfile accepts it.

Change Type (required)

Indicate the type of change your pull request is:

  • patch
  • minor
  • major
  • N/A

Does your PR have any documentation updates?

  • Updated docs
  • No Update needed
  • Unable to update docs

Adds a docs page at plugins/core/streaming-data.

Release Notes

New @player-ui/streaming-data-plugin loads large collections in batches outside the data model and saves changes to them through commit-records EXTERNAL states. See the Streaming Data plugin docs.

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.
@shahabdsh

Copy link
Copy Markdown
Contributor Author

Replaced by #968, which is stacked on #967.

@shahabdsh shahabdsh closed this Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant