Create custom rule for 'elements.move'

I cannot create custom handler for rules already handled by bpmn-js.
This is because the BpmnRules implementation for the elements.move always returns something (never undefined). Which causes EventBus._invokeListener to call event.stopPropagation() and subsequently prevents the next listener from being invoked.

I agree this is a good pattern for event handling. But as I look at this from a rule engine point, I’d expected that the most restrictive rule would be the enforced one.

There’s no given solution, I can think of multiple scenarios when either solution is the preferred way.
But I do belive my work around below is not very pretty and there should be a better way.

(make sure my custom modules are loaded first)

Modeler.prototype._modules = [ customModules ].concat(Modeler.prototype._modules)

If you would like to provide a custom rule independant from the module load order, give it a priority, i.e.

function CustomRuleProvider() {

  // 1000 is the default priority
  this.addRule('foo.bar', 1100, function(context) {

    // say yes or no via return
  });
}

If that is not enough, simply replace the BpmnRules with whatever suites your domain best.

Rules can never filter, they can just say yes, no or I don’t care by design. Otherwise the rule evaluation gets much more complicated for no big gain.

2 Likes

I totally missed the priority feature… thanks