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

obj-ob

v1.0.2

Published

object observe

Downloads

2

Readme

Summary

ob是一个用于对象监听的轻量库。是从vue里面拆分出来的。由于感受到vue对对象监听的便利。想到对象监听,或许不止可以用来dom更新。还可以用于其它需要监控的场景。所以就尝试拆分出一个轻量的对象监听库。大小只有5.5k,gzip后3k。

Build Status Coverage Status

#Install

npm install obj-ob

Usage

监听对象:

var data = {
    t: 'bilaaa',
    ruby: {
        type: 'dinamic'
    }
};

var ob = new Ob(data);

var teardown = ob.watch('ruby.type', function(value,oldvalue){
    console.log(data.ruby.type);
    console.log(this.ruby.type);
    console.log(value,oldvalue);
});
ob.ruby.type = 'static';

teardown();//解除watch

//通过getter监听 watch的时候就执行getter函数 
ob.watch(function(){
    var t = data.t;
});
ob.t = "xfa";

//深度监听
ob.watch('ruby.type', function(value,oldvalue){
    console.log(this.ruby.type);
},{deep:true});
data.ruby.type = {
    name:'binaf'
};
data.ruby.type.name = "cafx";    

监听数组(不能直接监听数组,必须把数组包装在对象的一个属性上):

var arrayData = {
    grass: [],
    vegetable: []
};

var obArray = new Ob(arrayData);

obArray.watch('vegetable', function(){
    console.log(obArray.vegetable);
});
arrayData.vegetable.push('radish');
obArray.$set(arrayData.vegetable,0,'pumpkin');//arrayData.vegetable[0]='xaa';不触发更新事件
arrayData.vegetable.pop();

API

  • watch 添加监听函数

    para: {string|function} getter - 要监听的属性 可以通过函数获取 {function} cb - 当数据变更 执行的回调函数 {object} options - 配置项 deep-深度监听

    return: 解绑监听事件函数

  • $set 设置某个属性并促发更新事件,为弥补array[1]='xx'不触发更新事件而设计

    para:

    {object} obj - 要设置属性的对象 {string} key - 属性名称 {object} val - 属性值

    return: 属性值

    example:

      var setData = {
          animal:['human'],
          car:'bmw',
          jobs:{}
      }
      var obSet = new Ob(setData);
    
      obSet.$set(setData.jobs,'compony','tyb');
      obSet.$set(setData.animal, 0,'lion');
  • $del 删除某个属性并促发更新事件

    para:

    {object} obj - 要删除属性的对象 {string} key - 属性名称

    return: undefined

    example:

       obSet.$del(setData.jobs,'compony');