Provide public API for getting event listeners
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 12.4k
- Forks
- 2.4k
- PR merge metrics
- No merged PRs in 30d
Description
## Motivation
The API provides `on`, `once`, `off` for listeners, but no way of actually fetching them once they've been instantiated.
In our application code we add custom event listeners to the map, for example:
```javascript
this.map.on('levelChange', ({ level }: { level: number }) => {
});
```
Now without keeping track of this listener in some application state (which would be nice to avoid as we try and keep all map related state within the map object where possible), there doesn't seem to be a clean way to get hold of the listener using the public API. At the moment we work around that like this:
```javascript
this.map._listeners['levelChange']
```
To turn it on (and off).
## Design Alternatives
It would be great to be able to have a public API that allows for this.
## Design
The map would provide a method which allows the developer to get all listeners or one by name.
### Implementation
```
map.getListener('levelChange')
```
or/and:
```
map.getListeners()
```
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 with the public map event API (`on`, `once`, `off`) and the current `_listeners` access described in the issue. Clarify whether the API returns one listener or all listeners, then add the requested public access with tests demonstrating retrieval by event name and without a name.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, frontend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100