npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

angular-redux-util

v3.0.4

Published

Angular Redux Util is a helper library for using Angular 6+ applications with Redux (via NgRedux) and Redux Observable.

Downloads

24

Readme

angular-redux-util

npm npm CircleCI

Angular Redux Util is a helper library for using Angular 6+ applications with Redux (meant for use with @angular-redux) and Redux Observable. It contains a simplified Epic setup and built in generic Get and Post epics.

Table of Contents

Peer Dependencies

|Module|Version| |---|---| |@angular/common|^6.0.0| |@angular/core|^6.0.0| |redux|^4.0.0| |redux-observable|^1.0.0| |redux-observable-util|^0.1.0| |rxjs|^6.0.0|

Meant for use with @angular-redux ^9.0.0.

Defining Redux Observable Epics

Angular Redux Util simplifies the setup for defining an epic, cleaning up the code for readability.

Before

somethingEpic = (action$, state$) =>
  action$.pipe(
    ofType(SOMETHING),
    switchMap(() =>
      this.httpClient.get<any>('/something').toPromise()
        .then(response => of({ type: SUCCESS, response }))
        .catch(error => of({ type: ERROR, response }));
    )
  );

After

@Epic(SOMETHING)
somethingEpic(action: AnyAction, state$) {
  this.httpClient.get<any>('/something').toPromise()
    .then(response => { type: SUCCESS, response })
    .catch(error => { type: ERROR, response });
}

Configuring Epics in Store

Configuration of the epics is also simplified compared to the standard setup of Redux Observable. You call the generateEpics instead of combineEpics, and pass the services that contain @Epic decorators.

Before

const epicMiddleware = createEpicMiddleware();
this.ngRedux.configureStore(rootReducer, APP_INITIAL_STATE, epicMiddleware);
epicMiddleware.run(combineEpics(service.epic1, service.epic2));

After

const epicMiddleware = createEpicMiddleware();
this.ngRedux.configureStore(rootReducer, APP_INITIAL_STATE, epicMiddleware);
epicMiddleware.run(generateEpics(service));

Redux Http Module

The Redux Http Module provide Get and Post epics ready out of the box. They take a specific payload, handle all of the http interactions, and return the results. You must provide a URL, success action (and body for POST). The error action and headers are optional. If no error action is provided, it will automatically use GENERIC_ERROR.

Getting Started

To get started, we need to setup the Get and Post epics into the store:

const epicMiddleware = createEpicMiddleware();

// Configure @angular-redux
this.ngRedux.configureStore(
  rootReducer,
  APP_INITIAL_STATE,
  [
    ...middleware,
    epicMiddleware
  ],
  [ ...enhancers, devTool.isEnabled() ? devTool.enhancer() : f => f]);

epicMiddleware.run(
  generateEpics(reduxHttpService)
);

Actions

Base Http Action

export class ReduxHttpAction {
  url: string;
  successAction: string;
  errorAction?: string;
  payload?: any;

  options?: ReduxHttpOptions;
}

Options

export class ReduxHttpOptions {
  headers?: HttpHeaders | {[header: string]: string | string[]};
  reportProgress?: boolean;
  responseType?: 'json';
  withCredentials?: boolean;
}

Http Action With Body

export class ReduxHttpBodyAction extends ReduxHttpAction {
  body: any|null;
}

Get Action

  • Type: REDUX_GET
  • Action Format: ReduxHttpAction

Example

getData(): void {
  const action: ReduxGetAction = {
    type: REDUX_GET
    url: 'assets/data.json',
    successAction: ExampleReduxActions.GET_DATA_SUCCESS
  };

  this.ngRedux.dispatch(action);
}

Post Action

  • Type: REDUX_POST
  • Action Format: ReduxHttpBodyAction

Patch Action

  • Type: REDUX_PATCH
  • Action Format: ReduxHttpBodyAction

Put Action

  • Type: REDUX_PUT
  • Action Format: ReduxHttpBodyAction

Delete Action

  • Type: REDUX_DELETE
  • Action Format: ReduxHttpAction