-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
47 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,24 @@ | ||
package core | ||
|
||
import org.scalajs.dom.Element | ||
import org.scalajs.dom.* | ||
import org.scalajs.dom.HTMLDivElement as Div | ||
import org.scalajs.dom.Node | ||
import org.scalajs.dom.document | ||
|
||
type Initialization = (String, Node => Unit) | ||
trait Initialize[+A <: Element] extends (Initialization => A): | ||
trait Initialize[+A <: Element]: | ||
extension (id: String) | ||
inline def elementAt(pos: Node => Unit) = this(id, pos) | ||
inline def reset(): Unit = this(id, _ => ()) | ||
def elementAt(pos: Node => Unit): A | ||
def reset(): Unit | ||
|
||
object Initialize: | ||
given html: Initialize[Div] = (id, pos) => | ||
Option(document.getElementById(id)).foreach(_.remove()) | ||
val a = document.createElement("div").asInstanceOf[Div] | ||
a.id = id | ||
pos(a) | ||
a | ||
given Initialize[Div] with | ||
extension (id: String) | ||
def reset(): Unit = init(id, _ => ()) | ||
def elementAt(pos: Node => Unit): Div = init(id, pos) | ||
|
||
private inline def init(id: String, pos: Node => Unit) = | ||
Option(document.getElementById(id)).foreach(_.remove()) | ||
val a = document.createElement("div").asInstanceOf[Div] | ||
a.id = id | ||
pos(a) | ||
a | ||
end given | ||
end Initialize |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters