1.0.1 • Published 8 years ago

fett-tracker v1.0.1

Weekly downloads
1
License
ISC
Repository
github
Last release
8 years ago

Fett

Fett is a small JS library to track how many versions of your web app are running.

Named after the greatest clone of all time, Boba Fett, Fett updates window.localStorage each time a new instance of your web app is opened in a new tab. It provides utilities to add and remove listeners, so you can react to the creation and removal of instances.

View a working demo of it here.

Why Fett?

Lots of apps are built as SPAs - designed to be navigated like a native app - but used more like a static page. If you've ever opened a resource-hungry SPA across ten or fifteen browser tabs, you have felt this pain as well. Integrating Fett into your app will allow users who do this kind of thing to have a smoother experience.

You can turn off features of your app as more instances of your app load, or even send the number of instances as a param to the server and have that return a static page instead of a SPA. At the very least, you can display a message to warn the user that they're not using your whiz-bang Babel-transpiled Webpack-bundled Redux app properly.

Installation

Run npm install fett-tracker or copy /src/fett.js.

API

startCounting

Before you can do anything, you have to call fett.startCounting('myCoolKey'), which takes an optional string parameter so you can set the key you'd like to use in localStorage. If you call startCounting with no parameters, it will choose a key for you. Feel free to call startCounting multiple times - it doesn't overwrite the data in localStorage.

numInstances

Once your app is counting its instances, call fett.numInstances() to get the number of current instances.

addListener and removeListener

To react to instances of your app being created or destroyed, you can add and remove listeners with fett.addListener(function) and fett.removeListener(function). The function you pass to addListener will be called every time localStorage changes.

1.0.1

8 years ago

1.0.0

8 years ago