-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor moving of modal elements to solve multiple issues #2238
Conversation
libs/designsystem/src/lib/components/modal/modal-wrapper/modal-elements-advertiser.service.ts
Outdated
Show resolved
Hide resolved
libs/designsystem/src/lib/components/modal/modal-wrapper/modal-wrapper.component.ts
Outdated
Show resolved
Hide resolved
We can just inject the modalWrapperComponent as advertiser directly!
libs/designsystem/src/lib/components/modal/modal-wrapper/modal-wrapper.component.ts
Outdated
Show resolved
Hide resolved
...ignsystem/src/lib/components/modal/modal-wrapper/modal-wrapper.component.integration.spec.ts
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice result - consider for next show-and-tell 🥇
this.removeChild(new ElementRef(kirbyPageTitleElement)); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The modal-wrapper class has grown large (monolithic) - consider moving the handler code to a separate handler delegate class solely accessible by the modal-wrapper.
this.modalElementsAdvertiser.removeModalElement(this.modalElementType, this.elementRef); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice interface which provides for a straight-forward and elegant distribution of responsibilities 👍
...ignsystem/src/lib/components/modal/modal-wrapper/modal-wrapper.component.integration.spec.ts
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really Nice 👍
Which issue does this PR close?
This PR closes #2096
This PR closes #2116
This PR closes #1517
What is the new behavior?
I'm messing around with refactoring the modal to make it easier to grasp and solve a few bugs.
Before
A mutation observer was used for watching for changes in the embedded component. If a
kirby-page-progress
,kirby-page-title
orkirby-modal-footer
element was added, it would be moved to its desired spot.The implementation of this was quite complex in my opinion and hard to grasp (And i have a suspiscion that i'm not the only one who believes this 👀)
Furthermore the bug from #2116 stems from the mutation observer not reacting when one of the aforementioned elements are added when they are wrapped in a component defined by the consumer.
To solve this we could either continue making it more complex (see the first suggested solution on #2116).. Or rethink how the moving of embedded components are done.
Resulting in ...
After
A new
ModalElementsAdvertiser
!What we really want to know is: "which element is added/removed when?" such that we can move them out of the modal content and into the header/footer/where ever it belongs.
Instead of having the
ModalWrapperComponent
watch for changes, i've switched it around such that the embedded components announce themselves.Each element that the modal should move registers itself using the methodModalElementsAdvertiser.registerElement
onngAfterViewInit
.This will in turn trigger anModalElementsAdvertiser.[elementType].added$
observable, which theModalWrapperComponent
is subscribed to. TheModalWrapperComponent
can then react accordingly.It's more or less a simple pub/sub pattern.Symmetrically there also exists aremoved$
observable for whenOnDestroy
is triggered for a component.It's a bit more verbose but i think it is easier to grasp ones head around as it is very clear what is executed when and has also made it possible to bundle relevant code some more.Edit: new approach!
We inject the
ModalWrapperComponent
as aModalElementsAdvertiser
into the child elements that should be moved. They can then call amodalElementsAdvertiser.add[ElementName]
andmodalElementsAdvertiser.remove[elementName]
method to register themselves in the wrapper component.E.g. when a
kirby-page-title
element is added it callsmodalElementsAdvertiser.addTitle
on ngAfterviewInit andmodalElementsAdvertiser.removeTitle
on ngDestroy.Does this PR introduce a breaking change?
Are there any additional context?
There's some remaining todos...
TODO:
Checklist:
The following tasks should be carried out in sequence in order to follow the process of contributing correctly.
Reminders
Review
When the pull request has been approved it will be automatically merged to
stable
via automerge.