-
Notifications
You must be signed in to change notification settings - Fork 103
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
Private protected API. #199
Comments
@BauchBeinePoe hello there. I'm actively working on stampit v3 which is going to be stamp-specification compatible. And your idea would perfectly fit the specification IMO. The name should be The initializer signature would be like that: const Stamp = compose({
initializers: [(options, { stamp, instance, args, protected }) => {
protected.log('Some log method');
}]
}); In stampit v3 the API would be this: const Stamp = stampit.init((options, { stamp, instance, args, protected }) => {
protected.log('Some log method');
}); Let's move this conversation here: stampit-org/stamp-specification#84 |
Thank you for the idea @BauchBeinePoe. As you know the community voted to not implement it. Although, a workaround using stampit v2 could be this: var log = stampit.init(({ instance }) => {
instance.log = console.log; // First, temporary assign the private state to the instance.
});
var a = stamp.compose(log).init(({ instance }) => {
const log = instance.log;
log('Some log method');
delete instance.log; // Later, delete private state form the instance.
}); With the future stampit v3 (or the existing module stamp-specification) it could be implemented simpler: var log = compose({initializers: [(options) => {
options.log = options.log || console.log;
}]});
var a = compose({initializers: [(options) => {
options.log('Some log method');
}]}); Although, stamps developed with stampit v2 and v3 will (most likely) be incompatible. :( |
Protected properties are now implemented as a separate stamp - https://www.npmjs.com/package/@stamp/privatize But please note, the |
Hey,
I am missing a private protected API and I would want to start a discussion on that. Or maybe there is already one and I've missed it.
For example: If I want to provide objects with a log method, I would do it like so:
When I create new stamps based on this log stamp these objects could simply call the log method. Simple as that, but the log method is also exposed in the public API where I do not need it.
As a suggestion I would rather have it this way:
This way the private object is not exposed in the public API but can be used by composed stamps.
What do you think?
The text was updated successfully, but these errors were encountered: