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

resource-shadow

v0.0.10

Published

ResourceShadow ==============

Downloads

15

Readme

ResourceShadow

Build Status Code Climate Test Coverage NPM version NPM dependencies Bower version

keep a synchronized copy of a remote http resource. Modify freely and changes will be synced in the background automatically.

  • modify the local copy without blocking I/O (don't make users wait for a server response)
  • localStorage is used to keep realtime sync with other frames/tabs/windows in same domain
  • saving/loading to remote http server is done in the background
  • works in offline mode (only localStorage), switch to online mode (http) at any time
  • custom 3-way merge is supported (used when both local and server versions were modified)
  • retries (with a delay) on timeout or other network errors

Usage

  // will load it from localStorage if exists
  var preferences = resourceShadow.create({ localKey: 'preferences'});

  // set initial value
  preferences.apply({ color = 'white' });

  // make changes offline using .apply (no async callbacks!)
  preferences.apply(function(data){
    data.color = 'red';
  });

  // change was immediately persisted to localStorage

  // go online
  preferences.goOnline('http://myhost/user/' + currentUser.id + '/preferences').load();

  // value from server is loading

  // you can make changes without waiting
  // just beware that might trigger a 3-way merge (by default local wins)
  preferences.apply(function(data){
    data.color = 'blue';
  });

  // you can wait using events
  preferences.once('loaded', function(data){
    data.color = 'blue';
  });

  // you can load server-side changes at any time
  setTimeout(function(){
    preferences.load();
  }, 3000);


  // custom 3-way merge
  preferences.options.threeWayMerge = function(originalJson, serverJson, localJson) {
    // using a naive object properties merge (check lodash .merge)
    return _.merge({},
      JSON.parse(originalJson),
      JSON.parse(serverJson),
      JSON.parse(localJson));
  });

  // using load and "rebase"
  var preferences = resourceShadow.create({ localKey: 'preferences2'});
  preferences.apply({ someInitialLocal: 'values' });

  // will load server value, and apply local value on top of it (using 3 way merge)
  // the result will be as if local version were created *after* (or on top) of server version
  preferences.loadAndRebase();

  // reset to initial state (and go offline)
  preferences.reset();

  // listen for changes
  preferences.on('change', function(data, info){
    if (info.source === 'localStorageEvent') {
      console.log('a change arrived from another tab/frame/window');
    } else if (info.source === 'apply') {
      console.log('a change was just applied locally');
    } else if (info.source === 'server') {
      console.log('a change was loaded from server');
    } else if (info.source === 'localStorage') {
      console.log('a change was found at localStorage');
    }
  });

  preferences.on('saved', function(){
    console.log('changes were saved to the server');
  });

Supported Platforms

  • IE9+ and modern browsers

visit test page to test your current browser.