All Projects → HarmoWatch → ngx-redux-core

HarmoWatch / ngx-redux-core

Licence: MIT license
The modern redux integration for Angular 6+

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language
HTML
75241 projects
CSS
56736 projects

Projects that are alternatives of or similar to ngx-redux-core

Aspnetcore Angular Universal
ASP.NET Core & Angular Universal advanced starter - PWA w/ server-side rendering for SEO, Bootstrap, i18n internationalization, TypeScript, unit testing, WebAPI REST setup, SignalR, Swagger docs, and more! By @TrilonIO
Stars: ✭ 1,455 (+4446.88%)
Mutual labels:  angular2, angular4, angular5
Ng Select
⭐ Native angular select component
Stars: ✭ 2,781 (+8590.63%)
Mutual labels:  angular2, angular4, angular5
Ng Simple Slideshow
A simple, responsive slideshow for Angular 4+.
Stars: ✭ 119 (+271.88%)
Mutual labels:  angular2, angular4, angular5
Angular File Uploader
Angular file uploader is an Angular 2/4/5/6/7/8/9/10 + file uploader module with Real-Time Progress Bar, Responsive design, Angular Universal Compatibility, localization and multiple themes which includes Drag and Drop and much more.
Stars: ✭ 92 (+187.5%)
Mutual labels:  angular2, angular4, angular5
Ng2 Pdfjs Viewer
An angular 8 component for PDFJS and ViewerJS (Supports angular 2/4/5/6/7)
Stars: ✭ 150 (+368.75%)
Mutual labels:  angular2, angular4, angular5
Angular Admin Lte
AdminLte for Angular 2
Stars: ✭ 109 (+240.63%)
Mutual labels:  angular2, angular4, angular5
Ng Drag Drop
Drag & Drop for Angular - based on HTML5 with no external dependencies. 🎉
Stars: ✭ 233 (+628.13%)
Mutual labels:  angular2, angular4, angular5
Angular2
Angular 2 Seed
Stars: ✭ 75 (+134.38%)
Mutual labels:  angular2, angular4, angular5
Angular5 Iot Dashboard
Multipurpose dashboard admin for IoT softwares, remote control, user interface. Develop your client dashboards in Angular 5 with vast variety of components available.
Stars: ✭ 148 (+362.5%)
Mutual labels:  angular2, angular4, angular5
Amazing Time Picker
Timepicker (Clock Picker) for Angular 2, Angular 4 and Angular 5, Angular 6, Angular 7 - Compatible with Angular Material
Stars: ✭ 142 (+343.75%)
Mutual labels:  angular2, angular4, angular5
Ng2 Flatpickr
Angular 2+ wrapper for flatpickr (https://github.com/chmln/flatpickr)
Stars: ✭ 91 (+184.38%)
Mutual labels:  angular2, angular4, angular5
Ngx Daterangepicker Material
Pure Angular 2+ date range picker with material design theme, a demo here:
Stars: ✭ 169 (+428.13%)
Mutual labels:  angular2, angular4, angular5
Springbootangularhtml5
♨️ Spring Boot 2 + Angular 11 + HTML5 router mode + HTTP interceptor + Lazy loaded modules
Stars: ✭ 89 (+178.13%)
Mutual labels:  angular2, angular4, angular5
Angular5 Seed
Angular5 Seed for Application
Stars: ✭ 222 (+593.75%)
Mutual labels:  angular2, angular4, angular5
Ngx Papaparse
Papa Parse wrapper for Angular
Stars: ✭ 83 (+159.38%)
Mutual labels:  angular2, angular4, angular5
Fusebox Angular Universal Starter
Angular Universal seed project featuring Server-Side Rendering, @fuse-box bundling, material, firebase, Jest, Nightmare, and more
Stars: ✭ 132 (+312.5%)
Mutual labels:  angular2, angular4, angular5
Angular Tree Component
A simple yet powerful tree component for Angular (>=2)
Stars: ✭ 1,031 (+3121.88%)
Mutual labels:  angular2, angular4, angular5
Drip Ionic3
「水滴打卡」App Open Source Code Base On Ionic V3 Framework
Stars: ✭ 74 (+131.25%)
Mutual labels:  angular2, angular4, angular5
Ng2 Search Filter
Angular 2 / Angular 4 / Angular 5 custom pipe npm module to make a search filter on any input, 🔥 100K+ downloads
Stars: ✭ 137 (+328.13%)
Mutual labels:  angular2, angular4, angular5
Angular Google Maps
Angular 2+ Google Maps Components
Stars: ✭ 1,982 (+6093.75%)
Mutual labels:  angular2, angular4, angular5

@harmowatch/ngx-redux-core

Join the chat at https://gitter.im/harmowatch/ngx-redux-core

npm version Renovate enabled Build Status HitCount Maintainability Test Coverage

The modern Redux integration for Angular 6+

This package contains a number of features that makes working with Angular and Redux very easy and comfortable. This is achieved using decorators. For example, you can decorate any class method with @ReduxAction. Every time the method is called it will dispatch a redux action.

Main Features

TypeScript support

One big advantage of this package is the TypeScript support for reducer functions. By using this package, you'll get a compiler error, if the payload of the redux action is not compatible with the reducer.

TypeScript support


Reduced boilerplate

The decorators will save you a lot of boilerplate code, so for example you don't have to call an extra service to dispatch the redux action anymore. Also the annoying switch-cases on the action-types are replaced by the @ReduxReducer decorator:

No switch case


Refactoring support

Refactoring is improved as well, since you refer directly to the action method and not to a string. Therefore, your IDE can also modify your reducer, when the action method was renamed.


Easy to test

Matchers

There are some jasmine matchers provided by this package. This makes it easy to test whether a method triggers a redux action and if the reducer really listens to it. There is also a matcher available which will ensure that the reducer does not work on the state reference. For more information about testing and matcher installation, please see the Testing Guide.

toDispatchAction
it('will dispatch a redux action', () => {
  expect(TodoListComponent.prototype.toggleListMode).toDispatchAction();
  // or test for a specific action name
  expect(TodoListComponent.prototype.toggleListMode).toDispatchAction('toggleListMode');
});
toReduceOn
it('listens to the correct actions', () => {
  expect(TodoReducer.prototype.add).toReduceOn(TodoListComponent.prototype.add);
});
notToMutateTheGivenState
it('does not mutate the given state', () => {
  expect(TodoReducer.prototype.add).notToMutateTheGivenState(state);
});

The Select Pattern

The Select Pattern gives you a powerful tool-set at your hand, to select slices of your state. The easiest way to access a state value is the reduxSelect pipe:

<pre>{{ 'some/state/path' | reduxSelect | async | json }}</pre>

Lazy Loaded Modules

Lazy Loaded Modules are also supported. So you can only initialize the reducer and the state when the respective NgModule is loaded.


Redux DevTools Extension support

The Redux DevTools Extension is fully supported and automatically enabled if your Angular app is running in dev mode.


What is Redux?

Redux is a popular and common approach to manage an application state. The three principles of redux are:


Installation

The redux package itself is not shipped with @harmowatch/ngx-redux-core. Therefore you also have to install the redux package:

$ npm install redux @harmowatch/ngx-redux-core --save

Quickstart

1. Import the root ReduxModule:

As the first step, you need to add ReduxModule.forRoot() to the root NgModule of your application.

The static forRoot method is a convention that provides and configures services at the same time. Make sure you call this method only in your root NgModule!

Please note that Lazy loading is also supported.

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ReduxModule } from '@harmowatch/ngx-redux-core';

