Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Generate better JavaScript
 From Goa Design

shirou
June 16, 2017

Generate better JavaScript
 From Goa Design

Generate (better) JavaScript from Goa Design. This JavaScript has,

1. Explicit Method using Promise API
2. Validation
3. Type Annotation

https://github.com/shirou/goagen_js

shirou

June 16, 2017
Tweet

More Decks by shirou

Other Decks in Programming

Transcript

  1. Who? • Twitter: r_rudi • CTO at Tsukinowa Inc. •

    Ansible / Sphinx • 4 years Golang • Server / FrontEnd / Infra / Android
  2. JS code generator: gen_js • JS code generator already included.

    • Hmm, it seems it does not have some of features…. • generate from swagger also. HPBKTEFYBNQMFEFTJHO
  3. goagen_js • https://github.com/shirou/goagen_js • It generates ES 2015 code. •

    You need Babel to run Web Browser. HPBHFOHFO
 QLHQBUIHJUIVCDPNTIJSPVHPBHFO@KT
 ETPNFFYBNQMFEFTJHO
  4. Sample Design WBS@3FTPVSDF VTFS GVOD \ #BTF1BUI VTFS 
 "DUJPO

    HFU GVOD \ 3PVUJOH (&5 6TFS*%  1BSBNT GVOD \ 1BSBN 6TFS*% *OUFHFS GVOD \ .BYJNVN   ^  3FRVJSFE 6TFS*%  ^
  5. 1. Explicit Method using 
 Promise API 6TFS(FU VTFS*% OVNCFS

    6TFS*%UPHFUJOGPSNBUJPO FYQPSUGVODUJPO6TFS(FU VTFS*% \ DPOTUVSMVSM1SFpY AVTFS\VTFS*%^A DPOTUFWWBMJEBUF W6TFS(FUVTFS*% VTFS*%  JG F \ SFUVSO1SPNJTFSFKFDU F  ^ SFUVSOHFU VSM  ^ utility function
  6. 2. Validation • ` FYQPSUDPOTU6TFS(FU\ 6TFS*%\ LJOEOVNCFS  NBYJNVN ^

    ^
 
 WBMJEBUFDBOWBMJEBUFXJUITQFDJpFESVMFTFU FYQPSUGVODUJPOWBMJEBUF SVMF BDUVBM \
  TOJQ 
 ^
 Generated Rule Validator function
  7. 3. Typescript Example 6TFS(FU VTFS*% OVNCFS 6TFS*%UPHFUJOGPSNBUJPO FYQPSUGVODUJPO6TFS(FU VTFS*%OVNCFS 1SPNJTF6TFS.FEJB\

    DPOTUVSMVSM1SFpY AVTFS\VTFS*%^A MFUFWWBMJEBUF W6TFS(FUVTFS*% VTFS*%  JG F \ SFUVSO1SPNJTFSFKFDU F  ^ SFUVSOHFU VSM  ^
  8. Conclusion • goagen_js can generate JS code with 1. Explicit

    Method Name with Promise 2. Validation 3. Type Annotation • but still under heavy development.