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

@gnandretta/atom

v0.0.1

Published

Atom like reference type to manage and observe state changes

Downloads

2

Readme

Atom

Manage and observe state changes in JavaScript, based on Clojure(Script) atoms.

Usage

var atom = require('atom');

var gabriel = atom({likes: "ice cream"});

gabriel.addWatch("logger", function(state) {
  console.log(state);
});

gabriel.state // => {likes: "ice cream"}

gabriel.swap(function(state) {
  return {likes: "cookies"};
});

// {likes: "cookies"} will be logged in the console

gabriel.state // => {likes: "cookies"}

Rationale

I want a clear distinction between state and identity.

Creating an atom

atom(state)

Creates a new atom with initial state.

Getting the atom state

a.state

Returns the current state for the atom a.

Updates

a.reset(state)

Sets the state of atom a to state.

a.swap(f, ...args)

Sets the state of atom a to the result of applying the function f to the current state, a.state, and the provided args.

function setLike(state, food) {
  return Object.assign({}, state, {likes: food});
}

a.swap(setLike, "hamburguers");
a.state.likes // => "hamburguers"

a.mreset(meta, state)

Like reset but it will pass the metadata meta to the watches.

a.mswap(meta, f, ...args)

Like swap but it will pass the metadata meta to the watches.

Observation

a.addWatch(key, f)

Invoke the function f every time the state of the atom a is updated. The key parameter is a ~String~ that is used to identify the watch and remove it later.

Every time the function f is invoked, it will recieve the following params:

  • state: current state of the atom, after the update.
  • oldState: the previous state of the atom, before the update. It is possible that state === oldState if you don't update the atom's state or if you update the state in place. The function f is called every time one of the update methods are called, there is no guarantee that the state has actually changed and that the changes are preserved in oldState. That is up to you.
  • key: the key provided when adding the watch.
  • meta: the metadata provided when performing the update with mreset or mswap. If the update was done through reset or swap this parameter will be undefined.

a.removeWatch(key)

Stop invoking the function for the watch with the key key.