Skip to content

Commit fdda9fe

Browse files
fdietzecornermanscala-stewarddependabot[bot]
authored
update colibri with lazy rx (#137)
* update colibri with lazy rx * fix * chore: format code * Update magnolia to 1.1.3 (#76) * Bump cypress-io/github-action from 5.0.4 to 5.0.5 (#77) Bumps [cypress-io/github-action](https://github.com/cypress-io/github-action) from 5.0.4 to 5.0.5. - [Release notes](https://github.com/cypress-io/github-action/releases) - [Commits](cypress-io/github-action@v5.0.4...v5.0.5) --- updated-dependencies: - dependency-name: cypress-io/github-action dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * fix? * update * update * update * Update instances.scala * update plugins * update scala version * update scala * format * update * Update build.sbt --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: johannes karoff <johannes@karoff.net> Co-authored-by: GitHub Actions Bot <> Co-authored-by: Scala Steward <43047562+scala-steward@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
1 parent 2b49db3 commit fdda9fe

File tree

8 files changed

+32
-45
lines changed

8 files changed

+32
-45
lines changed

build.sbt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ inThisBuild(
2222
)
2323

2424
val versions = new {
25-
val outwatch = "1.0.0-RC15"
26-
val colibri = "0.7.8"
25+
val outwatch = "1.0.0-RC18"
26+
val colibri = "0.8.0"
27+
2728
val funPack = "0.3.2"
2829
val scalaTest = "3.2.12"
2930
}

cypress/e2e/spec.cy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe('Form interactions', () => {
2626
cy.get('input').clear().type('2.3')
2727
cy.get('.value').should('have.text', '2.3')
2828
cy.get('input').clear().type('1e+230')
29-
cy.get('.value').should('have.text', '1e+230')
29+
cy.get('.value').should('have.text', '10030')
3030
})
3131
})
3232

demo/src/main/scala/Main.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package webapp
33
import outwatch._
44
import outwatch.dsl._
55
import cats.effect.SyncIO
6-
import colibri.reactive._
76

87
import formidable._
98

@@ -59,7 +58,7 @@ object Main extends Extras {
5958
)
6059
}
6160

