javascriptinheritanceclojurescriptprototypal-inheritanceclojurescript-javascript-interop

Implementing static properties in ClojureScript


How can I mimic this JavaScript inheritance in ClojureScript?

class AccessController extends EventEmitter {

  static async create (db, options) { }

  static get type () {
    throw new Error('\'static get type ()\' needs to be defined in the inheriting class')
  }

  get type () {
    return this.constructor.type
  }

  async canAppend (entry, identityProvider) {
    return true
  }

}

class OtherController extends AccessController {

 constructor (db, options) {
    super()
  }

  static async create (db, options) {
    return new OtherController (db, options)
  }

  static get type () {
    return 'othertype'
  }

  async canAppend(entry, identityProvider) {
    return true
  }
}

Mu understanding is that:

This would be achieved like that:

(defn- OtherController
  {:jsdoc ["@constructor"]}
  [orbitdb options]
  (this-as this
    (.call AccessController this orbitdb options)
    this))

(defn create-access-controller []
  (gobj/extend
      ;; inheritance
      (.-prototype OtherController)
      (.-prototype AccessController)

    ;; methods
    #js {:canAppend (fn [entry identity-provider]                          
                      true)})

    ;; static properties
    (set! (.. OtherController -type) "othertype")

    (set! (.. OtherController -create) (fn [db options]
                                         (new OtherController db (clj->js {}))))
  OtherController)

I'm not sure how to:


Solution