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-fluorine

v1.1.0

Published

A Redux enhancer to manage groups of actions as observables (agendas)

Downloads

7

Readme

Redux Fluorine is an enhancer to transform Observables truly into a first-class citizen in Redux. It enables you to directly dispatch observables containing actions, which is called an "agenda".

It gracefully handles errors! If an agenda completes with an error, it automatically reverts all its changes, without affecting the rest of your actions.

It's the perfect companion! It nicely complements side effect middleware like redux-saga or of course redux-observable.

Better composition! Since you can directly dispatch observables, it's easy to compose different agendas to create complex behaviour. This even allows you to track them without creating "signal actions".

Usage

To install the npm package run:

npm install --save redux-fluorine

It is very simple to integrate Redux Fluorine into your existing Redux projects. Keep in mind that because it wraps the store's state, you should apply it before the middleware-enhancer. It should be added to the compose function after the applyMiddleware:

import { createStore, compose, applyMiddleware } from 'redux';
import { createAgendaEnhancer } from 'redux-fluorine';

const enhancer = compose(
  applyMiddleware(...middleware),
  createAgendaEnhancer()
)

// You need Redux >3.1 to pass the enhancer to createStore directly
const store = createStore(reducer, initialState, enhancer);

Once you have installed it in your Redux project, you will be able to dispatch observables directly. Any emissions from these observables are dispatched as actions. This observable is referred to as an agenda. When an agenda errors, all its actions are reverted.

Documentation

Short Demo

import { Observable } from 'rxjs';
import { createStore } from 'redux';
import { createAgendaEnhancer } from 'redux-fluorine';

// Let's use a simple counter reducer as our example store
function counter(state = 0, action) {
  switch (action.type) {
  case 'INCREMENT':
    return state + 1
  case 'DECREMENT':
    return state - 1
  default:
    return state
  }
}

const store = createStore(reducer, createAgendaEnhancer())

store.getState() // 0

store.dispatch({ type: 'INCREMENT' })
store.getState() // 1

// Here we dispatch our action wrapped by an RxJS Observable
store.dispatch(Observable.of({ type: 'DECREMENT' }))
store.getState() // 0

// This observable dispatches INCREMENT, but is reverted after it throws its error
store.dispatch(
  Observable.of({ type: INCREMENT })
  .concat(Observable.throw('An Error')) // This observable throws an error
)

// The above agenda will have dispatched the INCREMENT action, but will emit
// a new state that reverted this action, after the error.

store.getState() // 0

When you dispatch an observable, the actions are all dispatched, but if the observable completes with an error, Fluorine will step through your past state and "filter out" all actions that this errored observable emitted.

By being able to dispatch observables, you will not need as many signal actions anymore. You can keep track of the observable's state in your container components. Or you can compose some actions really quickly. While it is not as elegant for side effects as redux-observable for example, it certainly is great for dispatching explicit actions.

Help & Discussion

You are welcome to ask questions, discuss your ideas and use cases, or troubleshoot potential bugs on the Fluorine Slack!