Skip to content

How do I use ES6 syntax #113

Description

@benlieb

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`
  }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions