primevue-mirror/components/lib/themes/service/index.js

41 lines
871 B
JavaScript
Raw Normal View History

2024-03-05 09:22:33 +00:00
function createService() {
const allHandlers = new Map();
return {
on(type, handler) {
let handlers = allHandlers.get(type);
if (!handlers) handlers = [handler];
else handlers.push(handler);
allHandlers.set(type, handlers);
return this;
2024-03-05 09:22:33 +00:00
},
off(type, handler) {
let handlers = allHandlers.get(type);
if (handlers) {
handlers.splice(handlers.indexOf(handler) >>> 0, 1);
}
return this;
2024-03-05 09:22:33 +00:00
},
emit(type, evt) {
let handlers = allHandlers.get(type);
if (handlers) {
handlers.slice().map((handler) => {
handler(evt);
});
}
}
};
}
const ThemeService = createService();
export default ThemeService;