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

es3-observ

v1.0.0

Published

An ES3-compatible rewrite of observ, observ-struct & observ-varhash, exposed as a single API

Downloads

2

Readme

#es3-observ

An ES3-compatible rewrite of core 'observ' modules, exposed as a single API:

Getting Started

Observable can be used in any node/browserify project out of the box:

var observ = require('es3-observ')

For global usage or AMD, you'll want to build the library (see Grunt Tasks below);

Basic Usage

Create an observable with an optional initial value:

var o = observ(1);

(if you don't pass an initial value, it will be set to null).

To get the value of the observable at any time, call it with no arguments:

var value = o();

console.log(value);

>>> 1

To bind listeners to the observable, call it with a function:

o(function (value) {
    console.log('[A]', value);
});

This function will be called every time the observable changes.

To set the value of the observable, call its set method:

o.set(2);
>>> [A] 2

If you assigned your listeners to a variable, you can call that to remove that listener:

var listenerB = o(function (value) {
    console.log('[B]', value);
});

o.set(3);

>>> [A] 3
>>> [B] 3

listenerB();
o.set(4);

>>> [A] 4

API

observ.value (aliased to observ)

Described in Basic Usage

observ.computed

Creates an observable which will update when any dependent observables change:

var oA = observ.value(1);
var oB = observ.value(1);
var oC = observ.computed([oA, oB], function (vA, vB) {
    return vA + vB;
});

oA(function (value) { console.log('[A]', value); });
oB(function (value) { console.log('[B]', value); });
oC(function (value) { console.log('[C]', value); });

oA.set(2);

>>> [C] 3
>>> [A] 2

oB.set(2);

>>> [C] 4
>>> [B] 2

observ.struct

Create an observable object which will update when any child observables change, and provide direct access to child observables.

var o = observ.struct({
    a: observ.value(1),
    b: observ.value(1)
});

o.a(function (value) { console.log('[A]', value); });
o.b(function (value) { console.log('[B]', value); });
o(function (obj) { console.log('[S]', obj.a + obj.b); });

o.a.set(2);

>>> [S] 3
>>> [A] 2

o.b.set(2);

>>> [S] 4
>>> [B] 2

observ.varhash

Create an observable mapping of keys to values which will update when any value changes, provide access to values through a get method, and allow insert/update and deletion of keys with the put and delete methods.

var o = observ.varhash({});

o(function (hash) {
    var sum = 0;

    for (var key in hash) {
        sum += hash[key];
    }

    console.log('[V]', sum);
});

o.put('a', 1);

>>> [V] 1

console.log(o.get('a'));

>>> 1

o.put('b', 2);

>>> [V] 3

o.put('a', 2);

>>> [V] 4

o['delete']('b');

>>> [V] 2

Examples

Run the development grunt task (instructions below) and open http://localhost:8000 in your browser. You'll find basic examples of ObservableValue, ComputedObservable, ObservableStruct & ObservableVarhash, as well as the code that created them.

Development

$ npm start

This will run npm install to locally install Node package dependencies, then run the default grunt task which:

  • Runs grunt dev to create a development build (see Tasks, below)
  • Starts up a development server in the build directory, running on http://localhost:8000
  • Watches files under src/ for changes, triggering partial development builds as required

Grunt Tasks

The build tasks transform the project source in src/ into a build under build/.

Development Build: $ grunt dev

Creates a local development build of the project.

  • JS in scripts/ is linted by JSHint, then bundled by Browserify into scripts/index.js
  • All other directories/files under src/ are copied directly across (such as index.html where the interactive examples live)

A global observ object is exposed when you run build/scripts/index.js globally or use an AMD loader.

Production Build: $ grunt prod

Creates a production-ready standalone build of the project.

The build process is similar to the development build, except the script is minified

Default: $ grunt