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

How do I use ES6 syntax #113

Open
benlieb opened this issue Dec 30, 2022 · 0 comments
Open

How do I use ES6 syntax #113

benlieb opened this issue Dec 30, 2022 · 0 comments

Comments

@benlieb
Copy link

benlieb commented Dec 30, 2022

I'm confused because the docs have Typescript and ES5 syntax, but I generally write ES6.

I can't figure out how to instantiate my models with ES6. I'd really rather not write TS.

This works:

const ApplicationRecord = SpraypaintBase.extend(
  {
    static: {
      baseUrl: window.location.origin,
      apiNamespace: "/api"
    }
  }
)

const Tag = ApplicationRecord.extend(
  {
    static: {
      jsonapiType: "tags"
    },
    attrs: {
      name: attr(),
    },
    methods: {
      sayHi: function() {
        return `Hi I'm a ${this.name} tag`
      }
    }
  }
)

But I'd prefer to write something like this, thought I'm not sure how to define attributes etc... Please help...

export default class ApplicationRecord extends SpraypaintBase {
  static baseUrl = window.location.origin
  static apiNamespace = "/api"
}

export default class Tag extends ApplicationRecord {
  static jsonapiType = "tags"

 //attributes ... etc

  sayHi() {
    return `Hi I'm a ${this.name} tag`
  }
}
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

No branches or pull requests

1 participant