kolobok_ua
kolobok_ua

Reputation: 4220

How to extend JointJs elements/links with typescript

How to extend JointJs elements/links with typescript?

I've tried to use this.set("defaults", obj), but it's ignored by jointjs.

Upvotes: 1

Views: 1222

Answers (1)

kolobok_ua
kolobok_ua

Reputation: 4220

JointJs has definition file for typescript: https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/jointjs

JointJs models are extended from Backbone, so it's possible to use this.set(key, value) expressions in constructor, except for "defaults" parameter, that needs to be written as method.

Example:

class MyType extends joint.shapes.basic.Rect {
  constructor(attributes?: any, options?: any) {
    super(attributes, options);
    this.set("markup", "<rect/>");
  }
  defaults(): Backbone.ObjectHash {
    return joint.util.deepSupplement({...}, joint.shapes.basic.Rect.prototype.defaults);
  }
}

In subclasses of MyType it's possible to use super.defaults():

defaults(): Backbone.ObjectHash {
    return joint.util.deepSupplement({...}, super.defaults())
}

Upvotes: 1

Related Questions