solution using backbone events instead of setTimeout
This commit is contained in:
parent
f9e6249615
commit
30d327f07a
1 changed files with 28 additions and 14 deletions
|
@ -70,7 +70,7 @@ Metamaps.Import = {
|
||||||
},
|
},
|
||||||
|
|
||||||
simplify: function(string) {
|
simplify: function(string) {
|
||||||
return string
|
return string;
|
||||||
.replace(/(^\s*|\s*$)/g, '')
|
.replace(/(^\s*|\s*$)/g, '')
|
||||||
.toLowerCase();
|
.toLowerCase();
|
||||||
},
|
},
|
||||||
|
@ -239,10 +239,28 @@ Metamaps.Import = {
|
||||||
var self = Metamaps.Import;
|
var self = Metamaps.Import;
|
||||||
|
|
||||||
parsedSynapses.forEach(function(synapse) {
|
parsedSynapses.forEach(function(synapse) {
|
||||||
self.createSynapseWithParameters(
|
//only createSynapseWithParameters once both topics are persisted
|
||||||
synapse.desc, synapse.category, synapse.permission,
|
var topic1 = Metamaps.Topics.get(self.cidMappings[node1_id]);
|
||||||
synapse.topic1, synapse.topic2
|
var topic2 = Metamaps.Topics.get(self.cidMappings[node2_id]);
|
||||||
);
|
var synapse_created = false
|
||||||
|
topic1.once('sync', function() {
|
||||||
|
if (topic1.id && topic2.id && !synapse_created) {
|
||||||
|
synaprse_created = true
|
||||||
|
self.createSynapseWithParameters(
|
||||||
|
synapse.desc, synapse.category, synapse.permission,
|
||||||
|
topic1, topic2
|
||||||
|
);
|
||||||
|
}//if
|
||||||
|
});
|
||||||
|
topic2.once('sync', function() {
|
||||||
|
if (topic1.id && topic2.id && !synapse_created) {
|
||||||
|
synaprse_created = true
|
||||||
|
self.createSynapseWithParameters(
|
||||||
|
synapse.desc, synapse.category, synapse.permission,
|
||||||
|
topic1, topic2
|
||||||
|
);
|
||||||
|
}//if
|
||||||
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -279,19 +297,15 @@ Metamaps.Import = {
|
||||||
},
|
},
|
||||||
|
|
||||||
createSynapseWithParameters: function(description, category, permission,
|
createSynapseWithParameters: function(description, category, permission,
|
||||||
node1_id, node2_id) {
|
topic1, topic2) {
|
||||||
var self = Metamaps.Import;
|
var self = Metamaps.Import;
|
||||||
var topic1 = Metamaps.Topics.get(self.cidMappings[node1_id]);
|
|
||||||
var topic2 = Metamaps.Topics.get(self.cidMappings[node2_id]);
|
|
||||||
var node1 = topic1.get('node');
|
var node1 = topic1.get('node');
|
||||||
var node2 = topic2.get('node');
|
var node2 = topic2.get('node');
|
||||||
|
|
||||||
if (topic1.isNew() || topic2.isNew()) {
|
if (!topic1.id || !topic2.id) {
|
||||||
return setTimeout(function() {
|
console.error("missing topic id when creating synapse")
|
||||||
self.createSynapseWithParameters(description, category, permission,
|
return;
|
||||||
node1_id, node2_id)
|
}//if
|
||||||
}, 200);
|
|
||||||
}
|
|
||||||
|
|
||||||
var synapse = new Metamaps.Backbone.Synapse({
|
var synapse = new Metamaps.Backbone.Synapse({
|
||||||
desc: description,
|
desc: description,
|
||||||
|
|
Loading…
Reference in a new issue