Add table to ViewerConfig
#3107
Merged
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.
This PR updates the
<perspective-viewer>and<perspective-workspace>APIs to follow a common pattern for binding to a PerspectiveServer, with the goal of unifying these components in the future.Until now,
<perspective-viewer>'sload()method has taken aTableproxy object as an argument. This has a few disadvantages:loadandrestoreboth render, calling both methods in sequence (as is often practically the case) involves convoluted internal state management to make sure renders are conserved and a single-frame un-restored UI is not drawn, and the calls must be made in the right order which is a poor DX for frameworks like React.Tablein an existingperspective-viewerrequires an internal config reset and a superfluous intermediateViewif followed by arestore.Tablefeatures (like joins) can't be supported.Meanwhile,
<perspective-workspace>has a reactiveMapofTableproxy objects with names. However, this API very closely mirrors what already existed inClient, which is already a sort-of collection ofTables, and even has an existingnamefield already (albeit a different one than what<perspective-workspace>previously supported):Both of these APIs have been replaced (or in
<perspective-viewer>case, supplanted) with a newload()method which takes aClientand binds the widget to thisClientexclusively. To support this, thesave()andrestore()methods on<perspective-viewer>now take atablefield in theirViewConfig, which names the table.With this change, calling
load()with aClientargument first on a<perspective-viewer>does not cause a render (because noTableis selected yet), andrestore()selects both theTableand itsViewConfig, guaranteeing one atomic render once both are called and the element is mounted.Calling
load()with aTableis now internally the equivalent of this, which emulates legacy support:While this works, it should be avoided in favor of using a
Clientto prevent extraneous renders.Upgrade Notice
There is one quirky footgun to be aware of with the new unified API. Until now,
namehas been an optional keyword argument to theTableconstructor, and omitting it internal led to an invisble random name assignment. However, relying on this behavior will now lead to non-symmetric behavior if you do not carefully retain this mapping in thenamefield ofViewConfig.For example:
You can avoid this by (painfully) syncing the
tablefields manually, or by simply always giving yourTableanameon construction.Summary
<perspective-viewer>changes:load()now takes aClientas an argument, or (optionally) a legacyTable.restore()now takes aViewConfigwith atablefield, corresponding to thenameof the PerspectiveTable.save()now returns aViewConfigwith this field.<perspective-workspace>changes:addTable(),removeTables()methods and thetablesproperty have been removed.load()method now takes aClient, like<perspective-viewer>.Drive-by changes:
abseilbuild issue onmacos-15.Tablenames in the engine now error (instead of silently overwriting eachother).