sam-goodwin / punchcard

Type-safe AWS infrastructure.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use call-site to do some hacky/awesome simplifications?

sam-goodwin opened this issue · comments

commented

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
commented

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.

commented

Oh I see, you were referring to their implementation. I think it's brilliant :P.

commented

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 😄