graphiti-api / spraypaint.js

Graphiti Client / Javascript ORM / JSONAPI
MIT License
107 stars 69 forks source link

How do I use ES6 syntax #113

Open benlieb opened 1 year ago

benlieb commented 1 year ago

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