projectstorm / react-diagrams

a super simple, no-nonsense diagramming library written in react that just works
https://projectstorm.cloud/react-diagrams
MIT License
8.58k stars 1.17k forks source link

Documentation for V5 #790

Open phwt opened 3 years ago

phwt commented 3 years ago

Hi, I'm using Storm React Diagrams V5 but can't find any documentation of it. The (SOME) DOCS in v5.3.2 branch also leads to docs for V6

Does to V5 have the documentation? Especially for create a custom elements I have a hard time understanding what is the model, widget and factory used for.

phwt commented 3 years ago

Found this explaining model and widget still not sure about the factory (does this related to factory design pattern?)

renato-bohler commented 3 years ago

(I used method names from v6, may differ from v5, but the general idea is the same basically)

As far as I understand, the factory is registered on react-diagrams, so that the library knows how to instantiate the corresponding model and widget when deserializing based on its type. This happens when you call model.deserializeModel, for example. Something along those lines:

  1. At some point, react-diagrams is required to deserialize (load) a diagram containing one entity whose type is set to 'diamond' (this happens .
  2. react-diagrams searches for a factory registered for type 'diamond'
  3. If react-diagrams finds one, it will use it to instantiate the corresponding model (via factory.generateModel method) and the corresponding React component (via factory.generateReactWidget method).
  4. If it doesn't find one, it will error out "Cannot find factory with type 'diamond'"