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

redux-looking-glass

v0.1.7

Published

redux-looking-glass React component

Downloads

29

Readme

Travis npm package Coveralls

redux-looking glass

Motivation

redux-looking-glass is smart Lenses for Redux

The traditional way of using Redux results in cluttered code that is difficult to follow.

The primary goal of this library is to free your code from reducers (and sagas!) and instead have it be more visibile.

Installation

npm install --save redux-looking-glass

or

yarn add redux-looking-glass

Examples

The three main exports from redux-looking-glass are:

lensReducer

This function wraps your root reducer, and allows redux-looking-glass to do its thing.

(see example)

lensFamily

This is a curried helper function that just helps you avoid repeating yourself.

lensFamily('wonderland.cheshire')(
  'status.visibility',
  'location.tree',
)

// note the following is also valid notation and can be mixed and matched if needed

lensFamily(['wonderland', 'cheshire'])(
  ['status', 'visibility'],
  ['location', 'tree'],
)

simply returns

[
  ['wonderland', 'cheshire', 'status', 'visibility'],
  ['wonderland', 'cheshire', 'location', 'tree']
]

lookingGlass

This is a curried higher-order-component lookingGlass([lensFamilies], [dataSources]) returns a function that has the same signature as react-redux's connect (and connect is called under the hood).

The reason for this is to allow you to pass in a normal mapStateToProps and mapDispatchToProps if need be.

more info on data sources

Redux Store Configuration


import { createStore } from 'redux'
import myRootReducer from 'Reducers'
import { lensReducer } from 'redux-looking-glass'

const configureStore = (preloadedState) =>
  createStore(
    lensReducer(myRootReducer),
    preloadedState
  )


Your Component


import React from 'react'
import lookingGlass, { lensFamily } from 'redux-looking-glass'


const cheshireLensFamily = lensFamily('wonderland.cheshireCat')

const cheshireCatLenses = cheshireLensFamily([
  'status.visibility',
])

const displayVisibility = (visibility) => ({
  invisibile: ' ',
  visible: '😸',
  smile: '👄',
}[visibility])

const nextVisibility = (visibility) => ({
  invisibile: 'visible',
  visible: 'smile',
  smile: 'invisibile',
}[visibility])

const CheshireCat = ({ visibility='invisibile', setVisibility }) =>
  <div>
    {displayVisibility(visibility)}
    <button
      onClick={() => setVisibility(nextVisibility(visibility))}
    >
      display {nextVisibility(visibility)}
    </button>
  </div>

const ConnectedCheshireCat = lookingGlass([cheshireCatLenses])(/*mapStateToProps, mapDispatchToProps*/)(CheshireCat)


export default ConnectedCheshireCat

Async Lenses

Current Limitations:

  • limited to network side effects
  • only supports json
  • not a replacement for complex "chain reaction" redux-saga flows, just simple ones
const dataSource = { path, url, method, body }
const ConnectedCheshireCat = lookingGlass([cheshireCatLenses], [dataSource])(/*mapStateToProps, mapDispatchToProps*/)(CheshireCat)

More documentation on async lenses coming soon

The implementation of async lenses is likely to change, and should currently be considered experimental!