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

Allow OVERRIDE wrappers to chain. #28

Closed
ruipin opened this issue Apr 3, 2021 · 3 comments
Closed

Allow OVERRIDE wrappers to chain. #28

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

Comments

@ruipin
Copy link
Owner

ruipin commented Apr 3, 2021

The module "Better Rolls" has an interesting use case. It is, by default, a full override. As such, it uses "OVERRIDE". However, if the caller passes a specific parameter, it wishes to call the original method.

Because OVERRIDE by default doesn't provide the wrapped chain object, they are forced to use private APIs to access the _wrapped method instead. In addition to being unsupported, this will soon become impossible due to the work for #16.

In the original API design, OVERRIDE didn't provide the wrapped chain object on purpose. This was to avoid people using OVERRIDE just because they wanted to be the last module called, even when they weren't truly overriding a method. However, I failed to realise that there is a very rare use case where such a module might wish to call the original method.

An optional solution that does not compromise the API's design goals and maintains backward compatibility is to take an optional chain parameter that, if true, provides the wrapped chain object regardless of the wrapper type:

libWrapper.register("module-a", "Foo.prototype.bar", "OVERRIDE", {chain: true});

Optionally, the third parameter could be replaced by the dictionary (only when not a string, for backwards compatibility), e.g.:

libWrapper.register("module-a", "Foo.prototype.bar", {type: "OVERRIDE", chain: true});
@ruipin ruipin added the enhancement New feature or request label Apr 3, 2021
@ruipin ruipin closed this as completed in 9e6fc44 Apr 9, 2021
ruipin added a commit that referenced this issue Apr 9, 2021
@ruipin
Copy link
Owner Author

ruipin commented Apr 9, 2021

v1.3.6.0 implements the first syntax:

libWrapper.register("module-a", "Foo.prototype.bar", "OVERRIDE", {chain: true});

I chose the first syntax to avoid needing messy backwards compatibility code.

Same change also adds a test for this syntax. This API is not documented yet, pending Better Rolls using it, in case we need to change it. It will be considered public soon.

ruipin added a commit that referenced this issue Apr 9, 2021
@ruipin
Copy link
Owner Author

ruipin commented Apr 9, 2021

Reopening just to track the Better Rolls updates, and update the documentation.

@ruipin ruipin reopened this Apr 9, 2021
@ruipin
Copy link
Owner Author

ruipin commented Apr 11, 2021

This is now documented in v1.4.0.0, and Better Rolls has been updated.

Closing.

@ruipin ruipin closed this as completed Apr 11, 2021
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

1 participant