Giter Site home page Giter Site logo

Node renaming about react-diagrams HOT 6 CLOSED

projectstorm avatar projectstorm commented on May 2, 2024
Node renaming

from react-diagrams.

Comments (6)

dylanvorster avatar dylanvorster commented on May 2, 2024 2

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.

Massetho avatar Massetho commented on May 2, 2024 2

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.

dylanvorster avatar dylanvorster commented on May 2, 2024

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.

will-stone avatar will-stone commented on May 2, 2024

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.

will-stone avatar will-stone commented on May 2, 2024

Cool, thanks. This feels like two-way binding which is why I thought it was frowned upon.

from react-diagrams.

JeremyRubin avatar JeremyRubin commented on May 2, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.