JS message subscription and publishing to realize communication between components

Time:2021-4-12

Link:PubSubJS

Specific code implementation:

//Install first
yarn add pubsub-js

//Introduction 
import PubSub from 'pubsub-js'

//Release: 
PubSub.publish('zxc', 'hello world');

//Subscription: zxc name must be the same
token = PubSub.subscribe('zxc', (msg, data) => {
    console.log('msg ', msg);
    console.log('data ', data);
})

//Unsubscribe: 
PubSub.unsubscribe(token);

This work adoptsCC agreementReprint must indicate the author and the link of this article

Recommended Today

Review of SQL Sever basic command

catalogue preface Installation of virtual machine Commands and operations Basic command syntax Case sensitive SQL keyword and function name Column and Index Names alias Too long to see? Space Database connection Connection of SSMS Connection of command line Database operation establish delete constraint integrity constraint Common constraints NOT NULL UNIQUE PRIMARY KEY FOREIGN KEY DEFAULT […]