LowEvent is a framework for event-driven applications where events are present-tense, not past-tense.
LowEvent represents events of all kinds; RequestEvent, RouteEvent, RenderEvent and ResponseEvent.
Inherit from LowEvent to create your own event:
class MyEvent < LowEvent
def initialize(data:, action: :render)
super(key: self.class, action:)
@data = data
end
endObserve the event with:
class MyObserver
include Observers
observe MyEvent
def render(event:)
event.data
end
endTrigger the event's action on its observers with:
MyEvent.trigger(data: "Custom Data")ℹ️ For more info see Observers.
A LowEvent is primarily concerned with what is happening, not what has happened.
An Event-Command Hybrid:
| Event | LowEvent | Command | |
|---|---|---|---|
| Tense | Past | Past/Present/Future | Future |
| Naming | OrderCreated | OrderEvent | CreateOrder |
| Action | 🚫 | :create_order | ✅ |
| Mutability | Immutable | Mutable/Immutable | Immutable |
| State | Ordered Actions | 🚫 | |
| Broadcasting | One to many | Ordered one to many | One to one |
| Return value | 🚫 | Value or nil | Value |
LowEvent builds a tree of every event as it's occuring and every subsequent event that occurs because of that event:
Add gem 'low_event' to your Gemfile then:
bundle install