clientIO / joint

A proven SVG-based JavaScript diagramming library powering exceptional UIs
https://jointjs.com
Mozilla Public License 2.0
4.51k stars 842 forks source link

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

Closed kumilingus closed 5 months ago

kumilingus commented 5 months ago

Description

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

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
        }
      }
   }
});