Ability to add listeners directly to objects like Modals/Collapse/etc
Open
Nobody has claimed this yet.
feature
js
v5
- Dominant language
- MDX
- Stars
- 175k
- Forks
- 78.6k
- Avg merge
- 7h 19m
- Merged PRs (30d)
- 35
Description
How about a public method to add listener(s) to an object, something like:
class Modal {
//...
on(event, callback) {
this._element.addEventListener(`${event}${EVENT_KEY}`, callback);
return this;
}
//...
}
This will allows us to do something like:
var myModal = new bootstrap.Modal(document.getElementById('myModal'));
myModal
.on('shown', function (e) {
// do something...
})
.on('hidden', function (e) {
// do something...
});
Instead of:
var myModal = new bootstrap.Modal(document.getElementById('myModal'));
myModal._element.addEventListener('shown.bs.modal', function (e) {
// do something...
});
myModal._element.addEventListener('hidden.bs.modal', function (e) {
// do something...
});
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the Modal and Collapse component implementations and how their element events are currently exposed through _element. Compare the requested chained on(event, callback) API with the existing event naming conventions and determine which components would need consistent support. Done means the scope and public API are defined and covered by appropriate component behavior tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100