Skip to content

Commit

Permalink
fix(command): return latest changed elements
Browse files Browse the repository at this point in the history
  • Loading branch information
philippfromme authored and barmac committed Oct 11, 2019
1 parent 73c7a43 commit fd24592
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/command/CommandStack.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ CommandStack.prototype._popAction = function() {
actions.pop();

if (!actions.length) {
this._eventBus.fire('elements.changed', { elements: uniqueBy('id', dirty) });
this._eventBus.fire('elements.changed', { elements: uniqueBy('id', dirty.reverse()) });

dirty.length = 0;

Expand Down
27 changes: 26 additions & 1 deletion test/spec/command/CommandStackSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ describe('command/CommandStack', function() {
};


it('should update dirty shapes after change', inject(function(commandStack, eventBus) {
it('should update dirty elements after change', inject(function(commandStack, eventBus) {

// given
commandStack.registerHandler('outer-command', OuterHandler);
Expand All @@ -683,6 +683,31 @@ describe('command/CommandStack', function() {
expect(events).to.eql([ [ s1, s2 ] ]);
}));


it('should return latest dirty elements after change', inject(function(commandStack, eventBus) {

// given
commandStack.registerHandler('outer-command', OuterHandler);
commandStack.registerHandler('inner-command', InnerHandler);

var s1 = { id: 1 }, s2 = { id: 1 }, context = { s1: s1, s2: s2 };

var events = [];

function logEvent(e) {
events.push(e.elements);
}

eventBus.on('elements.changed', logEvent);

// when
commandStack.execute('outer-command', context);

// then
expect(events[0]).to.have.length(1);
expect(events[0][0]).to.equal(s2);
}));

});


Expand Down

0 comments on commit fd24592

Please sign in to comment.