bpmn-io / bpmn-io/moddle

Maintain `$parent` safely within the core

Open
#41 2 comments 1 reaction 0 assignees View on GitHub
backlog enhancement spring cleaning
Dominant language
JavaScript
Stars
111
Forks
33
PR merge metrics
No merged PRs in 30d

Description

__Is your feature request related to a problem? Please describe__

The child to parent pointer `$parent` is important for model traversal. We do have [basic test coverage for it](https://github.com/bpmn-io/moddle/search?q=%24parent), however we do not ensure that it is being maintained as part of the core. Instead, libraries using it (i.e. [moddle-xml](https://github.com/bpmn-io/moddle-xml/blob/master/lib/read.js#L505), bpmn-js) manually maintain the property in various places. This is error prone and not properly done everywhere.

At best, we do automatically maintain the property:

```javascript
// $parent set during modeling
const foo = moddle.create('bpmn:ExtensionElements');

// during creation
const blub = { };
foo.values.push(blub); // blub = { $parent: foo }
foo.bar = { }; // bar = { $parent: foo }

// during removal
foo.values.pop(); // blub = { }
blub.$parent = null;
foo.bar = null; // bar = { }
```

__Describe the solution you'd like__

* [ ] `$parent` is maintained automatically by moddle so that I can rely on it

__Describe alternatives you've considered__

Keep `$parent` maintenance out of scope for the library.

__Additional context__

Brought up in the context of https://github.com/bpmn-io/bpmnlint/issues/69#issuecomment-1055354843.

Contributor guide

Open the contributing guide

Research direction

Review the existing $parent coverage linked in the issue and the manual maintenance in moddle-xml's lib/read.js, then compare it with the creation and removal examples. Define how core moddle should handle child assignment, collection changes, and removal, and add coverage showing that $parent is set and cleared consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.