Skip to content

Conversation

texodus
Copy link
Member

@texodus texodus commented Jan 10, 2025

This PR creates a new package @finos/perspective-react, a dedicated Perspective integration library for the React JavaScript framework.

This abstraction is intended to be lightweight over Perspective's browser native API, with the only design goal being to lessen the impedance mismatch between Perspective's internally stateful (and imperative) Custom Element API, and React's functional design. More relevant than the new PerspectiveVIewer React component, is the underlying API changes to the <perspective-viewer> Custom Element which makes integration possible:

  • Table::delete, View::delete, Client::terminate and HTMLPerspectiveViewerElement::delete are now fully destructive, and calling any method on their objects afterwards will throw a definitive null pointer dereference error. Calling these methods unrecoverably & completely deallocates their associated objects, not just their handles.
  • Alternatively, handle objects (such as a Table returned by Client::open_table) can be deallocated but not deleted remotely via table.free() in JavaScript (Python does not leak handles).
  • Table::delete has a new options parameter, which has a single boolean property lazy, which defers the deletion until the View count for this Table naturally reaches zero. Be careful not to overuse this - it is easy to "leak" Table by using lazy without remembering to cleanup all HTMLPerspectiveViewerElement (and hence View objects) which use it, effectively leaking the Table without a warning. The lazy property just makes ordering this method call easier in React where it is difficult to signal when all dependencies Custom Elements have been destroyed by React.useEffect destructors (which may be nested opaquely in the component graph) - it does not absolve you from calling View::delete or HTMLPerspectiveViewerElement::delete on dependencies in React.useEffect in the first place.
  • A new method HTMLPerspectiveViewerElement::eject is the reciprocal of HTMLPerspectiveViewerElement::load, removing any loaded Table and reverting the element to its initial state. This is different from HTMLPerspectiveViewerElement::delete, which deallocates the element entirely (and can't be recovered).
  • HTMLPerspectiveViewerElement::load is now equivalent to HTMLPerspectiveViewerElement::reset if the Table is already loaded (has the same Client instance and table name.

Drive-by changes:

  • Rustdoc for public APIs has been inlined everywhere. pyo3 and wasm_bindgen were struggling to handle these, and even where it worked it was quirky. This change, for example, makes @finos/perspective TypeScript types to have their APIs get proper tsdocs. Some ancillary build steps were pruned as well.

@texodus texodus added enhancement Feature requests or improvements breaking labels Jan 10, 2025
@texodus texodus force-pushed the feature/react-viewer-widget branch 6 times, most recently from 8936cf1 to a656f14 Compare May 4, 2025 18:21
@texodus texodus force-pushed the feature/react-viewer-widget branch 3 times, most recently from 1c89ff8 to f8705cf Compare May 4, 2025 19:26
texodus added 2 commits May 4, 2025 19:12
@texodus texodus force-pushed the feature/react-viewer-widget branch 2 times, most recently from bc413a4 to 05ec5c7 Compare May 5, 2025 02:56
@texodus texodus marked this pull request as ready for review May 5, 2025 03:01
@texodus texodus force-pushed the feature/react-viewer-widget branch from 05ec5c7 to 852ef20 Compare May 5, 2025 03:58
@texodus texodus merged commit d61ff5a into master May 5, 2025
14 checks passed
@texodus texodus deleted the feature/react-viewer-widget branch May 5, 2025 06:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking enhancement Feature requests or improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants