Comments (6)
Okay so you would actually write it like this: (u can modify the prop, there is nothing wrong with doing so, because repaint will cause this to be repainted anyways.)
The whole point of this library is that you should modify the models directly, you don't have to go through the diagram engine.
import * as React from 'react'
// UTILS
import * as SRD from 'storm-react-diagrams'
export class BoxNodeWidget extends React.Component {
static defaultProps = {
node: null
}
render() {
return (
<div
className="box-node"
style={{
position: 'relative',
backgroundColor: 'silver'
}}
onDoubleClick={() =>
this.props.node.name = "test";
this.props.diagramEngine.repaintCanvas()
>
...
from react-diagrams.
you can register a listener inside of the Widget for events from the model, and update view on that basis without requiring a whole repaint.
If you could give a bit more details about how to do that, it would be very useful ! Thanks.
from react-diagrams.
Well I think the first step would be to learn how MVC works. This library in all of its examples and code, makes heavy use of Models which are then passed into factories (controllers) which then return a view (React widgets). It should then go without saying that you should:
create your own widgets for your own models, that when double clicked, change a model property which then calls the repaint method on the engine. I noticed in some of your example code you pasted, that you were storing your models and engines inside a react component. This is a bad practice because you should really store data in a store or make use of reducers etc..
from react-diagrams.
Hmmm... ok, yes I could store it in my Redux store and access it from there. I'll give that a go. With the new found knowledge of repaintCanvas
(please, please, please, document the available methods), I have found a way to start off. I know directly manipulating props is VERY bad so will try the store approach now.
import * as React from 'react'
// UTILS
import * as SRD from 'storm-react-diagrams'
export class BoxNodeWidget extends React.Component {
static defaultProps = {
node: null
}
renameNode(id, name) {
// Set new name
this.props.diagramEngine.diagramModel.nodes[id].name = name
// Rerender diagram
this.props.diagramEngine.repaintCanvas()
}
render() {
return (
<div
className="box-node"
style={{
position: 'relative',
backgroundColor: 'silver'
}}
onDoubleClick={() =>
this.renameNode(this.props.node.id, 'test new name')}
>
...
from react-diagrams.
Cool, thanks. This feels like two-way binding which is why I thought it was frowned upon.
from react-diagrams.
Just commenting here for future searchers:
you can register a listener inside of the Widget for events from the model, and update view on that basis without requiring a whole repaint.
from react-diagrams.
Related Issues (20)
- custom code
- [Bug] Right angled links are diagonal if the points are added after the link is created
- 50 Errors in build HOT 2
- BezierCurve
- Tutorial not working HOT 1
- Deserialization not working HOT 2
- Demos should be refactored to be consistent with modern react standards and styles HOT 2
- I can't see the any nodes. HOT 1
- Is there a way with smart routing to ensure that the link line is never going through the node?
- Deregister Listener when links are created
- DragNewLinkState bug when pressing down with another mouse button while dragging.
- Does storm-react-diagrams support nonce attribute for CSP?
- Node EventListeners don't work when setting a state from component
- can't find createEngine export HOT 1
- Adding NodeModel to NodeLayer set itself as its parent, but NodeModel's parent must be a Diagram
- Module '"@projectstorm/react-diagrams"' has no exported member 'AbstractReactFactory'.
- Intermittent bug in dragNewLink with allowLooseLinks = false HOT 2
- Bug: running `diagrams-demo-project` error `TS2345: Argument of type 'Element' is not assignable to parameter of type 'ReactNode'. Property 'children' is missing in type 'Element' but required in type 'ReactPortal'.`
- Deserialization isn't working properly HOT 1
- got an error in gallary demo: diagrams-demo-gallery HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-diagrams.