Skip to content

Commit

Permalink
Merge pull request #155 from armanbilge/pr/i132
Browse files Browse the repository at this point in the history
Add `HtmlTag#withSelf`, restore debounce example
  • Loading branch information
armanbilge authored Jan 22, 2023
2 parents e88ef0d + 577b787 commit 873ede1
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 10 deletions.
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 @@ -29,7 +29,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] =
build.toResource.flatTap(e => M.modify(mkModifier(e), e))

def apply[M <: Tuple](modifiers: M)(
Expand All @@ -38,7 +38,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

0 comments on commit 873ede1

Please sign in to comment.