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

@xpf0000/objectobserver

v1.0.17

Published

JS Object Observer, Build on the basis of ES6 proxy, use like vue's watch

Downloads

19

Readme

Latest Version on NPM Software License npm

JS Object Observer, Build on the basis of ES6 proxy, use like vue's watch

Support circular reference

Can set watch depth and silence watch

Table of Contents

Install and basic usage

$ npm install --save @xpf0000/objectobserver
import { Watcher, watch, unWatch } from "@xpf0000/objectobserver"
let obj = { a: 0, b: { b0: 1 } }
obj = Watcher(obj)
let config = {
    '*': {
        handler(newVal, oldVal) {}
     },
     a: function (newVal, oldVal) {},
     b: {
        handler(newVal, oldVal) {},
        deep: true
     },
     'b.b0': function(newVal, oldVal) {}
}
watch(obj, config)
obj.a = 1
obj.c = 0
obj.b.b0 = 2

let arr = Watcher([])
let arr1 = Watcher(arr)
let arr2 = Watcher(arr)
let config1 = {
    '*': {
        handler(newVal, oldVal) {}
    },
}
let config2 = {
    '*': {
        handler(newVal, oldVal) {}
    },
}
watch(arr1, config1)
watch(arr2, config2)
arr.push(0)
arr1.push(1)
arr2.push(2)
unWatch(arr2, config2)

Watcher options

depth

set watch depth, default whole object

import {Watcher, watch, unWatch } from "@xpf0000/objectobserver"
let obj = { a: 0, b: { b0: 1 } }
obj = Watcher(obj, 1)
let config = {
    '*': {
        handler(newVal, oldVal) {}
    },
}
watch(obj, config)
obj.b.b0 = 2 //won't trigger
obj.a = 1 // trigger
obj.c = 0 // trigger

Watch item options

deep

Only observe this level or observe this level and subordinate level

import { Watcher, watch, unWatch } from "@xpf0000/objectobserver"
let obj = { a: 0, b: { b0: 1 } }
obj = Watcher(obj)
let config = {
    'b': {
        handler(newVal, oldVal) {},
        deep: false
    },
}
watch(obj, config)
obj.b = { c: 0 } // trigger
obj.b.c = 1 //won't trigger if deep is false

Methods

watch

import { Watcher, watch, unWatch } from "@xpf0000/objectobserver"
let obj = { a: 0, b: { b0: 1 } }
obj = Watcher(obj)
watch(obj, {...})
watch(obj, {...}, this) // set handler's run env
let watcher = watch(obj, {...})
watch.unWatch() // only clean this watcher

unWatch

import { Watcher, watch, unWatch } from "@xpf0000/objectobserver"
let obj = { a: 0, b: { b0: 1 } }
obj = Watcher(obj)
unWatch(obj, {...}) // only clean this watcher
unWatch(obj) // clean all watcher

Contributing

Any contribution to the code or any part of the documentation and any idea and/or suggestion are very welcome.

# serve with hot reload at localhost:8080
npm run serve

# run test
npm run test

# distribution build-bundle
npm run build

License

The MIT License (MIT). Please see License File for more information.