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

v1.0.0

Published

A riot mixin connecting tags to your redux store

Downloads

69

Readme

riot-redux-mixin

Build Status npm version

A riot mixin to connect tags to your redux store. Memoizing your selectors is probably a good idea (see https://github.com/ibloat/riot-redux-sample)

Usage

// get your store
var store = configureStore()

// pass the store to the mixin and tell riot about it
riot.mixin(riotReduxMixin(store)) // either globally
riot.mixin('redux', riotReduxMixin(store)) // or shared

and then in your tags (in case of a shared mixin)

this.mixin('redux')

// if needed mix actions or action creators into the tag via dispatchify
var foo = require('actions/foo')
this.dispatchify({ foo })

// these are now equivalent
this.foo()
this.dispatch(foo())

// if needed subscribe in some way
this.subscribe(function(state) { return { bar: state.foo.bar } }) // this.bar will be set on update
// or use reselect to reduce the amount of update() calls
var selector = require('selectors/bar')
this.subscribe(selector) // whatever object the selector returns will be merged into the tag
// you can also pass in a callback that will be called instead of this.update
this.subscribe(selector, console.log)

API

  • dispatch(action) - does what it says on the box, returns whatever store.dispatch returns.

  • dispatchify({actions}) - this one takes your action objects or action creators and makes them available in your tag's scope to be dispatched directly (without having to wrap them in dispatch() every time). The actions parameter is an object containing the actions so by calling this.dispatchify({foo}) you then can dispatch foo via this.foo() instead of this.dispatch(foo()). This is quite handy when you want to dispatch actions from DOM events.

  • subscribe(selector, callback = this.update, changed=selector.recomputations) - selector is a function that gets passed the current state and is expected to return an object. The object's keys will be merged into the tag's scope. For larger projects using a memoizing library like reselect is probably a good idea. That way your tag will only get updated when state relevant to your tag has changed.

    When not passing in a callback your tag will get updated with the new state via this.update(obj) otherwise the callback will get called with the selector's return value.

    Via the changed parameter one can pass either a function or a string that will determine how the selector is checked for updates. By default selector will be checked for a recomputations function which is available on reselect selectors.
    If a function gets passed in, it will be called with its own previous return value and an update will be triggered if the previous value and its return value are not equal. E.g. where foo(prev) { return prev; } will never update bar(prev) { return !prev } always will.
    Passing a string will cause the function to be looked up on the selector. subscribe will return an unsubscribe function. On unmount this function will automatically called.