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

riot-redux-router-immutable

v2.0.0

Published

ImmutableJS + RiotJS Router + Redux Middleware

Downloads

7

Readme

riot-redux-router-immutable

Dead simple integration between the riot js router and redux with ImmutableJS

Combine Riot's router, redux, and immutable so you can easily dispatch route actions to simultaneously update your store and the browser url. Does very little else - this readme is longer than all the code combined.

Features:

  • route action to dispatch in order to change the route
  • middleware to handle riot's router
  • optional reducer to update the store with the current url

Install:

npm install riot-redux-router-immutable

Usage:

To start using the riot router with redux, you must add the riotRouterMiddleware to your store (and the router reducer or your own to track the current url).

The middleware listens for ROUTER_GO_ACTIONs and uses their payload to trigger the riot router's route function instead of continuing on to the reducers. When the route changes, the middleware dispatches a ROUTER_ROUTE_CHANGED action, which is handled by the reducer to update the current url in the store.

Example

Example initialization - add the router middleware to redux

var riot = require('riot')
var redux = require('redux')
var router = require('riot-redux-router-immutable')

var rootReducer = require('./app/reducer')

var createStoreWithMiddleware = redux.compose(
  redux.applyMiddleware(router.middleware.factory()),
  // your other redux middleware here...
)(redux.createStore)

var reduxStore = createStoreWithMiddleware(rootReducer)

Example top level reducer -- router.current_url will be set on route change

var redux = require('redux')
var router = require('riot-redux-router-immutable')


module.exports = redux.combineReducers({
  router: router.reducer,
  // your other reducers here
})

Example usage -- 'custom-tag.tag'

<custom-tag>

  <a onclick={selectPage} url='page1'>Page 1</a>
  <a onclick={selectPage} url='page2'>Page 2</a>

  <div class={hidden: state.router.current_url !== 'page1'}>Page 1 FTW</div>
  <div class={hidden: state.router.current_url !== 'page2'}>Page 2 is Great</div>

  <div>Current Page: {state.router.current_url}</div>

  <style scoped>
    .hidden { display: none; }
  </style scoped>

  <script>
    var actions = require('riot-redux-router').actions
    var store = this.opts.store

    store.subscribe(function() {
      // NOTICE the toJS() - turn the immutable map into POJO
      this.state = store.getState().toJS()
      this.update()
    }.bind(this))

    selectPage(element) {
      store.dispatch(
        actions.route(
          element.target.getAttribute('url')
        )
      )
    }
  </script>
</custom-tag>