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

with-view-state

v0.3.2

Published

use redux to store view state

Downloads

5

Readme

with-view-state

use redux to store some state in view component

Install

npm install with-view-state --save

Introduction

people use redux may confused when to use setState and when to use dispatch reducer action.

this package is aimed to store the state to redux. Forget setState, enjoy redux!

usefull for these situations:

  • show/hide modal
  • submitting/done button
  • loading/hide spinner

Usage

1. add the reducer to your reducers

import { combineReducers } from 'redux';
import { reducer as viewState } from 'with-view-state';

// reducers = ....

export default combineReducers({
  ...reducers,
  viewState
});

2. wrap your component:


import withViewState  from 'with-view-state'
//  YourComponent : .....

const config = {
  id: 'myComponent',      //defualt is a random string, set some name if you need
}

const wrapped = withViewState(config)(YourComponent)

3. get/set in your componet

class YourComponent extends Component{

  onClick = () => {
    this.props.setViewState({ submitting: true } )
  }

  render() {
    const { viewState } = this.props;
    const { submitting } = viewState;
    // ....
  }
}

or dummy component:

const YouCompoent = ({viewState, setViewState}) => {
  //....
}

Configure

The configure that the decorator withViewState() accepts.

getViewState : Function(store): viewStateStore

default is

(store) => store.viewState

if your reducer is not at sotre.viewState, set another function

mapViewProps : Function(thisViewState) => props

default is

(state) => ({viewState: state})

this makes the component use props.viewState to get the state of the view. you can use another function as you wish

keepState : Bool || Function(props) Bool

As default, when a view is unmounted, it's view state will be removed from the store, you can set keepState = true to keep it , or set a function to determin by the props.

some configures will be deprecated in future:

reducerName : String

set the store name in reducer, default is 'viewState'

propName: String

set the props where can get the view state for a view , default is 'viewState'

Props

The props that generated to give to your decorated component.

setViewStateAction : Function(Object): action

This is a bound action creator for the view, it return the action

setViewState : Function(Object) :Void

this function dispatch a bound view update action

dispatchWithIndicator: Function(action, indicator) : Void

this function will first dispatch a indicator start action and then dispatch the action with a meta fields onCompleteAction which is the idicator complete action.

indicator: String || Object

when indicator is a string, it will be as the field name, in start it will be true, on completed, it will be false, if indicator is a object, it will be itself on start, and on completed, it will be a object with the same keys, but every value si false

for explain:

indicator = "submitting"

//on start :
viewState = {submitting : true, ...others }
//completed:
viewState = {submitting : false, ...others }

or

idicator = { spin: "double-bounce" , submitting: true }

//on start:
viewState = { spin: "double-bounce", submitting: true, ...others }
//completed:
viewState = { spin: false, submitting: false, ...others }

Notice: You must use some async handlers like redux-saga to dispatch the onCompleteAction.