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

v0.2.0

Published

A helpful decorator to run Redux actions in universal apps.

Downloads

1

Readme

redux-preheat

A helpful decorator to run Redux actions in universal React apps with support for Promises.

Why?

In a universal app you will want the store's state from the sever to match on the client side. You can solve this by adding a static method to a component, or adding a property to the route definition. redux-preheat hopes to solve this with a decorator, a promise, and your existing Redux actions.

How?

preheat(clientAction, serverAction = null)(Component)

The decorator for your components. If no serverAction is given then clientAction will run on both sides.

Note: You will want to group @preheat decorators and place them as close to the component as possible (aka after any @connect or other decorators).

import { preheat } from 'redux-preheat'
import * as actions from './actions'

// `actions.fetchData` will be called on either the client or server.
@preheat(actions.fetchData)
// `actions.fetchDataClient` will be called on the client.
// `actions.fetchDataServer` will be called on the server.
@preheat(actions.fetchDataClient, actions.fetchDataServer)
class MyComponent extends React.Component {
  render () {
    // ...
  }
}

getPreheatPromise(store, components = [], actionArg = null)

The promise used on the server. This example uses react-router.

import { getPreheatPromise } from 'redux-preheat'

app.get('/*', function (req, res) {
  match({ routes, location: req.url }, function (error, redirectLocation, renderProps) {
    if (renderProps) {
      // We have to pass the store to `getPreheatPromise`.
      let store = createStore({})

      // Get the list of components for the current route.
      let components = renderProps.components

      // On the client the action will be passed the component instance as an
      // argument, on the server we decide what to pass.
      // You will want this to be something the action can use to get request
      // params or some insight to the request.
      let actionArg = renderProps

      getPreheatPromise(store, components, actionArg).then(function () {
        const content = renderToString(
          <Provider store={store}>
            <RoutingContext {...renderProps} />
          </Provider>
        )

        res.status(200).send(renderMarkup(content, store.getState()))
      })
    }
  })
})

Example

See the app in example/.