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

observe-event

v0.7.1

Published

Make Object.observe emit events on every change

Downloads

11

Readme

observe-event NPM version Build Status Dependency Status

Make Object.observe emit events on every change

Object.observe is finally here and everyone is excited, but simply giving one callback the observe can make it hard to manage and re-use observations.

This simple Object.observe wrapper will return an event emitter instead that allows us to specify what type of change we want and passing the emitter around. If we want to catch all type of changes, we can do that too.

API

eObserve(object[, optAcceptList]) : EventEmitter

optAcceptList defines what type of changes to listen to. If not defined, it defaults to all changes (see below).

Events

The event emitter returned from eObserve(), emits changes made to the observed object in a channel that is the same as the type of change.

For instance:

eObserve(object).on('update', callback);

In addition to all types of changes as defined by the spec, a special channel exists to catch any change:

// Will trigger on any change
eObserve(object).on('any', callback);

Event overview

  • any – Triggered for all of the below
  • add
  • update
  • delete
  • reconfigure
  • setPrototype
  • preventExtensions

See the harmony specs for more information of the different changes

Install

Install using NPM

npm install --save observe-event

Install using Bower

bower install --save observe-event

Install manually

Download observe-event.js or observe-event.min.js from the dist folder and include in your HTML. See below for more details.

Usage

Node.js / Browserify

var eObserve = require('observe-event');

var obj = { message: 'Hello World!' };
eObserve(obj).on('update', function (change) {
  // => change.object.message = 'Hello, World!'
});

obj.message = 'Hello, World!';

See example

Manually in the browser

<script src="./dist/observe-event.js"></script>

var obj = { message: 'Hello World!' };
eObserve(obj).on('update', function (change) {
  // => change.object.message = 'Hello, World!'
});

obj.message = 'Hello, World!';

See example.

Using AMD (Require.js etc)

Not yet tested with AMD

Files observe-event.js and observe-event.min.js is wrapped with UMD (Universal Module Definition), so it should work with AMD as well as directly loading in the browser.


require(['observe-event'], function(eObserve) {
  var obj = { message: 'Hello World!' };
  eObserve(obj).on('update', function (change) {
    // => change.object.message = 'Hello, World!'
  });

  obj.message = 'Hello, World!';
});

Changelog

Version 0.7.0

  1. Changes from having a single file with UMD in it, to use a build step creating seperate distribution files.
  2. No longer have external dependencies (EventEmitter.js).
  3. For AMD and Browser you now need to use either observe-event.js or observe-event.min.js.

License

MIT License