ThoughtWorksInc / Binding.scala

Reactive data-binding for Scala
https://javadoc.io/page/com.thoughtworks.binding/binding_2.13/latest/com/thoughtworks/binding/index.html
MIT License
1.59k stars 108 forks source link

[WIP] Dom component #132

Closed glmars closed 3 years ago

glmars commented 5 years ago

It's early early early preview of dom component feature (please, see discussion in https://github.com/ThoughtWorksInc/Binding.scala/issues/128).

The main idea is introducing special syntax to extract peace of a @dom powered code as the separate reusable elements. I'm called it - "dom components".

object Dialog {
  @dom
  def apply(id: Binding[String], children: BindingSeq[Node]): Binding[Div] = <div id={id.bind} class="dialog">{children}</div>
}

implicit final class DialogTags(x: TagsAndTags2.type) {
  @domcomponent
  val dialog = Dialog
}

Which can be used in @dom functions:

@dom val html = <dialog id="123"><button><i>OK</i></button></dialog>

It generates such DOM tree:

<div id="123" class="dialog"><button><i>OK</i></button></div>

:exclamation:Hardcode:exclamation: - only dialog tag is considered as a dom component in this preview

/cc @sadhen, @ccamel, @jfilali, @skaz1970, @maxkorolev, @csoren

Atry commented 5 years ago

I think the efforts of custom components can be split into a separate repository. I had a try in https://github.com/ThoughtWorksInc/dom.scala/

Atry commented 5 years ago

You may want to fork https://github.com/ThoughtWorksInc/dom.scala and hack on it

glmars commented 5 years ago

Unfortunately, your experiment (https://github.com/ThoughtWorksInc/dom.scala/commit/083f8c330e497002de4b03e00c87e9657e4d6e7b#diff-5f9d51a26102bb299d4706844f7678c4R619) breaks mine :smile:

Atry commented 5 years ago

Never mind. Both implementation are experiments. I think you can even create a brand new annotation. I imagined an @html annotation in https://www.reddit.com/r/scala/comments/5oo6x0/desktop_gui_and_custom_tags_in_bindingscala/?ref=share&ref_source=link , which is more intuitive than current @dom annotation.

Leonid Turnaev notifications@github.com 于2018年12月17日周一 下午7:25写道:

Unfortunately, your experiment (ThoughtWorksInc/dom.scala@083f8c3

diff-5f9d51a26102bb299d4706844f7678c4R619

https://github.com/ThoughtWorksInc/dom.scala/commit/083f8c330e497002de4b03e00c87e9657e4d6e7b#diff-5f9d51a26102bb299d4706844f7678c4R619) breaks mine 😄

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ThoughtWorksInc/Binding.scala/pull/132#issuecomment-447812645, or mute the thread https://github.com/notifications/unsubscribe-auth/AAktuv5yShyAT2lPU8TNwqsbssgqEysKks5u539EgaJpZM4ZV25r .

-- 杨博 (Yang Bo)

Atry commented 3 years ago

I think this issue has been solved in the Name based XML proposal. html.scala is implemented based on the Name based XML.