All Projects → ptol → ts-reducer-creator

ptol / ts-reducer-creator

Licence: MIT license
TypeScript strongly typed boilerplate-free reducer creator for Redux and ngrx

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to ts-reducer-creator

angular-plugins
Reactive Angular Plugins
Stars: ✭ 36 (-12.2%)
Mutual labels:  ngrx
angular-admin-panel
An Angular Admin boilerplate to quickly scaffold any large scale enterprise application.
Stars: ✭ 18 (-56.1%)
Mutual labels:  ngrx
meditation-plus-angular
DEVELOPMENT MOVED TO
Stars: ✭ 15 (-63.41%)
Mutual labels:  ngrx
ngrx-films-list
Ngrx example app
Stars: ✭ 15 (-63.41%)
Mutual labels:  ngrx
streamkit
My streaming overlay platform for YouTube https://bit.ly/3AvaoFz and Twitch https://bit.ly/37xUPAM
Stars: ✭ 15 (-63.41%)
Mutual labels:  ngrx
spring-kotlin-angular4
Another abadoned Spring Boot application with Angular and Kotlinabandoned
Stars: ✭ 22 (-46.34%)
Mutual labels:  ngrx
devto-clone
This is a dev to clone in angular. Where we used Angular component-store, rx-angular/template
Stars: ✭ 36 (-12.2%)
Mutual labels:  ngrx
tracks
Angular2 progressive web app for tracking things
Stars: ✭ 23 (-43.9%)
Mutual labels:  ngrx
mean-ionic-ngrx
Monorepo as Microservices: Full MEAN stack with Angular 7, Ionic 4 and ReactiveX API (ngrx/Store + ngrx/Effects) + i18n/ngx-translate + Express NodeJS REST API servers micro-services + JWT Authentication + UnitTest/e2e exemple + Travis + DevOps scripts and many more...
Stars: ✭ 60 (+46.34%)
Mutual labels:  ngrx
ngrx-slice
Moved to https://github.com/nartc/nartc-workspace
Stars: ✭ 50 (+21.95%)
Mutual labels:  ngrx
undox
⎌ Redux Implementation of Undo/Redo based on storing actions instead of states.
Stars: ✭ 25 (-39.02%)
Mutual labels:  ngrx
ionic4-boilerplate
🚀 boilerplate for ionic4 with CI based on travis and fastlane. doc and example are provided
Stars: ✭ 25 (-39.02%)
Mutual labels:  ngrx
angular-cli-skeleton
angular-cli skeleton to quickly start a new project with advanced features and best practices. All features are described in README.md.
Stars: ✭ 32 (-21.95%)
Mutual labels:  ngrx
ionic3-firebase-ngrx
Sample Ionic 3 application using ngrx with firebase (auth, crud and camera plugin)
Stars: ✭ 48 (+17.07%)
Mutual labels:  ngrx
ionic2.0-angularfire
this a basic application for Ionic 2.0.rc5 with AngularFire2 with ngrx/store & ngrx/effects to manage state
Stars: ✭ 71 (+73.17%)
Mutual labels:  ngrx
ngrx-store-ionic-storage
Simple syncing between @ngrx/store and Ionic Storage.
Stars: ✭ 66 (+60.98%)
Mutual labels:  ngrx
angular2-webpack-advance-starter
An advanced Angular2 Webpack Starter project with support for ngrx/store, ngrx/effects, ng2-translate, angulartics2, lodash, NativeScript (*native* mobile), Electron (Mac, Windows and Linux desktop) and more.
Stars: ✭ 49 (+19.51%)
Mutual labels:  ngrx
flux-action-class
Boilerplate free class-based action creator. Following flux-standard-action spec. Built with TypeScript. Works with redux and ngrx.
Stars: ✭ 22 (-46.34%)
Mutual labels:  ngrx
ngrx-form
Reactive Forms bindings for NGRX and Angular
Stars: ✭ 46 (+12.2%)
Mutual labels:  ngrx
todo-app-ngrx
TodoMV* - Angular + Redux (ngrx)
Stars: ✭ 42 (+2.44%)
Mutual labels:  ngrx

Install

npm install ts-reducer-creator

How to use

First you need to define your actions and their payload types

interface CounterActions {
    setValue: number; \\"setValue" is an action and number is a payload type 
    increment: void;    
}

and State

export interface State {
    value: number;
}

export const initialState: State = {
    value: 0
}

Then you can call createHelpers

import {createHelpers} from 'ts-reducer-creator';

export const {reducer, actionCreators, ofTypeFilters, actionTypes} =
  createHelpers<State, CounterActions>('Counter', initialState, {
    increment: (state) => {
        return {...state, value: state.value + 1}; // state has type State
    },
    setValue: (state, payload) => {
        return {...state, value: payload};   // payload has type number
    },
});

to create

  • reducer - your reducer function
  • actionCreators - action creators actionCreators.setValue(10)
  • ofTypeFilters - action filters for Obserable<Action>. It can be used with redux-observable or ngrx effects actions$.pipe(ofTypeFilters.increment)
  • actionTypes - action types actionTypes.increment

Boilerplate vs ts-reducer-creator

Boilerplate

export enum CounterActionTypes {
  INCREMENT = '[Counter] Increment',
  SET_VALUE = '[Counter] SetValue'
}

export class Increment implements Action {
    readonly type = CounterActionTypes.INCREMENT;
}

export class SetValue implements Action {
    readonly type = CounterActionTypes.SET_VALUE;
    constructor(public payload: number) {}
}

export type CounterActionsUnion = Increment | SetValue;

export function reducer(state = initialState, action: CounterActionsUnion): State {
  switch (action.type) {
    case CounterActionTypes.INCREMENT: {
      return {...state, value: state.value + 1};
    }

    case CounterActionTypes.SET_VALUE: {
      return {value: action.payload};
    }

    default: {
      return state;
    }
  }
}

const actionCreators = {
  increment: () => new Increment(),
  setValue: (payload: number) => new SetValue(payload),
}

ts-reducer-creator

interface CounterActions {
    increment: void;
    setValue: number;
}

export const {reducer, actionCreators} = createHelpers<State, CounterActions>('Counter', initialState, {
    increment: (state) => {
        return {...state, value: state.value + 1}; 
    },
    setValue: (state, payload) => {
        return {...state, value: payload};  
    }
});

Examples

https://github.com/ptol/ts-reducer-creator/tree/master/examples

Angular with ngrx

https://github.com/ptol/ts-reducer-creator/blob/master/examples/angular/src/app/newStore.ts

React with redux and redux-observable

https://github.com/ptol/ts-reducer-creator/blob/master/examples/react/src/newStore.ts

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].