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

use-state

v0.0.3

Published

State management with models, immutable data and promise-based middlewares

Downloads

39

Readme

State management with models, immutable data and promise-based middlewares

Current Progress

  • [x] Support express-like(use-like) and promise-based middlewares
  • [x] Support Map, like {count: Number, login: {name: String}}
  • [x] Support List, like List(Number)
  • [x] Support Model, like Model('User', {name: String})
  • [x] Support used with react component
  • [ ] Support normalization and validation for key's value
  • [ ] Support auto/manual garbage collection for non-referenced model records
  • [ ] Support serialization for the state
  • [ ] Consider practice on server render phase
  • [ ] Consider partial data mount and unmount, to keep store low-memory cost

Features

  • Use model to define your structured and relational data
  • Support express-like(use-like) and promise-based middlewares
  • Allow async call(promise/async-await) in the middleware
  • Use immutable data and operates like immutable.js

Vision

//store.js
//define a model
const User = Model('User', {
  name: String,//literal key
  houses: List(House),//refer another model
})
const House = Model('House', {
  addr: String,
  user: User,
})

const structure = {
  loginUser: User,
  houseCount: Number, houses: List(House),
  prices: {dollar: Number, rmb: Number}
}
const store = new Store({structure});
store.use(router);

//router.js
const router = require('use-router');
router.all('/houses/query', (req)=>{
  const store = req.store;
  let state = store.state;
  return fetch('/houses/query', {userId: state.get(['loginUser', 'id'])})
  .then((result)=>{
    const {rows, count} = result;

    store.mutate((newState)=>{
      const houses = House.merge(rows)
      newState.set('houses', newState.get('houses').push(houses));
      newState.set('houseCount', count);
      newState.set(['houseCount', 'dollar'], count*1000);
    })
  })
  .catch(err=>{

  })
})

//AllHousesListView.js
class AllHousesListView extends Component{
  componentDidMount(){
    this.props.dispatch('/houses/query');
  }
  render(){
    const elHouseList = this.props.houses.map(house=><span>{house.get('id')} {house.get('addr')}</span>)
    return (<ul>
      {elHouseList}
    </ul>)
  }
}

connect((state, dispatch)=>{
  return {houses: state.get('houses')}
})(AllHousesListView)

Development

  1. Run npm run watch in other terminal
  2. Run npm run test:only -s to do test only work
  3. Run npm test to do lint, build and test, before publish
  4. Run npm run cover to do coverage test
  5. Run npm run perf to do performance check

License

Licensed under MIT

Copyright (c) 2017 kiliwalk