Class: Hibiki::Derived
- Inherits:
-
Object
- Object
- Hibiki::Derived
- Defined in:
- lib/hibiki/derived.rb
Overview
---- derived / computed -----------------------------------------------------
Instance Method Summary collapse
-
#call ⇒ Object
Solid signals are getter functions;
sig.()reads (and registers). -
#initialize(equals: nil, &block) ⇒ Derived
constructor
equals: per-signal equality (Solid's createMemo takes it too).
- #inspect ⇒ Object
- #invalidate ⇒ Object
-
#peek ⇒ Object
Read without subscribing the reader.
- #to_s ⇒ Object
- #value ⇒ Object
Methods included from Observer
#add_source, #clear_sources, #sources, #sources_changed?
Methods included from Trackable
#changed_from?, #notify, #register_dependency, #subscribers, #unsubscribe
Constructor Details
#initialize(equals: nil, &block) ⇒ Derived
equals: per-signal equality (Solid's createMemo takes it too). A derived has no write gate, so it matters only at the flush gate — observers ask changed_from?, which consults it (see Trackable).
12 13 14 15 16 |
# File 'lib/hibiki/derived.rb', line 12 def initialize(equals: nil, &block) @block = block @equals = equals @dirty = true end |
Instance Method Details
#call ⇒ Object
Solid signals are getter functions; sig.() reads (and registers).
32 |
# File 'lib/hibiki/derived.rb', line 32 def call = value |
#inspect ⇒ Object
42 |
# File 'lib/hibiki/derived.rb', line 42 def inspect = "#<Hibiki::Derived #{@dirty ? 'dirty' : @value.inspect}>" |
#invalidate ⇒ Object
34 35 36 37 38 39 |
# File 'lib/hibiki/derived.rb', line 34 def invalidate return if @dirty @dirty = true notify # propagate dirtiness downstream (derived-of-derived, effects) end |
#peek ⇒ Object
Read without subscribing the reader. A dirty derived still recomputes (collecting its own deps as usual) — peek only skips the outward edge.
26 27 28 29 |
# File 'lib/hibiki/derived.rb', line 26 def peek recompute if @dirty @value end |
#to_s ⇒ Object
41 |
# File 'lib/hibiki/derived.rb', line 41 def to_s = value.to_s |
#value ⇒ Object
18 19 20 21 22 |
# File 'lib/hibiki/derived.rb', line 18 def value recompute if @dirty register_dependency @value end |