Skip to content

Commit

Permalink
Expose Window#document
Browse files Browse the repository at this point in the history
  • Loading branch information
armanbilge committed Jan 31, 2023
1 parent c4e7411 commit f5c78b3
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 3 deletions.
21 changes: 21 additions & 0 deletions dom/src/main/scala-2/fs2/dom/WindowCrossCompat.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2022 Arman Bilge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package fs2.dom

private[dom] trait WindowCrossCompat[F[_]]

private trait WindowImplCrossCompat[F[_]] extends WindowCrossCompat[F]
2 changes: 2 additions & 0 deletions dom/src/main/scala-3/fs2/dom/Dom.scala
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ object Document {
}
}

opaque type HtmlDocument[F[_]] <: Document[F] = dom.HTMLDocument

opaque type Element[F[_]] <: Node[F] = dom.Element
opaque type HtmlElement[F[_]] <: Element[F] = dom.HTMLElement
opaque type HtmlAnchorElement[F[_]] <: HtmlElement[F] = dom.HTMLAnchorElement
Expand Down
38 changes: 38 additions & 0 deletions dom/src/main/scala-3/fs2/dom/WindowCrossCompat.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2022 Arman Bilge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package fs2.dom

import cats.effect.kernel.Async
import org.scalajs.dom

private trait WindowCrossCompat[F[_]] {

implicit def given_Dom_F: Dom[F]

def document: HtmlDocument[F]

}

private trait WindowImplCrossCompat[F[_]](using Async[F]) extends WindowCrossCompat[F] {

private[dom] def window: dom.Window

implicit def given_Dom_F = Dom.forAsync

def document = window.document.asInstanceOf[HtmlDocument[F]]

}
8 changes: 5 additions & 3 deletions dom/src/main/scala/fs2/dom/Window.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import cats.effect.kernel.Async
import fs2.Stream
import org.scalajs.dom

abstract class Window[F[_]] private {
abstract class Window[F[_]] private extends WindowCrossCompat[F] {

def history[S](implicit serializer: Serializer[F, S]): History[F, S]

Expand All @@ -41,8 +41,10 @@ object Window {
def apply[F[_]](implicit F: Async[F]): Window[F] =
apply(dom.window)

def apply[F[_]](window: dom.Window)(implicit F: Async[F]): Window[F] =
new Window[F] {
private def apply[F[_]](_window: dom.Window)(implicit F: Async[F]): Window[F] =
new Window[F] with WindowImplCrossCompat[F] {

private[dom] def window = _window

def history[S](implicit serializer: Serializer[F, S]) = History(window, window.history)

Expand Down

0 comments on commit f5c78b3

Please sign in to comment.