All Projects → timdeschryver → ngrx-etc

timdeschryver / ngrx-etc

Licence: MIT license
Utility functions for NgRx

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to ngrx-etc

ngrx-slice
Moved to https://github.com/nartc/nartc-workspace
Stars: ✭ 50 (-28.57%)
Mutual labels:  ngrx, immer
ngrx-entity-schematic
Angular schematic for quickly scaffolding NgRx Entities
Stars: ✭ 26 (-62.86%)
Mutual labels:  ngrx
Aspnetcore Angular Ngrx
🚀 An ASP.NET Core WebAPI Demo with an Angular Client using Ngrx store and effects and Signalr
Stars: ✭ 141 (+101.43%)
Mutual labels:  ngrx
Deox
Functional Type-safe Flux Standard Utilities
Stars: ✭ 200 (+185.71%)
Mutual labels:  ngrx
Pizza Sync
Pizza-Sync is a web app built on the frontend with angular, ngrx and on the backend with Nest. It let you and your friends/colleagues choose a pizza before placing a group order. Built using https://github.com/maxime1992/angular-ngrx-starter
Stars: ✭ 158 (+125.71%)
Mutual labels:  ngrx
Tinystate
A tiny, yet powerful state management library for Angular
Stars: ✭ 207 (+195.71%)
Mutual labels:  ngrx
Xsm
State Management made eXtraordinarily simple and effective for Angular, React, and Vue
Stars: ✭ 138 (+97.14%)
Mutual labels:  ngrx
ngrx-vis
Tool visualizing actions, reducers & effects in your Angular app
Stars: ✭ 49 (-30%)
Mutual labels:  ngrx
Rwa Trivia
Trivia App - Real World Angular series
Stars: ✭ 251 (+258.57%)
Mutual labels:  ngrx
Ngrx Store Freeze
@ngrx/store meta reducer that prevents state from being mutated.
Stars: ✭ 198 (+182.86%)
Mutual labels:  ngrx
Router Store
Bindings to connect the Angular Router to @ngrx/store
Stars: ✭ 187 (+167.14%)
Mutual labels:  ngrx
Aspnetcoreangularsignalr
SignalR ASP.NET Core Angular
Stars: ✭ 163 (+132.86%)
Mutual labels:  ngrx
Angular Ngrx Material Starter
Angular, NgRx, Angular CLI & Angular Material Starter Project
Stars: ✭ 2,623 (+3647.14%)
Mutual labels:  ngrx
Ngrx Course
NgRx (with NgRx Data) -The Complete Guide
Stars: ✭ 157 (+124.29%)
Mutual labels:  ngrx
react-immer-hooks
Easy immutability in React Hooks with Immer.
Stars: ✭ 45 (-35.71%)
Mutual labels:  immer
Angular Ngrx Chuck Norris
Chuck Norris Joke Generator w/ NgRx Store
Stars: ✭ 141 (+101.43%)
Mutual labels:  ngrx
Angular Ngrx Socket Frontend
Angular Ngrx Socket.IO Example
Stars: ✭ 177 (+152.86%)
Mutual labels:  ngrx
Angular Seed Advanced
Advanced Angular seed project with support for ngrx/store, ngrx/effects, ngx-translate, angulartics2, lodash, NativeScript (*native* mobile), Electron (Mac, Windows and Linux desktop) and more.
Stars: ✭ 2,279 (+3155.71%)
Mutual labels:  ngrx
ngrx-enums
A small library that provides the basis for using ts-enums for @ngrx actions and reducers.
Stars: ✭ 12 (-82.86%)
Mutual labels:  ngrx
ts-action-operators
TypeScript action operators for NgRx and redux-observable
Stars: ✭ 34 (-51.43%)
Mutual labels:  ngrx

NgRx-etc

All Contributors

mutableOn

Without the mutableOn function our entityReducer would look something like this.

const entityReducer = createReducer<{ entities: Record<number, { id: number; name: string }> }>(
  {
    entities: {},
  },
  on(create, (state, { type, ...entity }) => ({
    ...state,
    entities: { ...state.entities, [entity.id]: entity }
  }),
  on(update, (state, { id, newName }) => {
    const entity = state.entities[id]

    if (entity) {
      return {
        ...state,
        entities: {
          ...state.entities,
          [entity.id]: { ...entity, name: newName }
        }
      }
    }

    return state;
  },
  on(remove, (state, { id }) => {
    const { [id]: removedEntity, ...rest } = state.entities;

    return { ...state, entities: rest };
  }),
)

With the mutableOn function we are able to directly perform state mutations in reducers with less noise, and more concise code.

const entityReducer = createReducer<{ entities: Record<number, { id: number; name: string }> }>(
  {
    entities: {},
  },
  mutableOn(create, (state, { type, ...entity }) => {
    state.entities[entity.id] = entity
  }),
  mutableOn(update, (state, { id, newName }) => {
    const entity = state.entities[id]
    if (entity) {
      entity.name = newName
    }
  }),
  mutableOn(remove, (state, { id }) => {
    delete state.entities[id]
  }),
)

mutableReducer

For when you want to go all-in! Does work with the NgRx on method, as well as the mutableOn method. The only difference is that it's needed to return the state with the on method.

const entityReducer = createMutableReducer<{ entities: Record<number, { id: number; name: string }> }>(
  {
    entities: {},
  },
  on(create, (state, { type, ...entity }) => {
    state.entities[entity.id] = entity

    // explicit return state with `on`
    return state
  }),
  on(update, (state, { id, newName }) => {
    const entity = state.entities[id]
    if (entity) {
      entity.name = newName
    }

    // explicit return state with `on`
    return state
  }),
  mutableOn(remove, (state, { id }) => {
    delete state.entities[id]
    // don't have to return state with `mutableOn`
  }),
)

Contributors

Thanks goes to these wonderful people (emoji key):


Tim Deschryver

💻 ⚠️

Maarten Tibau

📖

xiansheng lu

📖

This project follows the all-contributors specification. Contributions of any kind welcome!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].