scala-js/scala-js-dom

Add support for the Push API

kapunga opened this issue · 6 comments

Add support for the Push API specified here:

https://developer.mozilla.org/en-US/docs/Web/API/Push_API

I'm adding this ticket because I wasn't sure if this was left out on purpose or not. If it's desired I will submit a pull request a little later as I've already added support for most of it to a previous version. (I had to add it to a local 0.8.2 due to compatibility issues in another library I'm using.)

That would be fine to add! Naturally it would sit in org.scalajs.dom.experimental since only firefox supports it, and things outside of the experimental package are supposed to work on all current mainstream browsers.

Is there a preferred way of dealing with links from core classes to experimental ones? In this this case we need ServiceWorkerRegistration.pushManager to access parts of the Push API.

We use implicits to overlay extra functionality onto existing classes. Probably the best place to add the implicit would be in a package object for your extension, such as org.scalajs.dom.experimental.push.

I'm having a little trouble patching functionality from experimental onto types in raw and was wondering if anyone had any ideas what I'm doing wrong. I need to add a property to org.scalajs.dom.raw.ServiceWorkerRegistration to a trait I've implemented for the PushManager in the experimental package. I've tried a couple of methods and have been unsuccessful, although both methods compile error free.

I tried the monkey patching pattern from here

// In PushManager.scala
@JSName("ServiceWorkerRegistration")
@js.native
trait PushServiceWorkerRegistration extends ServiceWorkerRegistration {
  var pushManager: PushManager = js.native
}

// In org.scalajs.dom.experimental package object:
  implicit def pushServiceWorkerRegistration(swr: ServiceWorkerRegistration): PushServiceWorkerRegistration =
    swr.asInstanceOf[PushServiceWorkerRegistration]

I've tried an implicit class like this:

// In org.scalajs.dom.experimental package object:
  @JSName("ServiceWorkerRegistration")
  @js.native
  implicit class PushServiceWorkerRegistration(swr: ServiceWorkerRegistration) extends ServiceWorkerRegistration {
    var pushManager: PushManager = js.native
  }

Any ideas?

Actually, nevermind, looks like someone has moved ServiceWorkerRegistration to experimental.