-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from LIN3S/feature/modal-initialized-event
The component Modal (Vanilla) now dispatches a ModalInitializedEvent after it's initialization.
- Loading branch information
Showing
7 changed files
with
94 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* This file is part of the Euskaltel project. | ||
* | ||
* Copyright (c) 2017 LIN3S <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @author Mikel Tuesta <[email protected]> | ||
*/ | ||
|
||
import {Event} from 'lin3s-event-bus'; | ||
|
||
class ModalInitializedEvent extends Event { | ||
|
||
static NAME = 'MODAL_INITIALIZED'; | ||
|
||
constructor({domNode, open, close} = {}) { | ||
super(ModalInitializedEvent.NAME); | ||
|
||
this.domNode = domNode; | ||
this.open = open; | ||
this.close = close; | ||
} | ||
} | ||
|
||
export default ModalInitializedEvent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* This file is part of the Euskaltel project. | ||
* | ||
* Copyright (c) 2017 LIN3S <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @author Mikel Tuesta <[email protected]> | ||
*/ | ||
|
||
import {EventSubscriber} from 'lin3s-event-bus'; | ||
import ModalInitializedEvent from './ModalInitializedEvent'; | ||
|
||
class ModalInitializedEventSubscriber extends EventSubscriber { | ||
constructor(modalId, aCallback, aPriority) { | ||
super(aCallback, aPriority); | ||
|
||
this.modalId = modalId; | ||
} | ||
|
||
isSubscribedTo(anEvent) { | ||
const event = new ModalInitializedEvent(); | ||
|
||
return anEvent.getName() === event.getName() && anEvent.domNode.id === this.modalId; | ||
} | ||
} | ||
|
||
export default ModalInitializedEventSubscriber; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,10 +10,22 @@ | |
* @author Ander Rodriguez <[email protected]> | ||
*/ | ||
|
||
import {Priority, LifeTimeEventPublisher} from 'lin3s-event-bus'; | ||
import {Priority, OneTimeEventPublisher, LifeTimeEventPublisher} from 'lin3s-event-bus'; | ||
import ModalStateChangedEventSubscriber from './ModalStateChangedEventSubscriber'; | ||
import ModalInitializedEventSubscriber from './ModalInitializedEventSubscriber'; | ||
|
||
const | ||
onInitialized = (modalId, onModalInitializedCallback, priority) => { | ||
const modalInitializedEventSubscriber = new ModalInitializedEventSubscriber( | ||
modalId, | ||
onModalInitializedCallback, | ||
new Priority(priority) | ||
); | ||
|
||
OneTimeEventPublisher.subscribe(modalInitializedEventSubscriber); | ||
|
||
return modalInitializedEventSubscriber; | ||
}, | ||
onStateChanged = (onModalStateChangedCallback, priority) => { | ||
const modalStateChangedEventSubscriber = new ModalStateChangedEventSubscriber( | ||
onModalStateChangedCallback, | ||
|
@@ -26,5 +38,6 @@ const | |
}; | ||
|
||
export { | ||
onStateChanged | ||
onStateChanged, | ||
onInitialized, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,8 +9,9 @@ | |
* @author Mikel Tuesta <[email protected]> | ||
*/ | ||
|
||
import {LifeTimeEventPublisher} from 'lin3s-event-bus'; | ||
import {OneTimeEventPublisher, LifeTimeEventPublisher} from 'lin3s-event-bus'; | ||
import ModalStateChangedEvent from './../../../../event-bus/Modal/ModalStateChangedEvent'; | ||
import ModalInitializedEvent from './../../../../event-bus/Modal/ModalInitializedEvent'; | ||
|
||
class Modal { | ||
|
||
|
@@ -37,6 +38,7 @@ class Modal { | |
this.onKeyDown = this.onKeyDown.bind(this); | ||
|
||
this.bindListeners(); | ||
this.publishModalInitializedEvent(); | ||
} | ||
|
||
bindListeners() { | ||
|
@@ -84,6 +86,14 @@ class Modal { | |
state: this.state | ||
})); | ||
} | ||
|
||
publishModalInitializedEvent() { | ||
OneTimeEventPublisher.publish(new ModalInitializedEvent({ | ||
open: this.open.bind(this), | ||
close: this.close.bind(this), | ||
domNode: this.domNode, | ||
})); | ||
} | ||
} | ||
|
||
export default Modal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters