-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Document GL JS plugin architecture #1835
Comments
cc @mcwhittemore as he's looking at making |
Thats a hard one. The first idea that comes to mind is having mapbox-gl pass in a ref to itself via the While I like the idea above, what I've been doing is moving to peerDependencies as this doesn't take a change to mapbox-gl and lowers the bundle size by removing extra refs to mapbox-gl. |
I'd say let's do this:
@mcwhittemore what's the reason for making |
@mourner The idea with making |
They shouldn't do this.
Ideally, only CDN dependencies rely on a
|
That looks like too much hassle if the only problem is not wanting to rely on a global inside browserify/webpack. |
Yes, but then we need to make sure everything a plugin could rely on is exposed (either publicly or through a "protected" method/property). |
We get complaints about Mapbox.js relying on globals (mapbox/mapbox.js#726, mapbox/mapbox.js#1060, mapbox/mapbox.js#253, mapbox/mapbox.js#468). We should expect to get them about Mapbox GL JS too if we follow the same path. |
@jfirebaugh most of these are specifically about browserify not working, and we can make sure it works while still relying on a global. |
One problem we've run into with mapbox-gl-draw is that its easy for different version of babel to be being used. Because of this we're talking about bundling gl-draw before we ship it. My hold up with this is that is means that mapbox-gl-js will be bundled with it. |
Why do we need to bundle with mapbox-gl-js? You can bundle excluding it. |
Oh. Didn't know browserify did this. Thanks |
Relying on mapboxgl being a global doesn't work for webpack's async loading pattern: define([
'mapbox-gl',
'mapbox-gl-directions'
], function(mapboxgl,directions) {
// failure, never gets here, because mapbox-gl-directions is not guaranteed to initialize
// after mapbox-gl
}); Given the current situation, I think that:
|
@tmcw maybe we could recommend using a different webpack pattern instead of placing such restrictions on the plugin architecture? E.g. this: define(function(require) {
var mapboxgl = require('mapbox-gl');
var mapboxglDirections = require('mapbox-gl-directions');
// all clear
}); |
@mourner The above example is an example of webpack code splitting with define syntax; unfortunately it's not just another pattern, it has a much different runtime behavior - specifically that the |
@tmcw yes, but it can still be achieved if we explicitly require the plugin to be loaded after mapboxgl in application code instead of fully rearchitecting plugins, right? For the code splitting, it would look like this: require.ensure(["mapbox-gl", "mapbox-gl-directions"], function(require) {
var mapboxgl = require("mapbox-gl");
var mapboxglDirections = require('mapbox-gl-directions');
// all clear
}); |
I have been pushing things in an architectural direction that does not require sources or plugins to reference
If all three of these changes go through, we should be able to sidestep all the architecture problems discussed in this ticket. Does this direction make sense? Are there any other classes of plugins that should be considered? Is there anything I'm missing? |
So the approach would be to remove the |
I believe this is the case. The only edge case I can think of is a plugin that wants to create instances of controls, |
This implements part of #1835 - mapboxgl.Control: deleted - Controls need to implement addTo -> controls need to implement onAdd - Navigation & attribution controls are no longer evented
This implements part of #1835 - mapboxgl.Control: deleted - Controls need to implement addTo -> controls need to implement onAdd - Navigation & attribution controls are no longer evented
This implements part of #1835 - mapboxgl.Control: deleted - Controls need to implement addTo -> controls need to implement onAdd - Navigation & attribution controls are no longer evented - Fix container style, clean up naming and scoping of scale and geocoder control - Move position argument to addControl method - Move onRemove responsibility to controls - Don't pass a boolean to attributionControl. Fixes #3561
…apboxgl (#3497) * Remove Control class, add removeControl method. This implements part of #1835 - mapboxgl.Control: deleted - Controls need to implement addTo -> controls need to implement onAdd - Navigation & attribution controls are no longer evented - Fix container style, clean up naming and scoping of scale and geocoder control - Move position argument to addControl method - Move onRemove responsibility to controls - Don't pass a boolean to attributionControl. Fixes #3561 * Unsubscribe from events on onRemove. Fixes #3562 * Fix attributionControl tests * Avoid more usage of bind * Remove inherited super * Remove single-use constant * Document IControl * Update debug.html, improve documentation * Fix lint * Fix default, let documentation infer it * Fix addControl removeControl tests * Use bindAll instead of arrow functions * Don't use parameter default syntax * Remove duplicated doc * Add getDefaultPosition
As of #3497 the code and API documentation is in place! But I'd like to queue up a blog post explaining this new API once a new release is rolled. Also tracking updates for our controls: |
@lucaswoj geocoder is now finished. Which branch should |
@tmcw it should target |
I'm going to write up a blog about the plugin architecture and then we can close this issue. |
Blogged, done https://www.mapbox.com/blog/build-mapbox-gl-js-plugins/ |
Right now we have a bunch of competing approaches for how mapbox-gl-js plugins express their dependency on GL-JS.
Some plugins require-into mapbox-gl for utilities and thus actually rely on gl js internals.
Core questions
cc @jfirebaugh @tristen @mourner
The text was updated successfully, but these errors were encountered: