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
  • Generate a mutable reducer

Was this helpful?

  1. @ngrx-ducks/core
  2. Architecture

getMutableReducer

PreviouscreateMutableDuckNextuseSelect

Last updated 3 years ago

Was this helpful?

Prerequisites

Please read about first before continue here. You nee a basic understanding about its API first.

Generate a mutable reducer

The method getMutableReducer takes care about connecting your case-reducer functions with immer and finally builds a reducer function that can be registered in the Store.

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

@StoreChunk()
export class Chunk {
  static reducer = getMutableReducer(initialState, CounterMutableFacade);
  
  // Basic usage without case 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)
  // );
}
import { Action, combineReducers } from '@ngrx/store';
import { MutableFacade } from './facade';
import { CounterState } from './counter.state';

export interface State {
  couter: CounterState;
}

export function reducers(state: State, action: Action) {
  return combineReducers<State>({
    couter: MutableFacade.reducer
  })(state, action);
}

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

createDuck
StackBlitz