Created
January 10, 2021 02:02
-
-
Save acomagu/7a5252b3650f0f1fbf2131d0d67bfc81 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { Node, Construct } = require('constructs'); | |
class RootConstruct extends Construct { | |
onSynthesize() { | |
console.log(this.synthesize()); | |
} | |
synthesize() { | |
return Object.assign({}, | |
...Node.of(this).children.map(child => child.synthesize()), | |
); | |
} | |
} | |
const root = new RootConstruct(undefined, 'root'); | |
class AConstruct extends Construct { | |
synthesize() { | |
return { 'りんご': 'ごりら' }; | |
} | |
} | |
new AConstruct(root, 'a'); | |
class BConstruct extends Construct { | |
synthesize() { | |
return { 'らっぱ': 'ぱせり' }; | |
} | |
} | |
new BConstruct(root, 'b'); | |
Node.of(root).synthesize({}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { Node, Construct } = require('constructs'); | |
class HighLevelConstruct extends Construct { | |
synthesize() { | |
return Object.assign({}, | |
...Node.of(this).children.map(child => child.synthesize()), | |
); | |
} | |
} | |
class RootConstruct extends HighLevelConstruct { | |
onSynthesize() { | |
console.log(this.synthesize()); | |
} | |
} | |
const root = new RootConstruct(undefined, 'root'); | |
class AConstruct extends Construct { | |
synthesize() { | |
return { 'りんご': 'ごりら' }; | |
} | |
} | |
class BConstruct extends Construct { | |
synthesize() { | |
return { 'らっぱ': 'ぱせり' }; | |
} | |
} | |
class ABConstruct extends HighLevelConstruct { | |
constructor(host, id) { | |
super(host, id); | |
new AConstruct(this, 'a'); | |
new BConstruct(this, 'b'); | |
} | |
} | |
new ABConstruct(root, 'ab'); | |
Node.of(root).synthesize({}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment