Skip to content
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

Real-time : interface between MM.action and real-time event #51

Open
ClemDelp opened this issue Jun 10, 2014 · 4 comments
Open

Real-time : interface between MM.action and real-time event #51

ClemDelp opened this issue Jun 10, 2014 · 4 comments

Comments

@ClemDelp
Copy link

Hello,

i would like put my-mind in real-time, i'm using socket io to broadcast updates, now i would like to interface the real-time event to my-mind actions:

MM.action.insertNewItem
MM.actiion.removeItem
MM.action.MoveItem
etc

for example for insert a new item i need the father item, how i can get the item with its id? i can add a node to the current item put if i want add a node to a specific item how i have to do?

thank you

@ondras
Copy link
Owner

ondras commented Jun 10, 2014

Hi @ClemDelp,

first of all, let me acknowledge that a real-time synchronization is indeed a very cool feature and I am planning on adding some kind of firebase-based sync myself, sooner or later.

Second, I am not sure whether broadcasting individual actions and re-playing them on all connected clients is the right way to go. When using firebase to maintain sync, I would try to persist the mind map state to the firebase, merging the incoming data with current design any time a subtree changes.

Finally, I am not sure I completely understand your question. Are you looking for a way to listen for MM.Actions performed (in order to broadcast them), or do you seek help with re-playing them once the server notifies you? If the latter is the case, please see https://github.com/ondras/my-mind/blob/master/src/action.js for individual MM.Action.* constructor signatures. The main problem with Actions is that they always select/focus the item being manipulated, so they are not very good at re-playing history.

@ClemDelp
Copy link
Author

Hi Ondras,

Thank you for your fast answer,

Yes it's the second case, i'm using Backbone and i have a collection of nodes. All the collection's models have an id-father attributes used to re-build the tree under my-mind format.

Actually when a user manipulates the tree all actions are broadcasted to other users then the tree are completely reset and re-build with update data. Of course this solution is really bad for user experience.

That i would like it's something like:
collection:create -> trigger MM.action.InsertNewItem
collection:remove -> trigger MM.action.RemoveItem
collection:update-text -> trigger MM.action.SetText
collection:update-position -> trigger MM.action.MoveItem
collection:update-color -> trigger ...
...

For example for a new node:
1- The server passes me the updated model,
2- i get its id_father attributes,
3- i need to get the item corresponding to the id_father
4- and then apply MM.action.InsertNewItem with the model to id_father parent node.

And i would like apply this methode to all other actions but i can find actually a function to select an item by its id. I don't know excatly where is the collection of nodes? In the localstorage?

@ondras
Copy link
Owner

ondras commented Jun 11, 2014

The map itself (instanceof MM.Map) is available as MM.App.map. You can navigate its nodes using getRoot() and getChildren() calls.

The catch is that individual items do not expose their IDs; to find an item by ID, you will have to call its .toJSON() method and look at the id field in the resulting object.

Adding a MM.Map.prototype.getItemById might be a good idea, what do you think?

@ClemDelp
Copy link
Author

Thank you, with this three functions i can now get the item by it ID :

MM.Map.prototype.getItemById = function(id){
var nodes = MM.getItemsCollection();
return nodes[id];
}

MM.getItemsCollection = function(){
var json_map = MM.App.map.getRoot();
var nodes = {};
var nodes = MM.getNodesRecursive(nodes,json_map);
return nodes;
}

MM.getNodesRecursive = function(nodes,json){
nodes[json._id] = json;
if(json.getChildren()){
json.getChildren().forEach(function(child){
MM.getNodesRecursive(nodes,child);
});
}
return nodes;
}

I will try now to connect my Backbone events to my_mind MM.action

ondras added a commit that referenced this issue Oct 4, 2022
do not auto-update via firebase when in edit mode. fixes #57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants