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
  • Combining Multiple Units to create a Meaningful Cluster
  • Accessing and Observing not so nested values of the Unit

Was this helpful?

  1. Guides

Nesting

PreviousConfigurationNextEvents

Last updated 4 years ago

Was this helpful?

As we know, ActiveJS doesn't have a single store, it has storage , hence instead of creating slices, we create groups.

When you need to combine multiple storage Units (or even other ActiveJS constructs) you can do that using the , to build a nested data structure, instead of storing deeply nested values in the Units.

Combining Multiple Units to create a Meaningful Cluster

To do proper nesting and to make sure that you use ActiveJS Units as intended, you should try to keep the values of the Units flat, i.e.: as less nested as possible.

This would allow you to have clear and granular control over the state of your App. Updating and accessing the stored values would be much easier and efficient as well. For example:

// instead of doing this
const store = new DictUnit({initialValue: {
  token: 'auth-token',
  userProfile: {...},
  userPreferences: {...}
}})

// do this
const tokenUnit = new StringUnit({initialValue: 'auth-token'})
const userProfileUnit = new DictUnit({initialValue: {...}})
const userPreferencesUnit = new DictUnit({initialValue: {...}})

const userDataCluster = new Cluster({
  tokenUnit, userProfileUnit, userPreferencesUnit // using shorthand notation
})

Accessing and Observing not so nested values of the Unit

Even if you followed the above advice and kept your Units flat you might still want to create an even finer chunk of the information. For that purpose, you can create a from a Unit's value.

📖
Units
Cluster
Selection