scala-js/scala-js-dom

`crypto` and it's deprecated package

japgolly opened this issue ยท 7 comments

I'd really love to have dom.crypto be of type js.UndefOr[Crypto]. It seems the impediment is the old deprecated package with the same name.

These are my ideas:

  1. change dom.crypto to be of type js.UndefOr[Crypto with DeprecatedCryptoPackage] so that at least in userland we can use it Crypto -- actually this won't work - deprecated crypto imports wouldn't be stable, not to mention that there's a js.UndefOr there

  2. Building on @sjrd's suggestion we could keep #588 as it but also add a webCrypto: js.UndefOr[Crypto] which we could deprecate in 3.x to be replaced by crypto

  3. just nuke the deprecated package, 2.0 is a new world

Any more ideas? I'm kinda happy with 3, but 2 would definitely be acceptable.

It's a bit ugly, but what if we add an implicit conversion to Crypto that brings in all the deprecated aliases? So that dom.crypto can still be used as if it is the old package. Would this work?

I don't think so. Cos source-compat is the concern the direct import statements would stop working. Plus maybe it wouldn't be worth it if the cost is an implicit anyway :)

Right, imports ๐Ÿ˜•

Regarding your idea 2, we already have a deprecated GlobalCrypto object or similar that could be used like that I think. Otherwise I'm ๐Ÿ‘ with it, I think I suggested something similar as well.

Oh another idea, we could add

object Crypto {
  def ifAvailable: js.UndefOr[Cypto]
}

It would be the same as option 2 above except instead of webCrypto it would be Crypto.ifAvailable. More of a 2b

GlobalCrypto has the wrong type for crypto and it's deprecated anyway.

Regarding your idea 2, we already have a deprecated GlobalCrypto object or similar that could be used like that I think. Otherwise I'm +1 with it, I think I suggested something similar as well.

Nice, so we'll go with a 2x option? Do you have a preference between webCrypto or Crypto.ifAvailable or something else?

IMO dom.webCrypto is best since it's very close to our eventual target of dom.crypto.

ok np, I'll do PR that after #588 is in ๐Ÿ‘