Example #1
0
 public function __construct(Emitter $emitter)
 {
     $this->emitter = $emitter;
     parent::__construct(function () use($emitter) {
         $emitter->emit();
     });
 }
Example #2
0
 function testEventFilter()
 {
     $click = new observr\Emitter('click');
     $doOK = $click->filter(function ($button, $e) {
         if ($button instanceof Mock\Button) {
             return true;
         }
         return false;
     })->map(function ($button, $e) {
         $button->value = 'Ok';
     });
     $button = new Mock\Button();
     $c = 0;
     $button->attach($click, function ($sender, $e) use(&$c) {
         $c++;
     });
     $doOK($button);
     $this->assertEquals(1, $c);
     $this->assertEquals('Ok', $button->value);
 }