All Projects → ngxs-labs → immer-adapter

ngxs-labs / immer-adapter

Licence: MIT license
🐹 Declarative state mutations

Programming Languages

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

Projects that are alternatives of or similar to immer-adapter

Reactor Addons
Official modules for the Reactor project
Stars: ✭ 175 (+272.34%)
Mutual labels:  adapter
Ecto mnesia
Ecto adapter for Mnesia Erlang term database.
Stars: ✭ 223 (+374.47%)
Mutual labels:  adapter
BaseToolsLibrary
Android通用适配器和常用的工具类
Stars: ✭ 24 (-48.94%)
Mutual labels:  adapter
Protobuf Adapter
Google Protocol Buffers adapter for Casbin
Stars: ✭ 185 (+293.62%)
Mutual labels:  adapter
Multiselectadapter
MultiSelectAdapter可以让你的Adapter快速实现多选和批量操作
Stars: ✭ 195 (+314.89%)
Mutual labels:  adapter
Base
🍁 Base是针对于Android开发封装好一些常用的基类,主要包括通用的Adapter、Activity、Fragment、Dialog等、和一些常用的Util类,只为更简单。
Stars: ✭ 249 (+429.79%)
Mutual labels:  adapter
Go Clickhouse
Golang ClickHouse connector
Stars: ✭ 174 (+270.21%)
Mutual labels:  adapter
ember-airtable
Boilerplate for quickly prototyping apps with Airtable, Node & Ember
Stars: ✭ 21 (-55.32%)
Mutual labels:  adapter
Commonadapter
一个适用于ListView/GridView/RecyclerView的Adapter库,简化大量重复代码,支持多种布局,可自定义图片加载的实现。
Stars: ✭ 219 (+365.96%)
Mutual labels:  adapter
entity-state
⏱ WIP: Entity adapter
Stars: ✭ 51 (+8.51%)
Mutual labels:  ngxs
Sherlockadapter
一个万能的封装了RecyclerView.Adapter的功能库。
Stars: ✭ 186 (+295.74%)
Mutual labels:  adapter
Mongodb Adapter
MongoDB adapter for Casbin
Stars: ✭ 194 (+312.77%)
Mutual labels:  adapter
react-immer-hooks
Easy immutability in React Hooks with Immer.
Stars: ✭ 45 (-4.26%)
Mutual labels:  immer
Kau
An extensive collection of Kotlin Android Utils
Stars: ✭ 182 (+287.23%)
Mutual labels:  adapter
oh-my-design-patterns
🎨 Record the articles and code I wrote while learning design patterns
Stars: ✭ 33 (-29.79%)
Mutual labels:  adapter
Pydesignpattern
Design Pattern that described by Python, This is the source code for the book of Everybody Know Design Patterns.
Stars: ✭ 174 (+270.21%)
Mutual labels:  adapter
Dsladapter
🔥 Kotlin时代的Adapter, Dsl 的形式使用 RecyclerView.Adapter, 支持折叠展开, 树结构,悬停,情感图状态切换, 加载更多, 多类型Item,侧滑菜单等
Stars: ✭ 231 (+391.49%)
Mutual labels:  adapter
ngrx-etc
Utility functions for NgRx
Stars: ✭ 70 (+48.94%)
Mutual labels:  immer
readable-web-to-node-stream
Converts a Web-API readable-stream into a Node readable-stream.
Stars: ✭ 33 (-29.79%)
Mutual labels:  adapter
InstantRecyclerView
A library that helps to implement a complex list with RecyclerView.(RecyclerView使用的封装与优化,帮助你快速利用RecyclerView构建复杂列表)
Stars: ✭ 22 (-53.19%)
Mutual labels:  adapter


Declarative state mutations

Build Status NPM License Codacy Badge

📦 Install

To install @ngxs-labs/immer-adapter and immer that is a peer-dependency run the following command:

npm install @ngxs-labs/immer-adapter immer
# or if you use yarn
yarn add @ngxs-labs/immer-adapter immer
Before

When your state is growing - it becomes harder to manage such mutations:

import { State, Action, StateContext } from '@ngxs/store';

export class FeedZebra {
  public static readonly type = '[Animals] Feed zebra';
  constructor(public payload: string) {}
}

@State<AnimalsStateModel>({
  name: 'animals',
  defaults: {
    zebra: {
      food: ['leaves', 'bark'],
      name: 'zebra'
    },
    panda: {
      food: [],
      name: 'panda'
    }
  }
})
export class AnimalState {
  @Selector()
  public static zebraFood(state: AnimalsStateModel): string[] {
    const zebraFood = [...state.zebra.food];
    zebraFood.reverse();
  }

  @Action(Add)
  public add({ getState, setState }: StateContext<AnimalsStateModel>, { payload }: Add): void {
    setState((state: AnimalsStateModel) => ({
      ...state,
      zebra: {
        ...state.zebra,
        food: [ ...state.zebra.food, payload ]
      }
    }));
  }
}
After

immer-adapter gives you the opportunity to manage mutations in a more declarative way:

import { ImmutableContext, ImmutableSelector } from '@ngxs-labs/immer-adapter';

@State<AnimalsStateModel>({
  name: 'animals',
  defaults: {
    zebra: {
      food: [],
      name: 'zebra'
    },
    panda: {
      food: [],
      name: 'panda'
    }
  }
})
export class AnimalState {
  @Selector()
  @ImmutableSelector()
  public static zebraFood(state: AnimalsStateModel): string[] {
    return state.zebra.food.reverse();
  }

  @Action(Add)
  @ImmutableContext()
  public add({ setState }: StateContext<AnimalsStateModel>, { payload }: Add): void {
    setState((state: AnimalsStateModel) => ({
      state.zebra.food.push(payload);
      return state;
    }));
  }
}
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].