Code Monkey home page Code Monkey logo

Comments (7)

kumilingus avatar kumilingus commented on September 25, 2024 1

It is the defaults :)

  • wrong order of merge arguments
  • super.default is a function in CBase
class CLink extends CBase {
  defaults() {
    return joint.util.merge(
      {},
      super.defaults(),
      {
        type: "CLink",
        attrs: {
          line: {
            stroke: "#ccc",
            strokeWidth: 2
          }
        }
      },
    );
  }
}

from joint.

alexandernst avatar alexandernst commented on September 25, 2024

Ooohh! 🤔

Ok, I have another questions. Why CBase is merging super.defaults, but CLink is merging super.defaults()? What is the difference between using super.defaults as a value and calling super.defaults() as a function?

from joint.

kumilingus avatar kumilingus commented on September 25, 2024

The shapes.standard.Link class is defined via the define method which using the extend method of Backbone. If you create a Backbone.Model this way (ES5 way), the defaults is a property, not a method. Therefore CBase needs to access it as a property.

The ES Class CBase defines the defaults as a method. Therefore CLink has to call it as a function.

I recommend reading this article which should explain this in detail. Also reading this Backbone issue might be helpful.

from joint.

alexandernst avatar alexandernst commented on September 25, 2024

Oohh, now I get it. Good thing to know :)
Thank you!!

from joint.

alexandernst avatar alexandernst commented on September 25, 2024

I have an extra question 🙏

Would it be possible to extend from 2 classes using this method? Lets say that I have CBaseLinkA which defines the stroke color (using the defaults()) and CBaseLinkB which defines the strokeWidth (also using the defaults()) and the markup attribute. Would it be possible to do something like

class MyLink extends merge(CBaseLinkA, CBaseLinkB) {
  defaults() {
    return joint.util.merge(
      {
        attrs: { line: { fill: "red" } }
      },
      super.defaults() // ???? 
    )
  }
}

from joint.

kumilingus avatar kumilingus commented on September 25, 2024

Perhaps you can check this discussion.

from joint.

alexandernst avatar alexandernst commented on September 25, 2024

Hmmm, I think I saw similar stuff in SO, but I'm not really sure how to handle the defaults(), since that is threated in a very special way. I'll play around and report back if I find a way of achieving this!

from joint.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.