Class: Low::Event

Inherits:
Object
  • Object
show all
Includes:
Low::Events::Definable, Support::ValueObject, LowType, Observers
Defined in:
lib/interfaces/event.rb

Overview

An event represents what is currently happening in your application.

Events are mutable in most cases (except for RenderEvent). They are action-driven, representing inputs and outputs that are currently happening in a linear pipeline-like flow. They are present-tense and one-to-many with one return value. The result of the previous event is made available to the next event. [UNRELEASED]

Integrations:

  • Observers for observer pattern which we wrap in an event-centric API

  • EventPool for a tree of events and their child events

  • LowState for state machines to trigger multiple actions [UNLRELEASED]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Support::ValueObject

#==, #eql?, #hash

Methods included from Low::Events::Definable

#define, included

Constructor Details

#initialize(key:, action: nil, children: []) ⇒ Event

The subclass will provide the key, usually “self.class”.



29
30
31
32
33
34
# File 'lib/interfaces/event.rb', line 29

def initialize(key:, action: nil, children: [])
  @key = key
  @action = action
  @children = children
  @created_at = Process.clock_gettime(Process::CLOCK_MONOTONIC, :millisecond)
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



25
26
27
# File 'lib/interfaces/event.rb', line 25

def action
  @action
end

#childrenObject

Returns the value of attribute children.



26
27
28
# File 'lib/interfaces/event.rb', line 26

def children
  @children
end

#created_atObject (readonly)

Returns the value of attribute created_at.



25
26
27
# File 'lib/interfaces/event.rb', line 25

def created_at
  @created_at
end

#keyObject (readonly)

Returns the value of attribute key.



25
26
27
# File 'lib/interfaces/event.rb', line 25

def key
  @key
end

Class Method Details

.inherited(child) ⇒ Object



52
53
54
# File 'lib/interfaces/event.rb', line 52

def inherited(child)
  child.include LowType
end

.take(**kwargs) ⇒ Object



50
# File 'lib/interfaces/event.rb', line 50

def take(**kwargs) = new(**kwargs).take

.trigger(**kwargs) ⇒ Object



49
# File 'lib/interfaces/event.rb', line 49

def trigger(**kwargs) = new(**kwargs).trigger

Instance Method Details

#takeObject



42
43
44
45
46
# File 'lib/interfaces/event.rb', line 42

def take
  event_tree = branch
  key = Observers::Keys[@key]
  key.take(event: self) { restore_level(event_tree:) }
end

#triggerObject



36
37
38
39
40
# File 'lib/interfaces/event.rb', line 36

def trigger
  event_tree = branch
  key = Observers::Keys[@key]
  key.trigger(event: self) { restore_level(event_tree:) }
end