mapbox / mapbox/mapbox-gl-js

Eliminate Source#on{Add,Remove}(map)

Open
#3,350 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

refactoring :building_construction:
Dominant language
TypeScript
Stars
12.4k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

The main use of `on{Add,Remove}(map)` in source subclasses is to store a reference to the map for later use. This introduces both statefulness (certain source operations work only after `onAdd` has been called) and tight coupling between a source and the map.

Instead, sources should be passed the things to which they need access as parameters to the relevant methods.

Ref https://github.com/mapbox/mapbox-gl-js/pull/3255#discussion_r80765491

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the Source subclasses and all onAdd/onRemove(map) call sites, then read the linked pull request discussion for the intended boundaries. Done means sources no longer retain map references through these hooks and the relevant source operations receive their dependencies as method parameters, with existing behavior preserved.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.