Invisible objects in signal from event

Moderatoren: pmueller, SE - Design and Construction

typ
Windoof-User
Windoof-User
Beiträge: 32
Registriert: 5. Nov 2016 19:06

Invisible objects in signal from event

Beitrag von typ » 14. Jul 2018 17:57

Hi,
on some methods I get additional signal triggers.

Code: Alles auswählen

  val e1 = Evt[Int]()
  val s1 = e1 list
  val sth = Signal[List[Int]] {
    s1()
  }

  val printer = Signal[Unit] {
      println(sth())
  }
  e1(1)
  e1(2)
  e1(3)
  // prints List() List() List(1) List(2, 1) List(3, 2, 1)
  

Code: Alles auswählen

  val e1 = Evt[Int]()
  e1(1)
  val s1 = e1 list
  val sth = Signal[List[Int]] {
    s1()
  }

  val printer = Signal[Unit] {
      println(sth())
  }
  e1(2)
  e1(3)
  // prints List() List() List(2) List(3, 2)
It seems like the event to signal methods calls the signal macro 2 times with an empty list.

Where does that come from?

@edit
Actually it is not bad at all, since the contract says, that macro methods should not have side-effects.
Zuletzt geändert von typ am 14. Jul 2018 19:08, insgesamt 4-mal geändert.

VSchü
Windoof-User
Windoof-User
Beiträge: 26
Registriert: 5. Jul 2015 16:46

Re: Invisible objects in signal from event

Beitrag von VSchü » 14. Jul 2018 18:27

Without exactly knowing the answer, I would guess this is what Prof. Salvaneschi meant when he sad, that one should not have side effects (like printing) inside signals. Could you verify if this still happens when you outsource the printing to something like

Code: Alles auswählen

printer.changed += { println(_) }
?

Antworten

Zurück zu „Software Engineering - Design and Construction“