Thoughts on a decoder "code generator" given a flow type.
See original GitHub issueOne pain point is the decoder is more-or-less just the flowtype rewritten. The advantage of something like https://github.com/codemix/flow-runtime is that this is done automatically, but without the flexibility of making more complex runtime decoders and/or deciding where to apply the runtime check.
What are your thoughts about a tool that would generate decoders for all exported types? For example if you have a file ./src/myModule.js
and you run $ decoder-codegen ./src/
, it would create a new file ./src/__generated__/myModule.decoders.js
. Then we can import the decoders into the source file.
myModule.js
import { guard } from 'decoders';
import { pointDecoder } from './__generated__/myModule.decoders';
const checkPointType = guard(pointDecoder);
export type Point = {
x: number,
y : number
}
export function moveUp(point: Point) {
checkPointType(point);
point.y = point.y - 1;
}
Inspired by https://github.com/apollographql/apollo-codegen#generate
Issue Analytics
- State:
- Created 5 years ago
- Comments:14 (7 by maintainers)
Top Results From Across the Web
Multi-stage code generator and decoder for communication ...
The static encoder includes a redundant symbol generator that generates a plurality of redundant symbols based on the input symbols.
Read more >Beyond Codex: A Code Generation Model That You Can Train
This post will overview codeT5, an encoder-decoder code generation model with publicly available pre-training checkpoints that you can try today ...
Read more >Text-to-code Generation with TensorFlow, & MBPP - Kaggle
This notebook demonstrates how to generate python code based on the natural language description using TensorFlow, HuggingFace and Mostly Basic Python ...
Read more >Downlink Baseband Decoder Implementation - DiVA Portal
A given code can only be used if there are no other codes used on the path from that given code to the...
Read more >Designing of 2 to 4 Line Decoder - ElProCus
This article discusses how to design 2 to 4 Line Decoder circuit which takes an 2 -bit binary number and produces an output...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Guard satisfies the majority of my use cases and does not require understanding of decoders to use, though it would be nice in certain situations.
The lib could provide both:
Additionally, I am thinking decoders that go beyond flow types (integer, regex, email, etc), it might make more sense to have that as an additional optional argument that would “extend” the decoder. The implementation of pulling this from comments or somewhere else would be tricky and maybe a little too magical.
or with decoders…
fyi, proof of concept started: https://github.com/sfarthin/flow-guard . Might be some time translating the flow AST into decoder code. (https://github.com/sfarthin/flow-guard/blob/master/macro.js#L5)