Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HtmlTag#withSelf, restore debounce example #155

Merged
merged 2 commits into from
Jan 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions calico/src/main/scala/calico/html/HtmlTag.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ final class HtmlTag[F[_], E] private[calico] (name: String, void: Boolean)(using
def apply[M](modifier: M)(using M: Modifier[F, E, M]): Resource[F, E] =
build.toResource.flatTap(M.modify(modifier, _))

def apply[M](mkModifier: E => M)(using M: Modifier[F, E, M]): Resource[F, E] =
def withSelf[M](mkModifier: E => M)(using M: Modifier[F, E, M]): Resource[F, E] =
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not to second guess 😅 maybe another option is fromSelf. But withSelf is good. I think 😅

build.toResource.flatTap(e => M.modify(mkModifier(e), e))

def apply[M <: Tuple](modifiers: M)(
Expand All @@ -40,7 +40,7 @@ final class HtmlTag[F[_], E] private[calico] (name: String, void: Boolean)(using
[a] => (r: Resource[F, E], m: Modifier[F, E, a], a: a) => r.flatTap(m.modify(a, _))
}

def apply[M <: Tuple](mkModifiers: E => M)(
def withSelf[M <: Tuple](mkModifiers: E => M)(
using inst: K0.ProductInstances[Modifier[F, E, _], M]): Resource[F, E] =
build.toResource.flatTap { e =>
inst.foldLeft(mkModifiers(e))(Resource.pure(e)) {
Expand Down
2 changes: 1 addition & 1 deletion docs/counter.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def Counter(label: String, initialStep: Int) =
div(
p(
"Step: ",
select { self =>
select.withSelf { self =>
(
allowedSteps.map(step => option(value := step.toString, step.toString)),
value <-- step.map(_.toString),
Expand Down
2 changes: 1 addition & 1 deletion docs/hello-world.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import fs2.concurrent.*
val app = SignallingRef[IO].of("world").toResource.flatMap { name =>
div(
label("Your name: "),
input { self =>
input.withSelf { self =>
(
placeholder := "Enter your name here",
// here, input events are run through the given Pipe
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ import fs2.concurrent.*
val component = SignallingRef[IO].of("world").toResource.flatMap { name =>
div(
label("Your name: "),
input { self =>
input.withSelf { self =>
(
placeholder := "Enter your name here",
// here, input events are run through the given Pipe
Expand Down
4 changes: 2 additions & 2 deletions docs/time.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ app.renderInto(node.asInstanceOf[fs2.dom.Node[IO]]).allocated.unsafeRunAndForget

## Debounce

```scala
```scala mdoc:js
import calico.*
import calico.html.io.{*, given}
import calico.syntax.*
Expand All @@ -89,7 +89,7 @@ val app = Channel.unbounded[IO, String].toResource.flatMap { emailCh =>
div(
span(
label("Your email: "),
input { self =>
input.withSelf { self =>
onInput --> (_.evalMap(_ => self.value.get).through(emailCh.sendAll))
}
),
Expand Down
6 changes: 3 additions & 3 deletions todo-mvc/src/main/scala/todomvc/TodoMvc.scala
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ object TodoMvc extends IOWebApp:
}

def TodoInput(store: TodoStore) =
input { self =>
input.withSelf { self =>
(
cls := "new-todo",
placeholder := "What needs to be done?",
Expand All @@ -96,7 +96,7 @@ object TodoMvc extends IOWebApp:
children <-- editing.map {
case true =>
List(
input { self =>
input.withSelf { self =>
val endEdit = self.value.get.flatMap { text =>
todo.update(_.map(_.copy(text = text))) *> editing.set(false)
}
Expand All @@ -113,7 +113,7 @@ object TodoMvc extends IOWebApp:
)
case false =>
List(
input { self =>
input.withSelf { self =>
(
cls := "toggle",
typ := "checkbox",
Expand Down