@@ -316,6 +316,58 @@ class PropertyTest extends UdashCoreTest {
316
316
counter2 should be(1 )
317
317
}
318
318
319
+ " fire on transformed value changed or when forced" in {
320
+ val origin : Property [Option [Int ]] = Property (Some (0 ))
321
+ val transformed : ReadableProperty [Boolean ] = origin.transform((q : Option [Int ]) => q.isDefined)
322
+ var counter = 0
323
+
324
+ transformed.listen(_ => counter += 1 )
325
+
326
+ origin.set(Some (0 ))
327
+ counter shouldBe 0 // suppressed at origin
328
+
329
+ origin.set(Some (1 ))
330
+ counter shouldBe 0 // suppressed at transformed
331
+
332
+ origin.set(None )
333
+ counter shouldBe 1
334
+
335
+ origin.set(None )
336
+ counter shouldBe 1
337
+
338
+ origin.set(None , force = true )
339
+ counter shouldBe 2
340
+
341
+ origin.touch()
342
+ counter shouldBe 3
343
+ }
344
+
345
+ " fire on streamed value changed or when forced" in {
346
+ val origin : Property [Option [Int ]] = Property (Some (0 ))
347
+ val target = Property .blank[Boolean ]
348
+
349
+ origin.streamTo(target)((q : Option [Int ]) => q.isDefined)
350
+ var counter = 0
351
+
352
+ target.listen(_ => counter += 1 )
353
+
354
+ origin.set(Some (0 ))
355
+ counter shouldBe 0 // suppressed at origin
356
+
357
+ origin.set(Some (1 ))
358
+ counter shouldBe 0 // suppressed at target
359
+
360
+ origin.set(None )
361
+ counter shouldBe 1
362
+
363
+ origin.set(None )
364
+ counter shouldBe 1
365
+
366
+ // todo detect forced / touched?
367
+ // origin.set(None, force = true)
368
+ // counter shouldBe 2
369
+ }
370
+
319
371
" combine with other properties (single properties)" in {
320
372
val p1 = Property (1 )
321
373
val p2 = Property (2 )
@@ -518,7 +570,7 @@ class PropertyTest extends UdashCoreTest {
518
570
519
571
val p = Property (" 1,2,3,4,5" )
520
572
val s : ReadableSeqProperty [Int , ReadableProperty [Int ]] =
521
- p.transformToSeq((v : String ) => Try (v.split(" ," ).map(_.toInt).toSeq).getOrElse(Seq [Int ]()))
573
+ p.transformToSeq((v : String ) => Try (v.split(" ," ).map(_.trim. toInt).toSeq).getOrElse(Seq [Int ]()))
522
574
523
575
p.listenersCount() should be(0 )
524
576
@@ -549,6 +601,14 @@ class PropertyTest extends UdashCoreTest {
549
601
lastPatch.removed.size should be(2 )
550
602
elementsUpdated should be(2 )
551
603
604
+ // suppressed at s
605
+ p.set(" 5 ,4 ,3" )
606
+ s.get should be(Seq (5 , 4 , 3 ))
607
+ lastValue should be(s.get)
608
+ lastPatch.added.size should be(0 )
609
+ lastPatch.removed.size should be(2 )
610
+ elementsUpdated should be(2 )
611
+
552
612
lastValue = null
553
613
lastPatch = null
554
614
elementsUpdated = 0
0 commit comments