Skip to content

Commit

Permalink
Dont throw error if node not included in changes. Fix #1731 (#1733)
Browse files Browse the repository at this point in the history
* Dont throw error if node not included in changes. Fix #1731

* Add test
  • Loading branch information
brollb authored Jun 10, 2020
1 parent 68d3cde commit 25cf460
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
16 changes: 15 additions & 1 deletion src/plugins/TwoPhaseCommit/StagedChanges.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,13 @@ define([
return this.changes;
};

StagedChanges.prototype.resolveCreateId = function(id) {
StagedChanges.prototype.tryResolveCreateId = function(id) {
const gmeId = this._createdGMEIds[id];
return gmeId;
};

StagedChanges.prototype.resolveCreateId = function(id) {
const gmeId = this.tryResolveCreateId(id);
assert(gmeId, `Creation id not resolved to actual id: ${id}`);

return gmeId;
Expand All @@ -71,6 +76,15 @@ define([
return this.changes[id];
};

StagedChanges.prototype.tryGetNodeEdits = function(id) {
id = CreatedNode.isCreateId(id) ? this.tryResolveCreateId(id) : id;
if (id) {
return null;
}

return this.changes[id];
};

StagedChanges.prototype.getModifiedNodeIds = function() {
return Object.keys(this.changes);
};
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/TwoPhaseCommit/TwoPhaseCore.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ define([
TwoPhaseCore.prototype._forAllNodeChanges = function (node, fn) {
const nodeId = this.getPath(node);
for (let i = 0; i < this.queuedChanges.length; i++) {
const changes = this.queuedChanges[i].getNodeEdits(nodeId);
const changes = this.queuedChanges[i].tryGetNodeEdits(nodeId);
if (changes) {
fn(changes);
}
Expand Down
12 changes: 12 additions & 0 deletions test/unit/plugins/TwoPhaseCommit/TwoPhaseCore.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@ describe('TwoPhaseCore', function() {
});

describe('getPointerPath', function() {
it('should get pointer path for newly created node w/ staged changes', async function() {
const {META, rootNode, core} = plugin;
core.getStagedChanges();
const base = META.FCO;
const parent = rootNode;
const newNode = core.createNode({base, parent});
core.setPointer(newNode, 'test', base);

const baseId = core.getPointerPath(newNode, 'test');
assert.equal(baseId, core.getPath(base));
});

it('should get pointer path for newly created node', async function() {
const {META, rootNode, core} = plugin;
const base = META.FCO;
Expand Down

0 comments on commit 25cf460

Please sign in to comment.