reactive_graph

Module traits

Source
Expand description

A series of traits to implement the behavior of reactive primitive, especially signals.

§Principles

  1. Composition: Most of the traits are implemented as combinations of more primitive base traits, and blanket implemented for all types that implement those traits.
  2. Fallibility: Most traits includes a try_ variant, which returns None if the method fails (e.g., if signals are arena allocated and this can’t be found, or if an RwLock is poisoned).

§Metadata Traits

  • DefinedAt is used for debugging in the case of errors and should be implemented for all signal types.
  • IsDisposed checks whether a signal is currently accessible.

§Base Traits

TraitModeDescription
TrackTracks changes to this value, adding it as a source of the current reactive observer.
NotifyNotifies subscribers that this value has changed.
ReadUntrackedGuardGives immutable access to the value of this signal.
WriteGuardGives mutable access to the value of this signal.

§Derived Traits

§Access

TraitModeCompositionDescription
WithUntrackedfn(&T) -> UReadUntrackedApplies closure to the current value of the signal and returns result.
Withfn(&T) -> UReadUntracked + TrackApplies closure to the current value of the signal and returns result, with reactive tracking.
GetUntrackedTWithUntracked + CloneClones the current value of the signal.
GetTGetUntracked + TrackClones the current value of the signal, with reactive tracking.

§Update

TraitModeCompositionDescription
UpdateUntrackedfn(&mut T)WriteApplies closure to the current value to update it, but doesn’t notify subscribers.
Updatefn(&mut T)UpdateUntracked + NotifyApplies closure to the current value to update it, and notifies subscribers.
SetTUpdateSets the value to a new value, and notifies subscribers.

§Using the Traits

These traits are designed so that you can implement as few as possible, and the rest will be implemented automatically.

For example, if you have a struct for which you can implement ReadUntracked and Track, then WithUntracked and With will be implemented automatically (as will GetUntracked and Get for Clone types). But if you cannot implement ReadUntracked (because, for example, there isn’t an RwLock so you can’t wrap in a ReadGuard, but you can still implement WithUntracked and Track, the same traits will still be implemented.

Traits§

  • Describes where the signal was defined. This is used for diagnostic warnings and is purely a debug-mode tool.
  • Allows disposing an arena-allocated signal before its owner has been disposed.
  • Helper trait to implement flatten() on Option<&Option<T>>.
  • Allows creating a signal from an async Stream.
  • Clones the value of the signal, without tracking the value reactively. and subscribes the active reactive observer (an effect or computed) to changes in its value.
  • Clones the value of the signal, without tracking the value reactively.
  • A variation of the Get trait that provides a signposted “always-non-reactive” API. E.g. for StoredValue.
  • Checks whether a signal has already been disposed.
  • Notifies subscribers of a change in this signal.
  • Give read-only access to a signal’s value by reference through a guard type, and subscribes the active reactive observer (an effect or computed) to changes in its value.
  • An alternative Read trait that works with Option<Readable> types.
  • Give read-only access to a signal’s value by reference through a guard type, without tracking the value reactively.
  • An alternative ReadUntracked trait that works with Option<Readable> types.
  • A variation of the Read trait that provides a signposted “always-non-reactive” API. E.g. for StoredValue.
  • Updates the value of the signal by replacing it.
  • A variation of the Set trait that provides a signposted “always-non-reactive” API. E.g. for StoredValue.
  • Allows converting a signal into an async Stream.
  • Allows tracking the value of some reactive data.
  • A reactive, mutable guard that can be untracked to prevent it from notifying subscribers when it is dropped.
  • Updates the value of a signal by applying a function that updates it in place, notifying its subscribers that the value has changed.
  • Updates the value of a signal by applying a function that updates it in place, without notifying subscribers.
  • A variation of the Update trait that provides a signposted “always-non-reactive” API. E.g. for StoredValue.
  • Give read-only access to a signal’s value by reference inside a closure, and subscribes the active reactive observer (an effect or computed) to changes in its value.
  • An alternative With trait that works with Option<Withable> types.
  • Give read-only access to a signal’s value by reference inside a closure, without tracking the value reactively.
  • An alternative WithUntracked trait that works with Option<Withable> types.
  • A variation of the With trait that provides a signposted “always-non-reactive” API. E.g. for StoredValue.
  • Gives mutable access to a signal’s value through a guard type. When the guard is dropped, the signal’s subscribers will be notified.
  • A variation of the Write trait that provides a signposted “always-non-reactive” API. E.g. for StoredValue.