List = const {}
// the name of the event and the event function put into the event pool
function $ ON (name, FUNC) {
IF (FUNC name ||!!) return ;
IF ! ( Object.keys (List) .includes (name )) {
List [name] = FUNC;
}
}
// find the name of the search executed according to the event pool event
function $ EMIT (name, ... Arg) {
IF (name)! return ;
IF (Object.keys (List). Includes (name)) {
List [name] (... Arg)
}
}
// execution is not complete and needs to be cleared after the event
function $ OFF (name) {
IF (! name)return;
if(Object.keys(list).includes(name)){
list[name]=null;
delete list[name]
}
}
export {
$on,
$emit,
$off,
}
Event subscription package to pass the non-parent-child value component (React)
Guess you like
Origin www.cnblogs.com/ayujun/p/12078334.html
Ranking