import {YourModuleStateProvider} from '...';
import {TodoListReducer} from '...';

@NgModule({
  imports: [
    BrowserModule,
    ReduxModule.forRoot({
      state: {
        provider: YourModuleStateProvider, // You'll create it in step 2
        reducers: [ TodoListReducer ], // You'll create it in step 4
      }
    }),
  ],
  providers: [
    YourModuleStateProvider // You'll create it in step 2
  ],
})
export class AppModule {}

2. Create a state provider

Now you have to create a provider for your module in order to describe and initialize the state.

import { Injectable } from '@angular/core';
import { ReduxState, ReduxStateProvider } from '@harmowatch/ngx-redux-core';

export interface YourModuleState {
  items: string[];
}

@Injectable()
@ReduxState({name: 'your-module'}) // Make sure you choose a application-wide unique name
export class YourModuleStateProvider extends ReduxStateProvider<YourModuleState> {

  getInitialState(): Promise<YourModuleState> { // You can return Observable<YourModuleState> or YourModuleState as well
    return Promise.resolve({
      items: []
    });
  }}

}

Don't forget to add the state as described in step 1

You can have just one ReduxStateProvider per NgModule. But it's possible to have a state provider for each lazy loaded module.

3. Create an action dispatcher

To initiate a state change, a redux action must be dispatched. Let's assume that there is a component called TodoListComponent that displays a button. Each time the button is clicked, the view calls the function addTodo and passes the todo, which shall be added to the list.

All you have to do is decorate the function with @ReduxAction and return the todo as a return value.

import { Component } from '@angular/core';
import { ReduxAction } from '@harmowatch/ngx-redux-core';

@Component({templateUrl: './todo-list.component.html'})
export class TodoListComponent {

  @ReduxAction()
  addTodo(label: string): string {
    return label; // your return value is the payload
  }

}

Now the following action is dispatched, every time the addTodo method was called:

{
  "type": "addTodo",
  "payload": "SampleTodo"
}

You can also create a provider to dispatch actions.

4. Create the reducer

There's one more thing you need to do. You dispatch an action, but at the moment no reducer is listening to it. In order to change this, we need to create a reducer function that can make the state change as soon as the action is fired:

import { ReduxReducer, ReduxActionWithPayload } from '@harmowatch/ngx-redux-core';

import {TodoListComponent} from '...';

export class TodoListReducer {

  @ReduxReducer(TodoListComponent.prototype.add)
  addTodo(state: TodoState, action: ReduxActionWithPayload<string>): TodoState {
    return {
      ...state,
      items: state.items.concat(action.payload),
    };
  }

}

Don't forget to add the state as described in step 1

5. Select values from the state

To select a state value, you just can use the reduxSelect pipe. But you've several options to select a state value. Please check out the Select Pattern article for more information.

<ul>
  <li *ngFor="let todo of ('items' | reduxSelect | async)">{{todo}}</li>
</ul>

Documentation

You'll find the latest docs here.


You like the project? Then please give me a Star and add you to the list of Stargazers.

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