fix(viewer): add priority and context arguments to events

Closes #393
This commit is contained in:
Ricardo Matias 2015-10-22 10:37:33 +02:00 committed by pedesen
parent b21fb7cec3
commit 4930fd72d4
2 changed files with 34 additions and 4 deletions

View File

@ -19,7 +19,7 @@ function initListeners(diagram, listeners) {
var events = diagram.get('eventBus');
listeners.forEach(function(l) {
events.on(l.event, l.handler);
events.on(l.event, l.priority, l.handler, l.that);
});
}
@ -331,14 +331,14 @@ Viewer.prototype.destroy = function() {
* @param {String} event
* @param {Function} handler
*/
Viewer.prototype.on = function(event, handler) {
Viewer.prototype.on = function(event, priority, handler, that) {
var diagram = this.diagram,
listeners = this.__listeners = this.__listeners || [];
listeners.push({ event: event, handler: handler });
listeners.push({ event: event, priority: priority, handler: handler, that: that });
if (diagram) {
diagram.get('eventBus').on(event, handler);
diagram.get('eventBus').on(event, priority, handler, that);
}
};

View File

@ -119,6 +119,36 @@ describe('Viewer', function() {
});
describe('#on', function() {
it('should fire with given three', function(done) {
// given
var viewer = new Viewer({ container: container });
var xml = require('../fixtures/bpmn/empty-definitions.bpmn');
// when
viewer.on('foo', 1000, function() {
return 'bar';
}, viewer);
// then
viewer.importXML(xml, function(err) {
var eventBus = viewer.get('eventBus');
var result = eventBus.fire('foo');
expect(result).to.equal('bar');
done();
});
});
});
describe('overlay support', function() {
it('should allow to add overlays', function(done) {