-
Notifications
You must be signed in to change notification settings - Fork 859
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP feat(joint-react): react lib project setup + POC's #2867
base: master
Are you sure you want to change the base?
WIP feat(joint-react): react lib project setup + POC's #2867
Conversation
7c00f5f
to
ef39d8d
Compare
PR Update: API Improvements (POC v2)Following discussions with @kumilingus, the API has been refined to be cleaner and more user-friendly. Changes & StructureThe components remain largely the same:
Public HooksThe following hooks are available:
Both Example:useElements(element => ({ id: element.id })); ➡️ We need to verify that this does not cause unnecessary re-renders. Internal Mechanics
I am still exploring more ways how to do this - but this way seems to be flexible and easy to use - I am not big fun of contexts, so if there are some concerns about it, I am open to discuss. EDIT:
Screenshots of POCGet data from react and update it from react (we can get and update any data between react and jointjs): Simple stress test - to render 450 elements with links between each |
Description
WIP react lib project setup + POC's
Public API
GraphProvider
component - Providesdia.Graph
to the React context, accessible anywhere in its children.PaperProvider
component - Providesdia.Paper
to the React context. It's optional; if not used, thePaper
component will create its ownPaper
instance.Paper
component - Provides a view (UI) for the graph elements.The user can utilize built-in JointJS shapes or custom React components.
Two proposed APIs how it should "react" with
react state
:Using React state for elements (cells) with the ability to still use the
dia.Graph
API:Using the
dia.Graph
imperative API as the source of truth and custom hooks for React reactivity for elements (cells) + some sugar utilities for editing updating:In my opinion, the second approach is clearer and better for performance - as it use react state and react re-renders only if user really need it. It leverages the
dia.Graph
imperative API rather than the React declarative way, which is not too much react way, but synchronizing the graph with React state can be challenging and may impact performance. This approach works well within the JointJS space, avoiding React states.When users want to interact with elements or cells via React components, they can use the hooks API, such as
useGraphCells
which will synchronize jointjs elements state with react state in bi-directional way (view / edit)For example, to control (add / remove/ edit) or display particular graph elements inside a React component:
Motivation and Context
This change is required to introduce the new
joint-react
package, providing a more efficient and clear way to manage graph elements in React applications.More info
To test this out, just run
yarn storybook
in newly created packagepackages/joint-react
This is just POC, it do not use any external UI library or something and I think it should not, for more UI examples we should add them inside example folder.
In this project, I will try to focus to these points all the time:
So if there is not something clear or something do not make sense, let me know in the comments.
Screenshots (if appropriate):
This is the first PR for this project.