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 🙏

© 2026 – Pkg Stats / Ryan Hefner

observer-proxy

v1.0.5

Published

Observer Proxy is watching object's changing.

Readme

Obserer Proxy

Observer Proxy is watching object's changing.

Observer Proxy only let you know when the value is changed which you are looking at.

If you get object.a, it will let you know if object.a changed.

Then object.b changed, it won't let you know. because you never get object.b!

You can update your view like React using this automatically.

Install

npm install observer-proxy

How to use

import createObserverProxy, { Observer } from 'observer-proxy';

const observer = new Observer({
  onStateUpdate: () => {
    // This funciton will be called when you change property by observer proxy.
    // like `observerProxy.abc = 5;`.
  },
});

// Make observer proxy
const observerProxy = createObserverProxy(myObject, observer);

// Get value
const abc = observerProxy.abc;

// Set value
observerProxy.abc = 5;

// Stop observing
observer.stopObserving();

How to use - Quick Example

import createObserverProxy, { Observer } from 'observer-proxy';

// 0. Prepare your object
const myObject = {
  abc: 123,
  def: 456,
};

// 1. Define your observer
const observer = new Observer({
  onStateUpdate: () => {
    console.log('Observer State Update Detected');
  },
});


// 2. Create Observer Proxy
const observerProxy = createObserverProxy(myObject, observer);


// 3. Get myObject's property by observerProxy

// Umm... I need abc!
const abc = observerProxy.abc;
console.log(abc); // console output -> 123

console.log(myObject.abc); // console output -> 123


// 4. Update
observerProxy.abc = 135; // console output -> 'Observer State Update Detected'

console.log(myObject.abc); // console output -> 135
                           // observerProxy change myObject's value.

observerProxy.def = 246; // console output -> nothing
                         // onStateUpdate not called. Becuse you didn't get 'def' before!

console.log(myObject.def); // console output -> 246
                           // observerProxy change myObject's value.

myObject.abc = 357; // console ouput -> nothing
                    // onStateUpdate not called. Because object proxy only watch when you change value by object proxy.


// 4.2 onStateUpdate Event by other observer proxy's changing

const observer2 = new Observer({
  onStateUpdate: () => {
    console.log('Observer 2 State Update Detected');
  },
});

const observerProxy2 = createObserverProxy(myObject, observer2);

observerProxy2.abc = 468; // console output -> 'Observer State Update Detected'
                          // observerProxy2 doesn't detect 'abc'. because we didn't get 'abc' of observerProxy2.

const abcByObserverProxy2 = observerProxy2.abc;

observerProxy2.abc = 579; // console output -> 'Observer State Update Detected'
                          // console output -> 'Observer 2 State Update Detected'

// Stop observerProxy2. Thank you observer proxy 2!!
observer2.stopObserving();


// 5. Stop wathcing
observer.stopObserving();

observerProxy.abc = 222; // console output -> nothing

console.log(myObject.abc); // console output -> 222

console.log(observerProxy.abc); // console output -> 222
console.log(observerProxy2.abc); // console output -> 222

Examples: React Global State

Here is example for React component. It can be use for Global State like Redux.

git clone https://github.com/skatpgusskat/ObserverProxy.git
cd ObserverProxy
npm run build
cd examples/react-global-state
npm run start

Reference

Observer

  • new Observer({ onStateUpdate })
    • onStateUpdate: <Function> / () => void
      • onStateUpdate will be called when change property by observer proxy.
  • stopObserving: <Function> / () => void
    • call this function to stop observing. onStateUpdate will never be called.