NgRx Ducks
  • Introduction
  • @ngrx-ducks/core
    • Installation
    • Architecture
      • @StoreChunk
      • createDuck
      • getReducer
      • createMutableDuck
      • getMutableReducer
      • useSelect
      • useSelectors
      • useActions
    • Guides
      • Quick Start
  • Migrations
    • v15
  • Resources
  • FAQ
  • GitHub
  • Changelog
  • Sponsor
Powered by GitBook
On this page
  • Prerequisites
  • Mutable Action Dispatcher

Was this helpful?

  1. @ngrx-ducks/core
  2. Architecture

createMutableDuck

PreviousgetReducerNextgetMutableReducer

Last updated 3 years ago

Was this helpful?

Prerequisites

Please read about first before continue here.

Mutable Action Dispatcher

Working with immutable operations can be hard. It can also lead to code that is more difficult to read. The library allows you to simply mutate your state tree. Immer will take care about immutability for you.

NgRx Ducks provides a binding to immer that allows you to simply mutate your state. Therefore you simply need to use the function createMutableDuck. Its usage is nearly the same like createDuck. The only difference is that you do not need to return the next state in a reducer function since immer takes care of it.

import { createMutableDuck } from '@ngrx-ducks/core';

@StoreChunk()
export class CounterMutableFacade {
  // Basic usage without reducer
  loadCount = createMutableDuck('[Counter] Load Count', dispatch<number>());

  // Usage with a case reducer
  increment = createMutableDuck(
    '[Counter] Increment value',
    (state: CounterState, payload: number) => (state.count += payload)
  );
}

You will find a full example of a mutable facade at .

createMutableDuck
immerjs/immer
StackBlitz