Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: set $parent on create and set #50

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Conversation

philippfromme
Copy link

@philippfromme philippfromme commented Feb 3, 2023

This pull request implements a simple approach to maintaining the $parent property.

What it does ✅

Sets $parent when using Moddle#create

var child = model.create('props:Parent', {
  child: model.create('props:Child')
});

console.log(parent.get('child').$parent);  

Sets $parent when using Base#set

var parent = model.create('props:Parent'),
    child = model.create('props:Child');

parent.set('child', child);

console.log(child.$parent);  

Unsets $parent when using Base#set

const child = model.create('props:Child');

const parent = model.create('props:Parent', {
  child
});

parent.set('child', undefined);

console.log(child.$parent);  

What it doesn't do ⛔

Setting parent without using API

var parent = model.create('props:Parent'),
    child = model.create('props:Child'),
    otherChild = model.create('props:Child');

parent.child = child;
console.log(child.$parent);  

parent.children.push(otherChild);
console.log(otherChild.$parent);  

Unsetting parent without using API

var parent = model.create('props:Parent'),
    child = model.create('props:Child');

parent.set('child', child);

parent.child = undefined;

console.log(child.$parent);  

This is the approach I'd prefer. Every model element has a clearly defined API. Using this API is the preferred way of working with model elements. Accessing properties without using the API (parent.child = child;) is possible but not necessarily intended. I consider setting and unsettling the parent using proxies as magic and, therefore, wouldn't implement that.


Closes #41

@bpmn-io-tasks bpmn-io-tasks bot added the in progress Currently worked on label Feb 3, 2023
@philippfromme
Copy link
Author

@barmac @marstamm @nikku @smbea, feel free to have a look and share your sentiment regarding my proposal.

@nikku
Copy link
Member

nikku commented Feb 3, 2023

Great initiative!

I consider setting and unsettling the parent using proxies as magic and, therefore, wouldn't implement that.

Not sure from this comment: Did you consider proxies? I'd love us to consider them, and discard if we found them unsuitable.

Unsetting parent

I think we cannot ship without that. If $parent is managed by the infrastructure then I'd assume that unsetting (via a well known path) does unset $parent, too. We'll otherwise not have a way to find out if an element is attached to the tree.

@philippfromme
Copy link
Author

Not sure from this comment: Did you consider proxies? I'd love us to consider them, and discard if we found them unsuitable.

I wanted to start the conversation first. I was anticipating the question about proxies. I'm not to fond of them. I agree that it's not great to set the $parent but not have any way of unsetting it. Maybe a Base#unset method is missing.

@nikku
Copy link
Member

nikku commented Feb 3, 2023

Maybe a Base#unset method is missing.

Usually we set to undefined instead. But Base#unset would be valid, too. We'd just need to make sure there exists a way to properly unset, too.

@philippfromme
Copy link
Author

Usually we set to undefined instead.

Now that I'm thinking about it, this could actually work. When calling set with undefined we unset $parent of all existing properties before removing them. I'll try that out.

@philippfromme
Copy link
Author

I'll try that out.

Done.

@philippfromme philippfromme marked this pull request as ready for review February 6, 2023 10:41
@bpmn-io-tasks bpmn-io-tasks bot added needs review Review pending and removed in progress Currently worked on labels Feb 6, 2023
@nikku nikku requested review from barmac and marstamm February 6, 2023 11:50
@nikku
Copy link
Member

nikku commented Feb 6, 2023

@philippfromme Did you try this against diagram-js / bpmn-moddle / bpmn-js? Great code-bases to integration-test against.

@philippfromme
Copy link
Author

@philippfromme Did you try this against diagram-js / bpmn-moddle / bpmn-js? Great code-bases to integration-test against.

No I haven't done that yet. I can do that, though. I assume that introducing this feature would allow us to remove a lot of child.$parent = parent across our libraries.

Copy link
Member

@barmac barmac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's verify that it does not break anything in the downstream libraries.

@bpmn-io-tasks bpmn-io-tasks bot added in progress Currently worked on and removed needs review Review pending labels Feb 9, 2023
@philippfromme
Copy link
Author

Let's verify that it does not break anything in the downstream libraries.

That's what I'm doing.

@philippfromme
Copy link
Author

I will pick this up again once I have time.

@marstamm marstamm marked this pull request as draft February 17, 2023 14:41
@marstamm
Copy link
Contributor

I will pick this up again once I have time.

I converted the PR to draft for now so we don't get notification on Slack about it

@nikku nikku added the backlog Queued in backlog label Sep 1, 2023 — with bpmn-io-tasks
@nikku nikku removed the in progress Currently worked on label Sep 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backlog Queued in backlog
Development

Successfully merging this pull request may close these issues.

Maintain $parent safely within the core
4 participants