bpmn-js-differ icon indicating copy to clipboard operation
bpmn-js-differ copied to clipboard

Enable ChangeHandler subclassing via prototype method

Open Copilot opened this issue 1 month ago • 1 comments

The isTracked function was module-scoped, preventing subclasses from overriding tracking logic for custom BPMN extension elements.

Changes

  • Converted isTracked to prototype method: Moved from standalone function to ChangeHandler.prototype.isTracked, enabling override via inheritance
  • Updated internal calls: Changed all isTracked(element) calls to this.isTracked(element) within ChangeHandler methods
  • Exported ChangeHandler: Added to public API exports in lib/index.js

Usage

import { ChangeHandler } from 'bpmn-js-differ';

class CustomChangeHandler extends ChangeHandler {
  isTracked(element) {
    // Custom tracking for extension elements
    if (element.$type === 'custom:ExtensionElement') {
      return { element, property: 'extension.' };
    }
    return super.isTracked(element);
  }
}
Original prompt

This section details on the original issue you should resolve

<issue_title>Support sub-classing</issue_title> <issue_description>### Problem We would like to develop a new ChangeHandler class that digs deeper into the BPMN Extension elements. We aren’t interested in changing your ChangeHandler for the standard BPMN elements - it works fine for those. But it doesn’t do such a good job with the extension elements and so we would like to be able to write our own. (Would also make it easier for Camunda to do the same :-)

Specifically, the base implementation tells us that an extension element is different but doesn’t give more detail as to how. We want to do this without losing (or having to duplicate) the ‘standard’ capabilities provided in the existing base implementation. We are struggling with this because of the isTracked function which is a module-scoped standalone function and not a prototype method. Thus we cannot override it through inheritance, making it impossible to extend the tracking logic.

Proposed Solution

As indicated, make the isTracked function a prototype method and add an export for the ChangeHandler. That said there are probably other ways you may choose to implement this - but hopefully the intent is clear.

Alternatives

We considered Monkey patching but this doesn’t seem to be feasible in this case. For now we have duplicated the ChangeHandler whilst we experiment but we think this introduces a maintenance problem because every time your base implementation changes then we would have to apply those changes to our copy which we feel would be an unnecessary burden for the sake of a relatively minor change at your end.

Additional context

None. </issue_description>

<agent_instructions>Please provide a pull request that fixes the issue, implementing the proposed solution by the issue reporter:

As indicated, make the isTracked function a prototype method and add an export for the ChangeHandler.</agent_instructions>

Comments on the Issue (you are @copilot in this section)

  • Fixes bpmn-io/bpmn-js-differ#29

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot avatar Nov 06 '25 13:11 Copilot