teleport-code-generators
teleport-code-generators copied to clipboard
Async generators can be made sync?
Initially we developed the component generators as async functions, but since the flow is sync, it might not be needed after all.
A resolution would be great before the official release
Some parts can, but there's one or two packages that are async. I think we are using the babel generator with a async callback that gets called when babel is done with it.
I'm certain we CAN make them sync as even the babel generator has a sync mode.
I'm also certain we SHOULD NOT make them sync as sync scales less well, and my assumption is that we might want to multithread the architecture to allow multiple components to be generated concurrently via worker threads / service workers.
@vladnicula what about having both like in the node API?
This would allow to transform this:
const teleport = require('@teleporthq/teleport-code-generators')
const reactGenerator = teleport.createReactComponentGenerator()
const uidl = {
name: 'DemoComponent',
content: {
type: 'text',
children: ['Teleport World!']
}
}
reactGenerator
.generateComponent(uidl)
.then(({ dependencies, code }) => {
console.log(dependencies)
console.log(code)
})
.catch(err => {
console.log(err)
})
into this
const teleport = require('@teleporthq/teleport-code-generators')
const reactGenerator = teleport.createReactComponentGenerator()
const uidl = {
name: 'DemoComponent',
content: {
type: 'text',
children: ['Teleport World!']
}
}
const { dependencies, code } = reactGenerator.generateComponentSync(uidl)