ng-state
  • Introduction
  • Main differences
  • Getting Started
    • Instalation
    • Examples
  • Core concepts
    • Main idea
      • More complex flow visualization
    • Configuration
      • Immer Setup
      • ImmutableJs Setup
    • Store
      • Operators
      • Optimistic updates plugin
      • Optimistic updates plugin
      • Form manager plugin
        • onChange hook
        • shouldUpdateState hook
        • Custom form elements
      • Persist state plugin
        • Configuring custom storage
    • Actions
      • Immer
      • ImmutaleJs
      • Injectable Actions
    • Components with Actions
      • Signal Actions
      • State Actions
    • @InjectStore decorator
    • @WithStore decorator
    • @ComponentState decorator
    • Dispatcher
  • Different scenarios
    • Passing list item index via router
    • ngOnChanges hook
    • FormManager pitfalls
  • Unit testing
    • Setup
    • Test store
    • Test actions
    • Test component with actions
    • Test with Angular TestBed
  • Debugging
    • Setup
    • Redux DevTools
    • Automated changes output
    • Manual state changes check
    • Additional debugging information
  • Production
    • Production mode
    • Server Side Rendering (SSR)
  • Other information
    • Best practices
    • CLI
      • Custom Configurations
    • Performance
    • Blog Posts
    • Contributing
Powered by GitBook
On this page

Was this helpful?

  1. Core concepts
  2. Store

Operators

PreviousStoreNextOptimistic updates plugin

Last updated 8 months ago

Was this helpful?

Store has multiple operators:

  • Select<T> - select peace of the state by provided path. Returns new observable. this.store.select(['todos']).T parameter is optional and falls back to any but recommended and specifies type of sub-selected state.

  • Initialize - initialize store with with new state. Returns observable holding initialized state. this.store.initialize(['todos', 'filter'], {newItem: false, usedItem: true})

  • Reset - resets selected peace of state to its initial state: this.store.select(['todos']).reset()

  • Map - transforms and returns state value.

  • Snapshot - returns snaphot of the current state.

  • toSignal - converts state to signal.

  • Update - updates selected state.

this.store.update((state: Map<any, any>) => {
        state.set('itemToStore', 'changed value');
});

According to immutableJS there is second parameter that can be passed to update function wrapToWithMutations It is used when you want to do multiple updates before triggering mutation.

https://stackoverflow.com/questions/28510753/when-should-i-use-withmutations-on-a-map-in-immutable-js