You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.8 KiB

function EV(eventName, arg, isExclusive) {
7 years ago
if (Object.values(EV.enum).indexOf(eventName) === -1) {
return console.warn('Unregistered event', eventName, 'registered events:', EV.enum);
7 years ago
}
7 years ago
EV.callbacks = EV.callbacks || {}; // static variable
EV.callbacks[eventName] = EV.callbacks[eventName] || [];
7 years ago
7 years ago
if (typeof arg !== 'function') {
// then its an argument
console.log('got event', eventName, '...');
7 years ago
for (let cc of EV.callbacks[eventName]) {
7 years ago
console.log('dispatching event', eventName);
cc(arg);
7 years ago
}
7 years ago
} else {
// its a callback. subscribe it to event
console.log('someone subscribed to', eventName);
if (isExclusive) {
// if it'a an excluside subscribe - other subscribers should be terminated
console.log('exclusive subscribe');
EV.callbacks[eventName] = [];
}
7 years ago
EV.callbacks[eventName].push(arg);
7 years ago
}
}
EV.enum = {
// emitted when local wallet created or deleted, so one must redraw wallets carousel
7 years ago
WALLETS_COUNT_CHANGED: 'WALLETS_COUNT_CHANGED',
// emitted when local wallet (usually current wallet) has changed number of transactions
// so one must redraw main screen transactions list and WalletTransactions screen tx list
7 years ago
TRANSACTIONS_COUNT_CHANGED: 'TRANSACTIONS_COUNT_CHANGED',
// emitted when we know for sure that on remote server tx list
// changed (usually for current wallet)
REMOTE_TRANSACTIONS_COUNT_CHANGED: 'REMOTE_TRANSACTIONS_COUNT_CHANGED',
6 years ago
// emitted when QR scanner scanned address that should be used in CREATE TRANSACTION screen
// thus, previous screen (CREATE TRANSACTION screen) will update it's input content
CREATE_TRANSACTION_NEW_DESTINATION_ADDRESS: 'CREATE_TRANSACTION_NEW_DESTINATION_ADDRESS',
// RECEIVE_ADDRESS_CHANGED: 'RECEIVE_ADDRESS_CHANGED',
7 years ago
};
7 years ago
7 years ago
module.exports = EV;