Giter Site home page Giter Site logo

Comments (4)

drichard avatar drichard commented on May 24, 2024

mindmaps.MindMapModel.createNode(node, parent) should be the right function for the job. However, it's important you pass a reference to the parent node.

You can get the parent node if you know its id. The id should be part of the node object that is sent to your clients (node.parent). then you can ask MindMapModel.getMindMap().nodes.get(id) and this SHOULD return the actual node object of the parent.

I have not tested this yet, but this is how I imagined to use it one day to implement collaboration between clients. I am excited to see if you manage to make it work.

Please let me know if you need more support.

from mindmaps.

b3457m0d3 avatar b3457m0d3 commented on May 24, 2024

this is all handled inside mindmaps.MindMapModel

    //node is the created node object
    //if parent is root
    if(node.parentId == null){
      //get the root on the clients map
      var root = self.getMindMap().getRoot();
      var id = root.id;
      var parent = self.getMindMap().nodes.get(id);
    } else {
      //or just grab the parent by the nodes parentId
      var id = node.parentId;
      var parent = self.getMindMap().nodes.get(id);
    }
    //then turn the object back into a usable node
    var newNode = mindmaps.Node.fromObject(node);
    //finally add the node to the clients map
    self.createNode(newNode,parent);

works! ...kinda - the node is successfully created on the client's maps, however this triggers an infinite loop where nodes are continuously added back and forth- getting close though!

from mindmaps.

b3457m0d3 avatar b3457m0d3 commented on May 24, 2024

the server logs show that all the duplicate nodes have the same id, so i tried changing the get method to check if a node already exists before adding it

//EDIT:  created new function
mindmaps.NodeMap.prototype.exists = function(nodeId) {
  if(nodeId in this.nodes){
    return true;
  } else {
    return false;
  }
};

and then checking if the node is in the map already with

var check = self.getMindMap().nodes.exists(node.id);
    if(check === false){
      //code from above comment
    }

but still no luck... any ideas?
UPDATE: now the server logs are showing unique id's for each created node, so it's back to the drawing board ...

from mindmaps.

b3457m0d3 avatar b3457m0d3 commented on May 24, 2024

getting closer, at the beginning of mindmaps.MindMapModel added this.createFired=0;

eventBus.subscribe(mindmaps.Event.NODE_CREATED, function(node) {
    if(self.createFired==0){
      mindmaps.socket.emit(mindmaps.Event.NODE_CREATED,node);
      self.createFired++;
    }
  });

then after self.createNode(newNode,parent);, added self.createFired=0;
voila! no more endless loop!
still some slight tweaking before i move on to removing/updating nodes, but i'm calling this one closed

from mindmaps.

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.