-
Notifications
You must be signed in to change notification settings - Fork 196
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
Proposal: implicit scope for any function #287
Comments
Given our current design, I think we always assume any preflight code is running in some |
Yes, totally think we need a keyword ( |
Maybe we can use JS bind, it takes the "this" arg, but also others. So we can explicitly set the this param and add a scope param to all functions without changing their signatures |
Hi, This issue hasn't seen activity in 60 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. |
Keep please |
A possible use case for this would be for the SDK's let timer = cloud.Timer.fromCron("* * * * 6"); // implicit scope and id
timer.on_tick(inflight () => {
// ...
}); |
yes, I think the "factory" use case is strong. I was thinking that we need to give factories a more first-class status in the language. In a sense an initializer and a static factory method are sort of the same thing. |
Here's a random idea. What if whenever a function in a JSII/Wing library (instance method, static method, constructor, etc.) has its first two arguments named "scope" and "id", then the Wing compiler will automatically remove them from the signature and automatically fill in the scope and id during jsification? (I think this would need to be fleshed out because of edge cases, e.g. does this apply to both classes and resources? Are there any places in Wing where there isn't a valid implicit scope?) |
@Chriscbr yes I like this a lot. |
Hi, This issue hasn't seen activity in 60 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. |
I am wondering if the notion of implicit scopes, which we already have for resource initializers, can be extended to methods/functions as well.
So basically any method/functions/constructor that has a first argument called
scope
of typeConstruct
is called without explicitly specifying the scope, and can be customised with "in SCOPE" syntax of course.This comes up quite a lot, especially in static factory methods. It means that any code that runs in wing always have access to the parent scope that called it. Something that we struggled with in the CDK quite a lot.
The follow up question is what happens in Wing code. If I want to access
scope
from any method/function, does it mean the compiler will implicitly include an additional first parameter to the function signature. That's a breaking change...Perhaps all wing functions should always have an implicit scope as the first argument? Don't kill me!
The text was updated successfully, but these errors were encountered: