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

vnstore

v1.7.16

Published

very nice store

Downloads

27

Readme

vnstore

A lightweight library to manage state + listen to state changes globally

TODO

  • split react stuff into it's own repo
  • combine vnstore + vnlocal. store just has a persist option
  • fix typings on the react stuff
    • also in general need to just solidify the API there

Getting Started

npm i -s vnstore
import {vnstore} from 'vnstore'

const $items = vnstore()

vncontext

import {vncontext, useContextHost, useProp} from 'vnstore'

const ctx = vncontext({count: 0})

const Parent = () => {
  const {host, setProp} = useContextHost(ctx)

  return host(
    <div>
      <Child />
    </div>
  )
}

const Child = () => {
  const setProp = useSetProp(ctx)
  const count = useProp(ctx, 'count')

  return (
    <div>
      <span>{count}</span>
      <button onClick={() => setProp('count', count + 1)} />
    </div>
  )
}

vnstore

Store Config

vnstore({
    fetcher: () => [], // a function which will return a list of items (either sync or as a promise) to fetch a list of items
    dependsOn: [], // a list of stores that when the selection changes will cause this store to be refreshed
    lazy: true, // call the fetcher one when items are needed
})

/** fetcher example */

const $items = vnstore({
    fetcher: () => fetchItemsAsync()
})
$items.refresh() // this will call fetchItemsAsync() and populate the store with it's response

/** lazy example */

const $items = vnstore({
    fetcher: () => fetchItemsAsync(),
    lazy: true
})
// fetchItemsAsync() not called yet
$items.list$(...)
// fetchItemsAsync() is called now


/** dependsOn example */

const $items = vnstore()

const $childrenItems = vnstore({
    fetcher: () => fetchChildrenAsync(),
    dependsOn: [$items]
})

$items.select('a')
// fetchChildrenAsync() is called

$items.select('b')
// fetchChildrenAsync() is called again

Data fetching

$items.loading() // false
$items.loading$(isLoading => ...)
$items.useLoading() // false

$items.refresh()
$items.loading() // true

Setters

$items.insert({id: 'a', prop1: 'abc', prop2: 'def'})
$items.insert([
  {id: 'a', prop1: 'abc', prop2: 'def'},
  {id: 'b', prop1: 'nice', prop2: 'one'}
])
$items.update('a', {prop1: 'ABC'})
$items.delete('a')
$items.select('a')
$items.size() // number

Getters

$items.list() // Item[]
$items.list(e => e.prop1 === 'qwerty') // Item[]
$items.map() // Map<string,Item>
$items.get('a') // Item | undefined
$items.selected() // Item | undefined

Listeners

$items.list$(items => /* Item[] */)
$items.list$(e => e.prop1 === 'qwerty', items => /* Item[] */)
$items.map$(e => /* Map<string,Item> */)
$items.get$('a', e => /* Item | undefined */)
$items.selected$(e => /* Item | undefined */)

React hooks

Hooks use listeners and will rerender component when items change

$items.useList() // Item[]
$items.useList(e => e.prop1 === 'qwerty') // Item[]
$items.useMap() // Map<string,Item>
$items.useGet('a') // Item | undefined
$items.useSelected() // Item | undefined

Other

$items.reset()
$items.list() // []