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

obcache

v0.2.3

Published

observable based cache interface for client side apps

Downloads

4

Readme

obcache is a utility for client side data caching, and ensuring all users of the data see updates. For use with react, see react-obcache.

It uses listener reference counting to avoid no longer needed data piling up.

Install

npm install obcache --save

Usage

Start by creating a cache. You can then .register handlers which are responsible for providing promises of data.

import ObCache from 'obcache';

var cache = new ObCache();
export default cache;

cache.register('userProfile', ([userId]) => {
  var promise = api.get('/user/' + userId + '/profile');
  return promise;
});

This example shows the full api of obcache. Typically you won't deal with it directly, but use a wrapper for your ui library/framework.

import cache from './cache';

var profile = cache
  .get('userProfile', '4920840918098')

profile.key === 'userProfile├4920840918098';

// makes the api request if the data isn't already present
// and registers listeners for new values
// they're called immediately if there is already a value or error
var unsubscribe = profile.listen({
  okay(profile) {
    console.log(profile);
  },
  error(error) => {
    console.log(error);
  },
  all(errorOrProfile) => {
  },
});

setTimeout(() => {
  // force a new request for the data, listeners are called again when it completes
  profile.refresh();
}, 1000)

setTimeout(() => {
  // remove our listener
  // the data becomes eligable for collection if there are no other listeners
  unsubscribe();
}, 5000);

// manually set the value
// this is typically used when e.g. you have a user listing call that wants
// to create several userProfile observables in the cache
profile.set({firstName: 'x', lastName: 'y'});

// set it to the new value; revert if the promise is rejected
// this can be used for optimistic updates
profile.setAssuming({firstName: 'x', lastName: 'y'}, () => {
  return aPromise;
});

// similar to the above but only updates the keys in the object mentioned
// so with state {a: 1, b: 2}; .update({a: 3}) results in {a: 3, b: 2}
// with set, it'd be replaced with {a: 3}
// updates are immutable transactions
profile.update(...)
profile.updateAssuming(...)

ES6 deps

obcache works best if setImmediate is available. Core.js (or babel polyfill) provides it.

Object.assign is required.

Development

Run npm run dev in one terminal, and npm run dev-test in another.

To do a single build, npm run build and npm run test.