-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[2.0] Add a way to resolve addon ordering dependencies #7797
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
Comments
This idea is open for discussion - other technical approaches (for example, alternative ideas on syntax) are welcome! |
I think this would be nice to have, however I think one of the challenges would be in the dependency graph building, specifically in the case of a cyclic dependency. It is probably rare and we can possibly just throw an error in that case perhaps. |
It might be worth to try using the internal modules, which are all written with the addon syntax and sufficiently complex, to figure out the technical details. |
Makes sense! At work we do something similar to manage our z indices across frontend components to avoid juggling lots of arbitrary numbers, and in the case of a circular dependency, we log an error mentioning what the cycle is, and then omit adding the edge that would create the cycle and continue on. I'm not sure whether or not treating it more like a warning or a full error is better, I could see either potentially being ok. |
After thinking a bit, I think in terms of API design, I would like it to be defined in the addon callback function instead of The extra option object that can be passed to |
Increasing access
Sometimes addons build off of other addons, or want to be compatible with other addons. Currently, every addon lifecycle stage will run addons' callbacks in the order that the callbacks were registered. This means that users might run into problems if they accidentally include the script tags for those addons in the wrong order. If addons have a way of describing their dependencies as they are registered, then there are less potential gotchas for users of those addons.
Most appropriate sub-area of p5.js?
Feature request details
An example of a situation where this might occur: addon A creates a new object in
presetup
, and addon B wants to do something with that object also inpresetup
. Addon B would need a way to always have itspresetup
run after addon A'spresetup
.To make this work, ideally, addons have a way to name themselves so that other developers can describe dependencies relative to them. For example, imagine you have a physics engine that updates the positions of all objects
predraw
. It could register itself with a name:Then, let's say you make an addon that adds some extra gravity forces to the physics system. You also want it to run before the user's code in
predraw
, but it needs to run before the physics engine applies the updates. You could then register this ordering dependency withbefore
orafter
:So the new API for
registerAddon
would be something like:Internally, when initializing p5, we would then:
This
before
/after
syntax isn't the only approach to getting an ordering, but I like that you only need to know the name of the other addon. I'm open to other ideas though!The text was updated successfully, but these errors were encountered: