blant-notifier

notifier

Usage no npm install needed!

<script type="module">
  import blantNotifier from 'https://cdn.skypack.dev/blant-notifier';
</script>

README

通知管理器

BLANT

通知管理器

安装

npm install --save blant-notify

正常使用

import notifier from 'blant-notifier';
var blant={};

// 方法1
new notifier(blant,true); // 参数说明,绑定到的对象,是否开启日志
// 方法2
var no1=new notifier();
var no2=new notifier(null,true);
//no1.emit("pagea", {"blant":"good"});
//no2.emit("pagea", {"blant":"good"});

// 注册
blant.listen("pagea", (data)=>{
    console.log(data);
}, this);

// 使用
blant.emit("pagea", {"blant":"good"});

// 移除
blant.remove('pagea',this);

// 清空
blant.clear();

在 wepy 中使用

// 在 app.wpy 中
import notifier from 'blant-notifier';

constructor() {
    super()
    this.use('requestfix')
    this.use('promisify');
    // 导入组件   参数说明:组件对象,绑定到的对象,是否开启日志
    this.use(notifier, wepy.notifier = {}, true);
}

// 在页面A中
export default class pagea extends wepy.page {
    onLoad() {
        // 移除
        wepy.notifier.remove('pagea',this);
        // 清空
        wepy.notifier.clear();
        // 监听
        wepy.notifier.listen("pagea", (data)=>{
            console.log(data);
        }, this);
    }
}

// 在页面B中
export default class pageb extends wepy.page {
    onLoad() {
        wepy.notifier.emit("pagea", {"blant":"good"});
    }
}

License

MIT.