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

bookie

v0.1.0

Published

Predictable and scalable state container in 0.5kB

Downloads

4

Readme

Bookie

Predictable and scalable state container in 0.5kB.

Simplicity is a great virtue but it requires hard work to achieve it and education to appreciate it. And to make matters worse: complexity sells better.

— Edsger W. Dijkstra, 1984

If Redux evolves the ideas from Flux but without it's complexity, Bookie evolves the ideas from Redux, by reducing the complexity still.

Gist

import { createStore } from 'bookie';

// First we create the store. The `createStore` function accepts one argument
// which will be the initial state of the store.
//
// Much like in Redux, any value type can be used for the state: Bookie is
// cool with primitives, arrays and objects.
const store = createStore(0);

// Once we got our store, it's time to define actions. Actions are simple
// pure functions that take state and return a new state. Optionally they
// can also accept a second argument for payload.
//
// If the state you are passing is an object, it will also be frozen at
// the root level to ensure that no mutation can occur.
const increment = store.createAction((state, payload = 1) => state + payload);
const decrement = store.createAction((state, payload = 1) => state - payload);

// We can listen to new state emittions with `subscribe`, the callback will
// receive a single argument which is the new (frozen) state.
const unsubscribe = store.subscribe(console.log);

// Finally lets dispatch some actions! All you have to do is call a function,
// no indirection required.
increment();
// -> `1`
increment();
// -> `2`

// We can pass payload to our action.
increment(5);
// -> `7`
decrement();
// -> `6`

// Calling the function returned from `subscribe` will unsubscribe that
// particular listener.
unsubscribe();

// Since the listener has been removed, calling `dispatch` again will not
// print anything.
decrement();

// Finally `getState` returns current state of the store. Once again, this
// value is frozen at the root level to avoid mutations.
console.log('Final state', store.getState());
// -> `Final state 5`