Use call-site to do some hacky/awesome simplifications?
sam-goodwin opened this issue · comments
Could we use https://www.npmjs.com/package/callsite to do some tricky stuff like auto-generating CDK construct IDs from the assign variable name?
const myConstruct = new Construct(stack, 'myConstruct');
// simplify to
const myConstruct = new Construct(stack)
Could even store the current "scope" globally to remove the boilerplate entirely:
const stack = new cdk.Stack(app, 'my-stack'); // pushes scope onto a global stack
const myConstruct = new Construct(); // no boiler-plate
IMHO, that's abusing the language features 😆
https://github.com/tj/callsite/blob/4882cd047cbc234df1d07cfe26f618ecb1a45e5e/index.js#L2-L10
Oh, absolutely! That's why it's so enticing, haha! Maybe not this particular use-case, but it might be useful for grabbing things like __dirname
from the caller's context.
Oh I see, you were referring to their implementation. I think it's brilliant :P.
Might break in webpack, though.
yeah, rewriting the global error class static method then rewriting it back, reminds me of DOJO/mootools era, long time ago 😄