Skip to content

Commit

Permalink
remove eventemitter3
Browse files Browse the repository at this point in the history
  • Loading branch information
tsubik committed May 24, 2024
1 parent 62af364 commit 5ffe8ce
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
20 changes: 15 additions & 5 deletions components/ui/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,21 @@ import { EE } from 'services/modal';

class Modal extends React.Component {

onToogleModal = (e) => {
const { toggleModal } = this.props;
if (toggleModal) toggleModal(e.detail.opened, e.detail.opts);
}

onSetModalOptions = (e) => {
const { setModalOptions } = this.props;
if (setModalOptions) setModalOptions(e.detail.opts);
}

componentDidMount() {
const { toggleModal, setModalOptions } = this.props;
const { setModalOptions } = this.props;

EE.on('toggleModal', toggleModal);
EE.on('setModalOptions', setModalOptions);
EE.addEventListener('toggleModal', this.onToogleModal);
EE.addEventListener('setModalOptions', this.onSetModalOptions);

this.el.addEventListener('transitionend', () => {
if (!this.props.modal.opened) {
Expand All @@ -41,8 +51,8 @@ class Modal extends React.Component {
}

componentWillUnmount() {
EE.removeListener('toggleModal');
EE.removeListener('setModalOptions');
EE.removeEventListener('toggleModal', this.onToogleModal);
EE.removeEventListener('setModalOptions', this.onSetModalOptions);
}

getContent() {
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"dayjs": "^1.11.11",
"deck.gl": "7.3.6",
"dotenv": "^16.4.5",
"eventemitter3": "^5.0.1",
"express": "^4.19.2",
"foundation-sites": "^6.8.1",
"fuse.js": "^7.0.0",
Expand Down
8 changes: 3 additions & 5 deletions services/modal.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import EventEmitter from 'eventemitter3';

const emitter = new EventEmitter();
const emitter = new EventTarget();

const actions = {};
actions.toggleModal = (opened, opts = {}) => emitter.emit('toggleModal', opened, opts);
actions.setModalOptions = (opts = {}) => emitter.emit('setModalOptions', opts);
actions.toggleModal = (opened, opts = {}) => emitter.dispatchEvent(new CustomEvent('toggleModal', { detail: { opened, opts }}));
actions.setModalOptions = (opts = {}) => emitter.dispatchEvent(new CustomEvent('setModalOptions', { detail: { opts } }));

export const EE = emitter;
export default actions;
5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2399,11 +2399,6 @@ eventemitter3@^4.0.1:
resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-4.0.7.tgz#2de9b68f6528d5644ef5c59526a1b4a07306169f"
integrity sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw==

eventemitter3@^5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-5.0.1.tgz#53f5ffd0a492ac800721bb42c66b841de96423c4"
integrity sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA==

express@^4.19.2:
version "4.19.2"
resolved "https://registry.yarnpkg.com/express/-/express-4.19.2.tgz#e25437827a3aa7f2a827bc8171bbbb664a356465"
Expand Down

0 comments on commit 5ffe8ce

Please sign in to comment.