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

rzero-tools

v1.1.1

Published

A decorator and HOC component for redux-zero

Downloads

18

Readme

Redux-Zero Tools (rzero-tools) Build Status MIT license package version

Overview

I was recently reviewing redux-zero and the tool seems to seriously take the strain off using redux given the massive amount of boiler plate that tool requests its users provide. Though redux-zero was a breath of fresh air, as are many tools that cut out the cruft, it was also missing some convenience that once achieves when finally getting redux setup in your project. The biggest missing part was being able to receive only the slice of your store that you need and being able to update that piece as easily.

Installation

Add the module as a dependency to your application

npm install --save rzero-tools

Usage

As a fan of using ES7 style decorators, I felt that it might make more sense to provide a single decorator to solve this issue. The decorator goes before your react component and takes a reference to your store, and a dot separated string denoting the path to your slice of the store.

A complete example can be shown here:

import React, { Component } from 'react'
import { render } from 'react-dom'
import { UseStore } from 'rzero-tools'
import { createStore, Provider } from 'redux-zero/react'

const store = createStore({
  pages: {
    home: {
      name: "Example Home Page Title"
    }
  }
})

@UseStore(store, 'pages.home', 'page')
class Home extends Component {
  changeName() {
    this.props.updateState({name: 'A contrived title'})
  }

  render() {
    // The default injected variable is called page, so the third parameter
    // to the decorator can be omitted if the property name "page" is
    // acceptable. Otherwise, modify this to be what you want.
    let { page } = this.props

    // Note that if you invoked this.changeName() via a timeout or click,
    // it would fire an update that only modified the state.pages.home object
    // as specified in the path of the @UseStore decorator.

    return (
      {/* As you might imagine this is "Example Home Page Title" */}
      <div>{page.name}</div>
    )
  }
}

render(
  <Provider store={store}><Home/></Provider>,
  document.querySelector('#react-root')
)

The important bit above is the decorator, @UseStore(), used to connect the component to the store as well as being able to read and write to specific part of the store.

A noteworthy callout is the fact that by simply specifying 'pages.home', the component is given the part of the store that maps to store.getState().pages.home.

If the path is left off or is supplied as an empty string, then the entire state is supplied.

Caveats / TODOs

Important

  1. Currently, due to the way this was built, the path specified in the store should all consist of objects or bad things will happen to your store.
  2. There may be a way to refactor things in the future, perhaps in a 2.0 release, where the store does not have to be passed to the decorator.

These would be ideal and if I continue to use redux-zero I'll focus on these two points as my primay next steps.