Selector

public struct Selector<T> : SyncSelectorNode where T : Equatable

A selector is a pure function that accepts atoms or other sync selectors as input. When these upstream atoms or sync selectors are updated, the selector function will be re-evaluated. Components can subscribe to selectors just like atoms, and will then be re-rendered when the selectors change. Selectors are used to calculate derived data that is based on state. This lets us avoid redundant state because a minimal set of state is stored in atoms, while everything else is efficiently computed as a function of that minimal state.

 let currentBooksSel = selector { accessor -> [Book] in
    let books = accessor.get(allBookStore)
      if let category = accessor.get(selectedCategoryState) {
          return books.filter { $0.category == category }
      }
    return books
}
  • T

    Undocumented

    Declaration

    Swift

    public typealias T = T
  • E

    Undocumented

    Declaration

    Swift

    public typealias E = Never
  • key

    Undocumented

    Declaration

    Swift

    public let key: NodeKey
  • get

    Undocumented

    Declaration

    Swift

    public let get: (StateGetter) throws -> T
  • Undocumented

    Declaration

    Swift

    public func getValue(_ accessor: StateGetter) throws -> T