Skip to content
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

Add before/after properties to allow modules to specify default prioritization #27

Open
ruipin opened this issue Apr 3, 2021 · 2 comments
Labels
enhancement New feature or request

Comments

@ruipin
Copy link
Owner

ruipin commented Apr 3, 2021

As it stands, modules are unable to signal a desired prioritization other than "WRAPPER", "MIXED", and "OVERRIDE".

A suggestion that has come my way is to add optional before and after constraints that will be used to decide on default prioritization. These would be lists of module IDs (or a single module ID), which would run by default before/after the given wrapper.

Example:

libWrapper.register("module-a", "Foo.prototype.bar", "MIXED", {before: "module-b", after: ["module-c", "module-d"]});

Optionally, we could have the dictionary be the third parameter (when it is not a string, for backward compatibility), and have the wrapper type be one of the dictionary values:

libWrapper.register("module-a", "Foo.prototype.bar", {type: "MIXED", before: "module-b", after: ["module-c", "module-d"]});

The user could then be warned if these constraints conflict (including when it's because the users themselves changed prioritization).

@ruipin ruipin added the enhancement New feature or request label Apr 3, 2021
@caewok
Copy link

caewok commented May 26, 2021

Adding my support for this suggestion. I have a pretty good use case in mind: I am working on a module that would act as a library for certain distance measurements. The trick is, though, who goes first can matter quite a bit when figuring out distance in a quasi-cooperative manner. Instead of trying to track this through some sort of Array, it would be simpler and cleaner if modules could just flag order in some manner. If that could be done, each module could simply wrap the distance function and add on their calculations in their specified turn. Everyone who does not participate would be relegated to last (or better yet, not at all if a given flag is set).

@ruipin
Copy link
Owner Author

ruipin commented May 26, 2021

For such a specific use-case, something handled directly by your library would probably be better. There's too many variables to rely solely on libWrapper, IMO.

I'd suggest you wrap the methods youself, and provide other modules with an API to register their own roll handlers that your wrapper then calls.

It doesn't mean this approach you suggest wouldn't work, but I think it wouldn't be very flexible IMO. Also, this issue isn't high priority, there's a few other things I think are more important, such as #33

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants