Class: Hibiki::State

Inherits:
Object
  • Object
show all
Includes:
Trackable
Defined in:
lib/hibiki/state.rb

Overview

---- writable signal --------------------------------------------------------

Instance Method Summary collapse

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

#callObject

Solid signals are getter functions; sig.() reads (and registers).



22
# File 'lib/hibiki/state.rb', line 22

def call = value

#inspectObject



39
# File 'lib/hibiki/state.rb', line 39

def inspect = "#<Hibiki::State #{@value.inspect}>"

#peekObject

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_sObject



38
# File 'lib/hibiki/state.rb', line 38

def to_s = value.to_s

#updateObject

sugar for in-place updates: counter.update { it + 1 }



36
# File 'lib/hibiki/state.rb', line 36

def update = self.value = yield(@value)

#valueObject



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