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

v0.1.2

Published

Redux via stuff

Downloads

15

Readme

redux-via

redux-via provides a basis for using Redux across boundaries with Flux Standard Actions.

By the way, via is Latin for "road", which brings us to a very important question: Why did the Redux FSA-compliant action cross the road? To get reduced at the other side. Duh!

...

OK, let's pretend that supposed joke never happened and get to the point.

Usage

First, install an adapter:

Client and server side configuration look very similar. Specifics will depend on the adapter API. We'll use the names outViaAdapter and inViaAdapter just for the example.

import {inClientViaAdapter as inViaAdapter} from 'redux-via-adapter';
import {outClientViaAdapter as outViaAdapter} from 'redux-via-adapter';

...at the client side, or...

import {inServerViaAdapter as inViaAdapter} from 'redux-via-adapter';
import {outServerViaAdapter as outViaAdapter} from 'redux-via-adapter';

...at the server side. Then...

// ...
const transport = ...; // object dealing with communication

const finalCreateStore = compose(
  applyMiddleware(
    outViaAdapter(transport), // initialize for outcoming actions
    anotherMiddleware,
    yetAnotherMiddleware,
  )
)(createStore);

const store = finalCreateStore(rootReducer, initialState);

// initialize for incoming actions
inViaAdapter(transport, store.dispatch);

Meta options

Action flow is controlled by options specified in the meta property.

Client side

broadcast (Boolean)

If true, sends the action to all the other clients. Default value: false

server (Boolean)

If true, sends the action to the server. Default value: false

next (Boolean)

If true, the action continues to the next middleware or the reducer, locally in the server. Default value: true

Server side

broadcast (Boolean)

If true, sends the action to all the clients except the specified in client. Default value: false

client (String)

If broadcast is false, sends the action the specified client. If broadcast is true, sends the action to all clients except the specified client. Default value: undefined

next (Boolean)

If true, the action continues to the next middleware or the reducer in the client(s). Default value: true

Meta object keys conflicts

If redux-via meta keys conflict with other meta keys, use the meta.noConflict function. For example:

// before
const action = {
  type: 'ACTION',
  meta: {server: true} // say this is causing an error in another library
};
// after
import {meta} from 'redux-via';
const action = {
  type: 'ACTION',
  meta: {
    server: 'a-server-name-for-who-knows-what',
    ...meta.noConflict({server: true})  // PEACE!
  }
};

Implementing an adapter

// Doc in progress... In the meantime, redux-via-socket.io can provide an example of how to do it.

npm install --save redux-via

inClientVia(dispatch: Function, action: Object)

Handles incoming actions at client side. Arguments:

  • dispatch: The dispatch function from store.
  • action: The action object.

outClientVia(cross: Function): Function

Builds a middleware that handles outcoming actions at client side. Arguments:

  • cross: The function to cross the action out of the client boundary.
  • Returns a Redux middleware

inServerVia(dispatch: Function, action: Object, client: String)

Handles incoming actions at server side. Arguments:

  • dispatch: The dispatch function from store.
  • action: The action object.
  • client: The client identifier.

outServerVia(cross: Function): Function

Builds a middleware that handles outcoming actions at server side. Arguments:

  • cross: The function to cross the action out of the server boundary.
  • Returns a Redux middleware

Thanks to:


License

MIT