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

reactive-redux

v1.1.1

Published

Allows you to generate a reactive data source for Meteor/Tracker from a part of a Redux tree.

Downloads

14

Readme

reactive-redux

Allows you to generate a reactive data source for Meteor/Tracker from a part of a Redux tree.

Goals

Whether you are integrating Redux into an existing Meteor project, or wanting to create a new project using Redux and Tracker, it is not easy to get both systems (Redux/Tracker) to play well together. This mini helper module allow you to generate reactive data source from the redux Store for Meteor to consume.

Usage

Let say you have a Redux Store with state having the following shape :

state = {
  posts {
    total : 12,
    selectedId : "zec1d4"
  }
}

You would like to rerun your autoruns based on the id of the selected post in your store.

import factory from "reactive-redux";
import {Tracker} from "meteor/tracker";
import {Store} from "./whereItWasInitialized.js";

//regular Meteor reactive datasource with a get() method
const reactivePostId = factory("posts.selectedId", Store); //Store is you Redux Store

Tracker.autorun(()=>{
  Meteor.subscribe("post_comments", reactivePostId.get()); //reactivePostId is a reactive data source.
};

The reactive data source has a get() method like a ReactiveVar or Session. However it has no set() since all your mutations should be commited on the redux Store through action creators.

Alternative usage

Since version 1.1.0, you can provide a selector to the factory in place of the path key. This way you can avoid using a magic string, and there is only one place to change (the selector), when your redux state shape changes.

The precedent example becomes this :

import factory from "reactive-redux";
import {Tracker} from "meteor/tracker";
import {Store} from "./whereItWasInitialized.js";

//selector to access the part of the state tree you are interested in
const selector = (state)=>(state.posts.selectedId);

//the factory is provided this time with the selector instead of the string path
const reactivePostId = factory(selector, Store);

Tracker.autorun(()=>{
  Meteor.subscribe("post_comments", reactivePostId.get()); //reactivePostId is a reactive data source.
};

It's strongly recommended that your selector doesn't do too much cpu intensive tasks since it will be rerun on each redux state change for comparison purpose. Using the reselect library for memoization is also probably a good idea.

API

The module has a unique export which is a factory function which generate the reactive data sources.

factory(pathOrSelector, Store) (default export) - returns a reactive data source whose get() method will return the part of the state tree you are interested in.

The pathOrSelector is a path string or a selector function.

  • A path string uses the object-path get path syntax
  • A selector is a function taking the whole redux state as a unique parameter and returning the part of the state tree you are interested in, eventualy after additional treatment.

The Store param is the initialized Redux Store;

reactiveDataSource the object returned by the factory which will trigger a rerun of every Tracker/Meteor computation (Autoruns, Blaze helper..) you will put it in.

The object has a get() method which returns the value in your Store pointed by the path.

It has also a a cancel() method if for some reason you would like to unbind the value from the Store. In that case, get() will still return the current value, but the data source will not be reactive anymore.

Acknowledgements

Thank you to Alexander Ivantsov whose redux-subscriber module allow this module to do its thing.