Class: Hibiki::State
Overview
---- writable signal --------------------------------------------------------
Instance Method Summary collapse
-
#call ⇒ Object
Solid signals are getter functions;
sig.()reads (and registers). -
#initialize(value) ⇒ State
constructor
A new instance of State.
- #inspect ⇒ Object
-
#peek ⇒ Object
Read without subscribing (per-signal untrack), for read-modify-write effects that must not depend on what they write.
- #to_s ⇒ Object
-
#update ⇒ Object
sugar for in-place updates: counter.update { it + 1 }.
- #value ⇒ Object
- #value=(new_value) ⇒ Object
Methods included from Trackable
#notify, #register_dependency, #subscribers, #unsubscribe
Constructor Details
#initialize(value) ⇒ State
Returns a new instance of State.
8 9 10 |
# File 'lib/hibiki/state.rb', line 8 def initialize(value) @value = value end |
Instance Method Details
#call ⇒ Object
Solid signals are getter functions; sig.() reads (and registers).
22 |
# File 'lib/hibiki/state.rb', line 22 def call = value |
#inspect ⇒ Object
39 |
# File 'lib/hibiki/state.rb', line 39 def inspect = "#<Hibiki::State #{@value.inspect}>" |
#peek ⇒ Object
Read without subscribing (per-signal untrack), for read-modify-write effects that must not depend on what they write.
19 |
# File 'lib/hibiki/state.rb', line 19 def peek = @value |
#to_s ⇒ Object
38 |
# File 'lib/hibiki/state.rb', line 38 def to_s = value.to_s |
#update ⇒ Object
sugar for in-place updates: counter.update { it + 1 }
36 |
# File 'lib/hibiki/state.rb', line 36 def update = self.value = yield(@value) |
#value ⇒ Object
12 13 14 15 |
# File 'lib/hibiki/state.rb', line 12 def value register_dependency @value end |
#value=(new_value) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/hibiki/state.rb', line 24 def value=(new_value) return if new_value == @value @value = new_value # Solid wraps every write in runUpdates; mirroring that, an unbatched # write becomes an implicit batch of one. The whole invalidation wave # (all diamond branches) lands before effects flush, so an effect runs # once per write and never sees a half-updated graph. Hibiki.batch { notify } end |