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

refactor(dia.CellView)!: early evaluation of calc attributes #2459

Merged
merged 5 commits into from
Jan 16, 2024

Conversation

kumilingus
Copy link
Contributor

@kumilingus kumilingus commented Jan 1, 2024

Description

Perform the following actions at the start of the cell view update:

  • evaluate the calc expressions used in the presentation attributes
  • translate (e.g. to dash-case) the presentation attribute names

This way, their evaluated value, and their true name become available for anyone dealing with them later (it's no longer needed to evaluate the calc() value multiple times or check for the existence of an attribute under different names).

Here's the new schema of how an attribute is set on the DOM node:
image

The PR also organizes the attributes into files based on their purpose.

Migration guide

It's only a breaking change if you define custom attributes (undocumented yet).

Before:

const MyElement = dia.Element.define('MyElement', {
  root: {
    myAttribute: 5
  }
}, {
  /* prototype */
}, {
  /* static */
  attributes: {
      // the name must match the attribute as used on the model `root/myAttribute`.
      myAttribute: {
        set: function(value, bbox, node, attrs) {
          return value + (attrs['myOtherAttribute'] || attrs['my-other-attribute']);
        }
      }
   }
});

Now:

const MyElement = dia.Element.define('MyElement', {
  root: {
    myAttribute: 5 // could be dash-cased or camel-cased
  }
}, {
  /* prototype */
}, {
  /* static */
  attributes: {
      // must be dash-cased (more precisely, it must be the true name returned by `V.attributeNames`)
      'my-attribute': {
        set: function(value, bbox, node, attrs) {
          return value + attrs['my-other-attribute']; // always `true` name
        }
      }
   }
});

@zbynekstara zbynekstara self-requested a review January 15, 2024 09:51
@kumilingus kumilingus merged commit da5000b into clientIO:dev Jan 16, 2024
1 check passed
@kumilingus kumilingus deleted the early-calc branch January 16, 2024 12:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants