LogoLogo
  • Introduction
  • Intro
    • 🚀Getting Started
    • Key Characteristics
    • Fundamentals
    • Motivation
  • Fundamentals
    • 💾Units
      • BoolUnit
      • NumUnit
      • StringUnit
      • DictUnit
      • ListUnit
      • GenericUnit
    • 🤝Systems
      • AsyncSystem
      • Custom AsyncSystem
    • 🤜Action
    • 📦Cluster
  • 🔨Utilities
    • Stream
    • Selection
  • Integrations
    • Angular
    • React
      • useObservable Hook
      • useUnit Hook
  • 📖Guides
    • Configuration
    • Nesting
    • Events
    • Typings
    • Caching
    • Persistence
    • Immutability
    • Freeze and Mute
    • Development Environment
    • General Guidelines
  • More
    • 👀Examples
    • ✍️Articles
Powered by GitBook
On this page
  • Make a Selection
  • Static Value Access
  • Reactive Value Access

Was this helpful?

  1. Utilities

Selection

PreviousStreamNextAngular

Last updated 4 years ago

Was this helpful?

is a simple construct that operates on a nested property in the non-primitive Units' value, i.e.: , , and .

Selection offers the ability to access and observe a nested property at a certain path in a Unit's value.

Make a Selection

// create a Unit
const preferencesUnit = new DictUnit({initialValue: 
  {color: 'blue', music: 'EDM', game: 'GTA5'}
})

// make a selection
// the 'select' method takes path as it's params
const musicPreference = preferencesUnit.select('music')

Static Value Access

After creating a Selection object, we can access the value at the selected path anytime, without worrying if the value still exists or not.

// access the value at the selected path
console.log(musicPreference.value())
// logs 'EDM' immediately

Reactive Value Access

To observe the value over time we can make an Observable at the selected path, and subscribe to it.

// create an Observable
const musicPreference$ = musicPreference.asObservable()

// subsribe for reactive access
musicPreference$.subscribe(value => console.log(value))
// logs 'EDM' immediately, and
// will log whenever the value at the selected path changes
🔨
Selection
ListUnit
GenericUnit
DictUnit