-
Notifications
You must be signed in to change notification settings - Fork 1.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
First shot: control plugins #3503
Conversation
Sorry for the delay here, this does deserve a response. I think what you've built is really cool and we should encourage people to build more things like this. Discussing (here or in #1392) about what plugins actually need is the first step. Documenting it in I think we should be clear on what things in iD we consider the interface, and then be diligent about following semantic versioning starting with the v2.0 release so that people can actually build plugins without breakage. The list of things is probably this, even though we don't have it written down anywhere:
It looks like your specific plugin needs a few things more on the iD side: A place attach to like a control (we should make an element identified like |
Here's how I'm seeing this:
As such, the plugin would not be allowed access to I'm not sure how an event would work in this case, and why it would be preferable to a plugin - which side would listen to the event? Conceptually I don't see how an event could do the job of either a function, as this currently works, or, potentially assigning to a iD member variable, in the style of node's require hooks. |
Ok, we are definitely coming at this from different points of view, but hopefully we can meet in the middle and spec out something useful. Here are my original thoughts, which I'm totally not sold on - just brainstorming.. iD would have a function myPlugin(context) {
var plugin = {
init: function() {
d3.select('#surface').call(addPluginThings);
context.map().on('drawn.myplugin', updatePluginStuff);
},
off: function() {
context.map().on('drawn.myplugin', null);
}
};
return plugin;
}; So clearly my thinking is influenced by how the rest of the code in iD works, and the "d3" way of doing things. But it sounds kind of similar to what you need for your plugin to work: a registration function, a context, and some html. To your other points:
We can't really prevent this, right?
Plugins would listen for events emitted by iD. Maybe vice versa too, because a plugin should be able to tell iD to redraw in response to something the user did on the plugin side (tricks like |
We can't prevent it at the code level, but drawing the line there would mean:
This is, notably, modeled after the Chrome extension API, Firefox API, modeled after our troubles with the TileMill plugin system, and also with React's no-reaching-up style system: components own a part of the DOM going down, but cannot affect their siblings or parents.
Sure, I agree with that... plugins can use the |
Closing; usable as an example but not going to merge this anytime soon. |
Okay, here goes: first shot at #1392
See id-upwards for an example plugin.
This establishes the 'hook' which JavaScript plugins can call by invoking a function, but it does not yet propose how you'd include other JavaScript on the page. This could be loading from npm, local sources, an iD-specific source, etc. Open to options.
Tweet-gif of example in action.
Observations: