Download js/ui_state/lib/pubsub.js from flowers-team/Interactive_DeepRL_Demo: direct link, hf CLI and curl.
- Browser
- Download file 913 Bytes
-
https://huggingface.co/spaces/flowers-team/Interactive_DeepRL_Demo/resolve/main/js/ui_state/lib/pubsub.js
- Command line
-
hf download hf://spaces/flowers-team/Interactive_DeepRL_Demo/js/ui_state/lib/pubsub.js
-
curl -L -o pubsub.js https://huggingface.co/spaces/flowers-team/Interactive_DeepRL_Demo/resolve/main/js/ui_state/lib/pubsub.js
913 Bytes
| /** | |
| * @classdesc UI state manager. | |
| */ | |
| export default class PubSub { | |
| /** | |
| * @constructor | |
| */ | |
| constructor() { | |
| this.events = {}; | |
| } | |
| /** | |
| * Adds the given callback function to the given event and adds the event to the handled events if it is not in it yet. | |
| * @param event {string} | |
| * @param callback {function} | |
| * @return {number} | |
| */ | |
| subscribe(event, callback) { | |
| if (!this.events.hasOwnProperty(event)) { | |
| this.events[event] = []; | |
| } | |
| return this.events[event].push(callback); | |
| } | |
| /** | |
| * Triggers all the callback functions for the given event. | |
| * @param event {string} | |
| * @param data | |
| * @return {*[]|*} | |
| */ | |
| publish(event, data = {}) { | |
| if (!this.events.hasOwnProperty(event)) { | |
| return []; | |
| } | |
| return this.events[event].map(callback => callback(data)); | |
| } | |
| } |