码迷,mamicode.com
首页 > 其他好文 > 详细

订阅发布机制

时间:2021-06-17 16:36:50      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:data   ken   for   bsp   use   code   rgba   with   require   

订阅发布机制

github地址: https://github.com/mroderick/PubSubJS


import PubSub from ‘pubsub-js‘ // or when using CommonJS const PubSub = require(‘pubsub-js‘); // create a function to subscribe to topics var mySubscriber = function (msg, data) { console.log( msg, data ); }; // add the function to the list of subscribers for a particular topic // we‘re keeping the returned token, in order to be able to unsubscribe // from the topic later on var token = PubSub.subscribe(‘MY TOPIC‘, mySubscriber); // publish a topic asynchronously PubSub.publish(‘MY TOPIC‘, ‘hello world!‘); // publish a topic synchronously, which is faster in some environments, // but will get confusing when one topic triggers new topics in the // same execution chain // USE WITH CAUTION, HERE BE DRAGONS!!! PubSub.publishSync(‘MY TOPIC‘, ‘hello world!‘); // unsubscribe mySubscriber from ALL topics PubSub.unsubscribe(mySubscriber);

 

订阅发布机制

标签:data   ken   for   bsp   use   code   rgba   with   require   

原文地址:https://www.cnblogs.com/zhijianzhizhen/p/14852630.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!