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

fusion-plugin-react-redux-mod

v0.0.8

Published

Integrates React and Redux to a Fusion.js application

Downloads

5

Readme

fusion-plugin-react-redux

Build status

Integrates React and Redux to a Fusion.js application

It handles creating your store, wrapping your element tree in a provider, and serializing/deserializing your store between server and client.

Note that this plugin extends the Redux state with a property called ctx that references the request's context


Table of contents


Installation

yarn add fusion-plugin-react-redux

Usage

// you can just use standard Redux reducers
export default (state, action) => ({
  count: countReducer(state.count, action),
  things: thingsReducer(state.things, action),
});

function countReducer(state, action) {
  switch (action.type) {
    case 'INCREMENT':
      return state + 1;
    case 'DECREMENT':
      return state - 1;
    default:
      return state;
  }
}

function thingsReducer(state, action) {
  switch (action.type) {
    case 'ADD_THING':
      return [...state, action.payload];
    default:
      return state;
  }
}

Setup

// in your main.js file
import React from 'react';
import Redux, {
  ReduxToken,
  ReducerToken,
  EnhancerToken,
  GetInitialStateToken,
} from 'fusion-plugin-react-redux';
import ReduxActionEmitterEnhancer from 'fusion-plugin-redux-action-emitter-enhancer';
import App from 'fusion-react';
import reducer from './reducer';

export default function start() {
  const app = new App(root);
  app.register(ReduxToken, Redux);
  app.register(ReducerToken, reducer);
  app.register(EnhancerToken, enhancer);
  __NODE__ && app.register(GetInitialStateToken, async ctx => ({}));

  return app;
}

API

Registration API

Redux
import Redux from 'fusion-plugin-react-redux';

The Redux plugin. Provides the service API and installs a redux provider at the top of the React tree. Typically it's registered to ReduxToken

ReduxToken
import {ReduxToken} from 'fusion-plugin-react-redux';

Typically, it's registered with Redux

Dependencies

ReducerToken
import {ReducerToken} from 'fusion-plugin-react-redux';

The root reducer. Required.

Types
type Reducer = (state: any, action: Object) => any
EnhancerToken
import {EnhancerToken} from 'fusion-plugin-react-redux';

Redux enhancer. Optional.

Types
type Enhancer = (next: StoreCreator) => StoreCreator
type StoreCreator = (reducer: Reducer, preloadedState: State) => Store
GetInitialStateToken
import {GetInitialStateToken} from 'fusion-plugin-react-redux';

A function that gets initial state asynchronously without triggering actions. Optional. Useful for testing. When architecting application state, prefer using standard reducers to specify initial state.

Types
type InitialState = (ctx: Context) => Promise<State> | State

Service API

const service: ReduxServiceInstance = Redux.from((ctx: Context));
Types
type ReduxServiceInstance = {
  ctx: Context,
  store: Store,
  initStore: () => Promise<Store>
}
store.ctx

For convenience, Redux stores are composed with a default right-most enhancer to add store.ctx along side with other Store APIs. This is particular useful for your custom store enhancers to access to ctx for use-cases such as logging, analytics, etc.

See fusion-plugin-redux-action-emitter-enhancer for a usage example.


Redux devtools integration

The plugin automatically integrates with the redux devtools Chrome extension