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

rwr-redux

v0.5.0

Published

Redux integration for react_webpack_rails

Downloads

451

Readme

rwr-redux

Redux.js integration plugin for react_webpack_rails.

It allows you to use Redux state containers in a different part of Rails views. Thanks to this gem you can use multiple components (Redux containers) on one page. They can easily access the same store and have their state synced.

Guides and Examples

  • basic react redux rails example: app
  • how to use Redux and react-router in Rails app: guide and example.

Setup

  • Add rwr-redux to your Gemfile:
gem 'rwr-redux'
  • Install rwr-redux and redux packages:
$ npm install --save redux react-redux rwr-redux

Usage

First of all, you have to register your store and containers in react/index.js. Then you can use them in a Rails view using provided helpers. When a page is loaded, your container component is wrapped with <Provider> component and will have access to defined store.

register integrations, store and components in react/index.js

Register integrations:

import RWR, { integrationsManager } from 'react-webpack-rails';

integrationsManager.register('redux-store', RWRRedux.storeIntegrationWrapper);
integrationsManager.register('redux-container', RWRRedux.containerIntegrationWrapper);

Register store:

import Store from './store';
RWRRedux.registerStore('MyStoreName', Store);

Register redux container:

import Container from './containers/MyContainerName';
RWRRedux.registerContainer('MyContainerName', Container);

store

Registered store has to be a function which accepts initial state as an argument and returns store object:

export default function configureStore(initialState) {
  return createStore(rootReducer, initialState);
}

use registered store and components in Rails view

Define store with initial state:

<%= redux_store 'MyStoreName', { foo: @bar } %>

Add Redux container:

<%= redux_container 'MyContainerName' %>

If you have more than one store in a view, you can specify store_name:

<%= redux_container 'MyContainerName', store_name: 'MyStoreName' %>

Usage with react-redux-router

If you want to use router in your redux app, you have to only create routes component. rwr-redux will wrap it with <Router> and <Provider> components, and also, will sync history with the store. Only browserHistory is supported.

example routes

app/react/routes/index.js

export default (
  <Route path="/" component={App}>
    <Route path="about" component={About} />
  </Route>
)

register integration and routes in react/index.js

integrationsManager.register('redux-router', RWRRedux.routerIntegrationWrapper);
import RoutesName from './routes';
RWRRedux.registerRoutes('RoutesName', RoutesName);

use registered routes in Rails view

Do not forget to use redux_store helper.

<%= redux_store 'MyStoreName', { foo: @bar } %>

<%= redux_router 'RoutesName' %>

Server Side Rendering

More info how to use server side rendering with react_webpack_rails: click

Rails routes has to be properly setup:

get '/server_side/' => 'pages#server_side'
get '/server_side/*path' => 'pages#server_side'

To enable server side rendering pass server_side: true to helpers options:

<%= redux_store 'MyStoreName', { foo: @bar }, server_side: true %>

<%= redux_container 'MyContainerName', server_side: true %>

<%= redux_router 'RoutesName', server_side: true %>

NOTE: rwr-redux automatically handles matching, redirecting and routing errors. Redirects and 404's are passed to Rails and handled there so you will be redirected or get 404 page like in normal Rails app.

Contributing

Issues

Found a bug in rwr-redux? Open an issue on GitHub Issues.

Pull requests

Interested in contributing to rwr-redux? That's great, and thank you for your interest!

After checking out the repo, run bundle exec rake setup:all to install every environment dependencies.

To get your contributions accepted, make sure:

  • All the tests pass. Run bundle exec rake test:all.
  • Any new code paths you've added are covered by tests.
  • Describe your changes in pull request (what it adds, how to migrate from previous version etc.)

License

The gem is available as open source under the terms of the MIT License.