Fixed flickering when inserting properties from library by ensuring consistent ID generation
This commit is contained in:
@@ -59,8 +59,10 @@ const insertPropertyFromLibraryNode = new ValidatedMethod({
|
||||
'ancestors.id': nodeId,
|
||||
removed: {$ne: true},
|
||||
}).fetch();
|
||||
// The root node is last in the array of nodes
|
||||
nodes.push(node);
|
||||
|
||||
// The root node is first in the array of nodes
|
||||
// It must get the first generated ID to prevent flickering
|
||||
nodes = [node, ...nodes];
|
||||
|
||||
// re-map all the ancestors
|
||||
setLineageOfDocs({
|
||||
@@ -82,10 +84,10 @@ const insertPropertyFromLibraryNode = new ValidatedMethod({
|
||||
});
|
||||
|
||||
// Insert the creature properties
|
||||
let insertedDocIds = CreatureProperties.batchInsert(nodes);
|
||||
CreatureProperties.batchInsert(nodes);
|
||||
|
||||
// get the root inserted doc
|
||||
let rootId = insertedDocIds[insertedDocIds.length - 1];
|
||||
let rootId = node._id;
|
||||
|
||||
// Tree structure changed by inserts, reorder the tree
|
||||
reorderDocs({
|
||||
@@ -97,7 +99,6 @@ const insertPropertyFromLibraryNode = new ValidatedMethod({
|
||||
recomputeInactiveProperties(rootId);
|
||||
// Inserting a creature property invalidates dependencies: full recompute
|
||||
recomputeCreatureByDoc(rootCreature);
|
||||
|
||||
// Return the docId of the last property, the inserted root property
|
||||
return rootId;
|
||||
},
|
||||
|
||||
@@ -120,13 +120,19 @@ export function setLineageOfDocs({docArray, oldParent, newAncestry}){
|
||||
export function renewDocIds({docArray, collectionMap}){
|
||||
// map of {oldId: newId}
|
||||
let idMap = {};
|
||||
// Give new ids and map the changes
|
||||
|
||||
// Get a random generator that's consistent on client and server
|
||||
let randomSrc = DDP.randomStream('renewDocIds');
|
||||
|
||||
// Give new ids and map the changes as {oldId: newId}
|
||||
docArray.forEach(doc => {
|
||||
let oldId = doc._id;
|
||||
let newId = Random.id();
|
||||
let newId = randomSrc.id();
|
||||
doc._id = newId;
|
||||
idMap[oldId] = newId;
|
||||
});
|
||||
|
||||
// Remap all references using the new IDs
|
||||
const remapReference = ref => {
|
||||
if (idMap[ref.id]){
|
||||
ref.id = idMap[ref.id];
|
||||
|
||||
Reference in New Issue
Block a user