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

redux-crud-observable

v1.1.1

Published

Actions, reducers & epics for managing crud redux state

Downloads

23

Readme

redux-crud-observable

Build Status codecov

Ever been tired of manipulating CRUD entities in a redux app? You always have to do the same things again and again: fetching an entity, doing the corresponding ajax call, waiting for the promise resolution, storing the value in a reducer... Boring.

redux-crud-observable is doing all of that for you. You only have to setup your entity name and your api configuration. It will handle the rest for you, ie:

  • generating the corresponding actions creators
  • generating the corresponding reducer
  • generating the corresponding selectors
  • handling all ajax calls

It also comes with a very handy feature: request cancellation. It means that you can cancel at any time a request that is already flying ✈️.

Getting Started

Simply run:

npm install --save redux-crud-observable

It also has peer dependencies: redux, redux-observable, rxjs and reselect.

Doc

You could browse the project documentation here.

Usage

You could check an exemple in this functionnal test.

Configuration

To use this library, you will have to add the createEpicMiddleware from redux-observable to your store enhancers. Here is a bery basic setup.

import { createStore, applyMiddleware } from 'redux';
import { createEpicMiddleware } from 'redux-observable';
import { epicFactory, crudReducerFactory } from 'redux-crud-observable';

const ENTITY = 'JEDI';
const crudReducer = crudReducerFactory(ENTITY);
const rootReducer = combineReducers({
  crud: crudReducer,
});
const rootEpic = reduxCrudObservable.crudEpicFactory({
  apiConfig: {
    apiProto: 'https',
    baseUrl: 'api.starwars.galaxy',
    json: false,
    route: '/jedis',
    token: 'Bearer 1234',
    version: '/v1',
  },
  entity: ENTITY,
});

const store = createStore(rootReducer, applyMiddleware(createEpicMiddleware(rootEpic)));

Actions Creators

You can generate and use crud actions creators like that:


import { crudActionsCreatorFactory } from 'redux-crud-observable';

const {
  requestReadEntity,
  cancelReadEntity,
} = reduxCrudObservable.crudActionsCreatorFactory('JEDI');

console.log(requestReadEntity({
  id: 5
})); // { type: 'REQUEST_READ_JEDI', payload: 5 }

The full list of actions creators is available here.

Reducer

You can create the crud reducer and use it like that:


import { combineReducers } from 'redux';
import { crudReducerFactory } from 'redux-crud-observable';

const crudReducer = crudReducerFactory('JEDI');

export default combineReducers({
  crud: crudReducer,
});

Epic

You can create the root crud epic like that:

import { crudEpicFactory } from 'redux-crud-observable';

const rootEpic = crudEpicFactory({
  apiConfig: {
    apiProto: 'https',
    baseUrl: 'api.starwars.galaxy',
    json: false,
    route: '/jedis',
    token: 'Bearer 1234',
    version: '/v1',
  },
  entity: 'JEDI',
});

Selectors

You can create some reselect selectors like that:


import { crudSelectorFactory } from 'redux-crud-observable';

const { entitiesValueSelector } = crudSelectorFactory(['crud']);

console.log(entitiesValueSelector(state)); => // Immutable.Map({ 1234: { hash: 1234, name: 'Yoda' } });

Here is the list of available selectors.

Roadmap