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

react-iflow

v1.0.0-alpha.29

Published

The connector for react and iFlow state management.

Downloads

78

Readme

React iFlow

The connector for React 🌈 iFlow state management.

Travis Coverage Status npm

React iFlow If you use React and iFlow to manage state, save all kinds of selectors cumbersome, while supporting a variety of user-defined store.

🔥🔥🔥It is a highly efficient and concise React and iFlow store connector🔥🔥🔥

Features and benefits

  • Least possible time selector
  • Automatic array diff
  • Full support comprehensive selector
  • Support immutable

Install

yarn add react-iflow
//or
npm install --save react-iflow

Getting started

To Edit

The Gist

  • index.js
import React, { Component } from 'react'
import ReactDOM from 'react-dom'
import Body from './body'
ReactDOM.render(<Body/>, document.getElementById('app'))
  • store.js
import iFlow from 'iflow'

const pipe = iFlow({
  calculate: function (number) {
    this.counter += number
  },
  counter: 0,
})

const store = pipe.create()
export default store
  • body.js
import React, { Component } from 'react'
import flow from 'react-iflow'
import store from './store'

class Body extends Component {
  render () {
    return (
      <div>
        <button onClick={() => this.props.store.calculate(-1)}>-</button>
        {this.props.store.counter}
        <button onClick={() => this.props.store.calculate(1)}>+</button>
      </div>
    )
  }
}

export default flow(store)(Body)

Examples

React with iFlow examples Counter(Online) TODO(Online)

API

flow

It's the standard connector of iFlow store

import flow from 'react-iflow'

flow is higher-order function,and it supports the decorator's writing. If the last one argument of the flow is store, then the connected store will take it precedence.

  • Selector: In fact, in most cases, 🎉🎉🎉you don't need to use selectors🎉🎉🎉, because iFlow will automatically help you diff state to determine if the component is updated, unless you need to compute derived data.

  • Higher-order functions
class CustomComponent extends Component {}
flow(store)(CustomComponent)

If use Provider, you don't need to pass the store argument, unless you need to set the selector.

class CustomComponent extends Component {}
flow()(CustomComponent)

More concise way

import { connect } from 'react-iflow'
class CustomComponent extends Component {}
connect(CustomComponent)
  • Class decorator
@flow()
class CustomComponent extends Component {}
  • User-defined select node store
@flow(store.count)
class CustomComponent extends Component {}
  • With array selectors functions
@flow([(state, props) =>{
  return {
    ...props,
    count: state.count,
  }
}],store)
class CustomComponent extends Component {}
  • With arguments selectors functions
@flow(
  (state, props) =>{
    return {
      ...props,
      count: state.count,
    }
  },
  (state, props) =>{
    return {
      ...props,
      counter: state.count.counter,
    }
  },
  store
)
class CustomComponent extends Component {}

provider

import { Provider } from 'react-iflow'
ReactDOM.render(<Provider store={store}><Body/></Provider>, document.getElementById('app'))
  • Provider depend on the react's context to complete the cross component transfer, and its role is exactly the same as react-redux's Provider if you are familiar with react-redux

connect

import { connect } from 'react-iflow'
class CustomComponent extends Component {}
connect(CustomComponent)

When you call Provider inject store, you can use connect API to quickly connect store to the component, it's simple.

immutable

  • Single-layer immutable store is effective when using immutable

@immutableis a single-layer traversal props, so the mixed structure of the iFlow store and plain objects is invalid.

For example:

class Parent extends Component {
  // this.props.sub is iflow store
  render() {
    return <Sub store={this.props.sub} />
  }
}

@immutable
class Sub extends Component {
  // omit
}

This is effective. But the following example is not valid:

class Parent extends Component {
 // this.props.sub is iflow store
 render() {
   const store = {foo:'bar', sub: this.props.sub}
   return <Sub store={store} />
 }
}

@immutable
class Sub extends Component {
 // omit
}

Of course, if you're not using @immutable You can arbitrarily pass the iFlow store.

  • About the Usage of PureComponent

Because the iFlow connector uses the mutable store by default, So the connector directly with the React.PureComponent connection will not be updated, iFlow connector corresponding component should be react.Component, do not worry, iFlow will automatically diff comparison, it is more efficient and automatic than the light comparison of React.PureComponent.

If you really need to use react.PureComponent, then it is recommended that you could use cooperatively with @immutable. This is a great help in Sub-Component performance optimization.

For example:

@flow(store)
@immutable
class Body extends PureComponent {
  render () {
    return (
      <div>
        <button onClick={() => this.props.store.calculate(-1)}>-</button>
        {this.props.store.counter}
        <button onClick={() => this.props.store.calculate(1)}>+</button>
      </div>
    )
  }
}

License


MIT