observer-watch

0.0.1 • Public • Published

Observer

npm install observer-watch
import Observer from './src/Observer.js';
 
let oberver = new Observer({
    description:{
        name:"Ysb",
        job:"Front end developer",
        favourites:['eating','reading']
    }
})
//单个属性变化监听
observer.addWather(['name'],name=>{
    console.log("name",name)
})
//多个属性变化监听
observer.addWather(['name','job'],(name,job)=>{
    console.log("name,job",name,job)
}
//根据条件触发监听函数
observer.addWather(['favourites'],favourites=>{
    console.log("favourites",favourites)
},function(newObserver,oldObserver,path){
    return newObserver.length > 3
});
//更新监听的对象
observer.update({
    name:"YSB",
    job:"Front end developer",
    favourites:['loving','eating','reading']
});
observer.update({
    name:"YSB---",
    job:"jser",
    favourites:['loving','eating']
});
observer.update({
    name:"YSB---",
    job:"jser",
    favourites:['loving','eating','woking','swimming']
});

Readme

Keywords

Package Sidebar

Install

npm i observer-watch

Weekly Downloads

0

Version

0.0.1

License

ISC

Unpacked Size

42.5 kB

Total Files

5

Last publish

Collaborators

  • yangshangbo