Generate better JavaScript
 From Goa Design

28da29f13a2f4e6f602b7bfa032a94cc?s=47 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

28da29f13a2f4e6f602b7bfa032a94cc?s=128

shirou

June 16, 2017
Tweet

Transcript

  1. Generate JavaScript
 From Goa Design Shirou WAKAYAMA (@r_rudi)
 Tsukinowa Inc.

    Better
  2. Who? • Twitter: r_rudi • CTO at Tsukinowa Inc. •

    Ansible / Sphinx • 4 years Golang • Server / FrontEnd / Infra / Android
  3. 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
  4. goagen_js • https://github.com/shirou/goagen_js • It generates ES 2015 code. •

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

    HFU GVOD \ 3PVUJOH (&5 6TFS*%  1BSBNT GVOD \ 1BSBN 6TFS*% *OUFHFS GVOD \ .BYJNVN   ^  3FRVJSFE 6TFS*%  ^
  6. 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
  7. 2. Validation • ` FYQPSUDPOTU6TFS(FU\ 6TFS*%\ LJOEOVNCFS  NBYJNVN ^

    ^
 
 WBMJEBUFDBOWBMJEBUFXJUITQFDJpFESVMFTFU FYQPSUGVODUJPOWBMJEBUF SVMF BDUVBM \
  TOJQ 
 ^
 Generated Rule Validator function
  8. 3. Type annotation • flowtype • typescript HPBHFOHFO
 QLHQBUIHJUIVCDPNTIJSPVHPBHFO@KT
 ETPNFFYBNQMFEFTJHO


    UBSHFUUZQFTDSJQUHFOPVUUT
  9. 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  ^
  10. Conclusion • goagen_js can generate JS code with 1. Explicit

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