62-
def formFrame[T: Form](name: String): VMod = Owned {
61+
def formFrame[T: Form](name: String): VMod = {
6362
val state = Form.state[T]
6463
div(
6564
cls := name,

formidable/src/main/scala-2/Form-Scala2.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ trait FormDerivation {
1414
def join[T](ctx: CaseClass[Typeclass, T]): Form[T] = new Form[T] {
1515
override def default: T = ctx.construct(param => param.default.getOrElse(param.typeclass.default))
1616

17-
override def render(state: Var[T], config: FormConfig): VMod = Owned.function { implicit owner =>
17+
override def render(state: Var[T], config: FormConfig): VMod = {
1818
val subStates: Var[Seq[Any]] =
1919
state.imap[Seq[Any]](seq => ctx.rawConstruct(seq))(_.asInstanceOf[Product].productIterator.toList)
2020

@@ -38,7 +38,7 @@ trait FormDerivation {
3838
val defaultSubtype = ctx.subtypes.find(_.annotations.exists(_.isInstanceOf[Default])).getOrElse(ctx.subtypes.head)
3939
defaultSubtype.typeclass.default
4040
}
41-
override def render(selectedValue: Var[T], config: FormConfig): VMod = Owned.function { implicit owner =>
41+
override def render(selectedValue: Var[T], config: FormConfig): VMod = {
4242
val selectedSubtype: Var[Subtype[Form, T]] =
4343
selectedValue.imap[Subtype[Form, T]](subType => subType.typeclass.default)(value => ctx.split(value)(identity))
4444

formidable/src/main/scala-3/Form-Scala3.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ trait FormDerivation extends AutoDerivation[Form] {
1212
override def join[T](ctx: CaseClass[Typeclass, T]): Form[T] = new Form[T] {
1313
override def default: T = ctx.construct(param => param.default.getOrElse(param.typeclass.default))
1414

15-
override def render(state: Var[T], config: FormConfig): VMod = Owned.function { implicit owner =>
15+
override def render(state: Var[T], config: FormConfig): VMod = {
1616
val subStates: Var[Seq[Any]] =
1717
state.imap[Seq[Any]](seq => ctx.rawConstruct(seq))(_.asInstanceOf[Product].productIterator.toList)
1818

@@ -35,7 +35,7 @@ trait FormDerivation extends AutoDerivation[Form] {
3535
val defaultSubtype = ctx.subtypes.find(_.annotations.exists(_.isInstanceOf[Default])).getOrElse(ctx.subtypes.head)
3636
defaultSubtype.typeclass.default
3737
}
38-
override def render(selectedValue: Var[T], config: FormConfig): VMod = Owned.function { implicit owner =>
38+
override def render(selectedValue: Var[T], config: FormConfig): VMod = {
3939
val selectedSubtype: Var[SealedTrait.Subtype[Form, T, _]] =
4040
selectedValue.imap[SealedTrait.Subtype[Form, T, _]](subType => subType.typeclass.default)(value =>
4141
ctx.choose(value)(_.subtype)

formidable/src/main/scala/Form.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ trait Form[T] {
2121
override def render(
2222
state: Var[S],
2323
config: FormConfig,
24-
): VMod = Owned { Form.this.render(state.imap(f)(g), config) }
24+
): VMod = Form.this.render(state.imap(f)(g), config)
2525
}
2626
}
2727

formidable/src/main/scala/FormConfig.scala

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ trait FormConfig {
5454
state: Var[String],
5555
inputPlaceholder: String = "",
5656
validationMessage: Rx[Option[String]] = Rx.const(None),
57-
): VMod = Owned {
57+
): VMod =
5858
div(
5959
input(
6060
tpe := "text",
@@ -63,18 +63,15 @@ trait FormConfig {
6363
onInput.stopPropagation.value --> state,
6464
),
6565
validationMessage.map(_.map(msg => div(msg, color.red))),
66-
): VMod
67-
}
66+
)
6867

6968
def selectInput[T](options: Seq[T], selectedValue: Var[T], show: T => String): VMod = {
7069
select(
71-
Owned.function { implicit owner =>
72-
options.zipWithIndex.map { case (opt, ind) =>
73-
option(dsl.value := ind.toString)(
74-
show(opt),
75-
selectedValue.map(sel => selected := opt == sel),
76-
)
77-
}
70+
options.zipWithIndex.map { case (opt, ind) =>
71+
option(dsl.value := ind.toString)(
72+
show(opt),
73+
selectedValue.map(sel => selected := opt == sel),
74+
)
7875
},
7976
onChange.value.map(index => options(index.toInt)) --> selectedValue,
8077
)

formidable/src/main/scala/instances.scala

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,57 +7,52 @@ package object formidable {
77

88
implicit val stringForm: Form[String] = new Form[String] {
99
def default = ""
10-
def render(state: Var[String], config: FormConfig) = Owned {
10+
def render(state: Var[String], config: FormConfig) =
1111
config.textInput(state)
12-
}
1312
}
1413

1514
implicit val intForm: Form[Int] = new Form[Int] {
1615
def default = 0
17-
def render(state: Var[Int], config: FormConfig) = Owned {
16+
def render(state: Var[Int], config: FormConfig) =
1817
encodedTextInput[Int](
1918
state,
2019
encode = _.toString,
2120
decode = str => str.toIntOption.toRight(s"'$str' could not be parsed as Int"),
2221
config,
2322
)
24-
}
2523
}
2624

2725
implicit val longForm: Form[Long] = new Form[Long] {
2826
def default = 0
29-
def render(state: Var[Long], config: FormConfig) = Owned {
27+
def render(state: Var[Long], config: FormConfig) =
3028
encodedTextInput[Long](
3129
state,
3230
encode = _.toString,
3331
decode = str => str.toLongOption.toRight(s"'$str' could not be parsed as Long"),
3432
config,
3533
)
36-
}
3734
}
3835

3936
implicit val doubleForm: Form[Double] = new Form[Double] {
4037
def default = 0.0
41-
def render(state: Var[Double], config: FormConfig) = Owned {
38+
def render(state: Var[Double], config: FormConfig) =
4239
encodedTextInput[Double](
4340
state,
4441
encode = _.toString,
4542
decode = str => str.toDoubleOption.toRight(s"'$str' could not be parsed as Double"),
4643
config,
4744
)
48-
}
4945
}
5046

5147
implicit val booleanForm: Form[Boolean] = new Form[Boolean] {
5248
def default = false
53-
def render(state: Var[Boolean], config: FormConfig) = Owned {
49+
def render(state: Var[Boolean], config: FormConfig) =
5450
config.checkbox(state)
55-
}
5651
}
5752

5853
implicit def optionForm[T: Form]: Form[Option[T]] = new Form[Option[T]] {
5954
def default = None
60-
def render(state: Var[Option[T]], config: FormConfig) = Owned {
55+
def render(state: Var[Option[T]], config: FormConfig) = {
6156
val checkboxState = state.transformVar[Boolean](_.contramap {
6257
case true => Some(Form[T].default)
6358
case false => None
@@ -76,7 +71,7 @@ package object formidable {
7671

7772
implicit def seqForm[T: Form]: Form[Seq[T]] = new Form[Seq[T]] {
7873
def default = Seq.empty
79-
def render(state: Var[Seq[T]], config: FormConfig) = Owned {
74+
def render(state: Var[Seq[T]], config: FormConfig) =
8075
state.sequence.map(seq =>
8176
config.formSequence(
8277
seq.zipWithIndex.map { case (innerState, i) =>
@@ -87,8 +82,7 @@ package object formidable {
8782
},
8883
addButton = config.addButton(() => state.update(_ :+ Form[T].default)),
8984
)
90-
): VMod
91-
}
85+
)
9286
}
9387

9488
implicit def vectorForm[T](implicit seqForm: Form[Seq[T]]): Form[Vector[T]] = seqForm.imap(_.toVector)(_.toSeq)
@@ -99,18 +93,14 @@ package object formidable {
9993
encode: T => String,
10094
decode: String => Either[String, T],
10195
config: FormConfig,
102-
)(implicit owner: Owner): VMod = {
103-
val fieldState = Var(encode(state.now()))
104-
val validationMessage: Var[Option[String]] = Var(None)
96+
): VMod = {
97+
val validatedFieldState: Var[(String, Either[String, T])] = Var.createStateful(
98+
state.contramapIterable { case (_, decoded) => decoded.toOption },
99+
state.map(t => (encode(t), Right(t))),
100+
)
105101

106-
state.foreach { value => fieldState.set(encode(value)) }
107-
fieldState.map(decode).foreach {
108-
case Left(msg) =>
109-
validationMessage.set(Some(msg))
110-
case Right(value) =>
111-
validationMessage.set(None)
112-
state.set(value)
113-
}
102+
val fieldState = validatedFieldState.imap[String](str => (str, decode(str)))(_._1)
103+
val validationMessage = validatedFieldState.map(_._2.left.toOption)
114104

115105
config.textInput(fieldState, validationMessage = validationMessage)
116106
}

0 commit comments

Comments
 (0)