@resourge/react-fetch
Version:
[](LICENSE)
64 lines (62 loc) • 1.34 kB
JavaScript
/**
* react-fetch v1.41.3
*
* Copyright (c) resourge.
*
* This source code is licensed under the MIT license found in the
* LICENSE.md file in the root directory of this source tree.
*
* @license MIT
*/
const requestNotification = new Map();
const notifications = new Map();
const NotificationService = {
getRequest(id) {
return requestNotification.get(id);
},
startRequest(id, prom) {
requestNotification.set(id, prom);
},
finishRequest(id) {
requestNotification.delete(id);
},
subscribe(id, request) {
return notification => {
notifications.set(id, {
notification,
request
});
return () => {
notifications.delete(id);
};
};
},
notifyAll() {
if (requestNotification.size === 0) {
notifications.forEach(({
notification
}) => {
notification();
});
}
},
notifyById(id) {
const notification = notifications.get(id);
if (notification) {
notification.notification();
}
},
requestAllAgain(filter) {
if (notifications.size) {
notifications.forEach(({
request
}, key) => {
if (!filter || filter(key)) {
request();
}
});
}
}
};
export { NotificationService as default };
//# sourceMappingURL=NotificationService.js.map