ã¯ã©ã€ã¢ã³ãã®JavaScriptã¯æ¥éã«å€åããŠããŸããã©ã€ãã©ãªããã¬ãŒã ã¯ãŒã¯ãããã«ãŒã¯ããã«çŸããäºãã«çœ®ãæããããŸãã ãã ããããã«ãããããããå€ãã®ããŒæäœã¯ã©ã®ã¯ã©ã€ã¢ã³ãã¢ããªã±ãŒã·ã§ã³ã§ãåãã§ãã ãããŠãçŸä»£ã®ããã³ããšã³ããã¬ãŒã ã¯ãŒã¯ã§ã¯ããã®å€æ§æ§ãã¹ãŠã«å ±éç¹ãå€ããããŸãã
- èšäº1ïŒåºæ¬
- èšäº2ïŒãµãŒããŒ
- èšäº3ïŒã¯ã©ã€ã¢ã³ã
ãã®èšäºã¯ã Contoso Expressãããžã§ã¯ãã®ã³ãŒãã«åºã¥ããŠããŸãã
ãã®èšäºã®ããã€ãã®ãããã¯ã詳ããç¥ãããšãã§ãããªãœãŒã¹ã®ãªã¹ãã
ã¡ãã£ãšããæŽå²
Webæšæºã¯ãã£ãããšå€åããŸããããšãã°ãHTML 5ã®ææ°ããŒãžã§ã³ã¯2幎åã«æ¿èªããã以åã®XHTMLã¯2000幎ã«åããŠç»å ŽããŸããã æ°ããããŒãžã§ã³éã®ã®ã£ããã¯14幎ã§ããã åæã«ãæ°ããããŒãžã§ã³ã«ã¯æ ¹æ¬çã«æ°ãããã®ã¯äœããããŸããã CSSãæ¥éã«çºå±ããŠããŸããïŒ2012幎ã«flexboxã¬ã€ã¢ãŠãã«ã€ããŠåããŠèãããšãã4幎ãçµã¡ãŸããããIE11ã§ã®éšåçãªãµããŒããšä»¥åã®ããŒãžã§ã³ã§ã®äžåšã«æºè¶³ããŠãããªãã䜿çšã§ããããã§ãã JavaScriptã§ãèŠãç®ã»ã©éãå€åããŠããŸãããæè¿ã®ES6ã¢ããããŒãã®åã«ã以åã®ã¡ãžã£ãŒããŒãžã§ã³5.0ã¯6幎åã«ãªãªãŒã¹ãããŸããã åæã«ãæ°ããæšæºãåºçŸããŠããããã«äœ¿çšãéå§ã§ãããšããæå³ã§ã¯ãããŸããã ãã¹ãŠã®äž»èŠãªãã©ãŠã¶ããµããŒããéå§ãããŸã§ã«æéãããããŸãïŒIEã®å ŽåãåŸ ã€ããšã¯ã§ããŸããïŒã
ãã ããã¯ã©ã€ã¢ã³ãã¢ããªã±ãŒã·ã§ã³ã®èŠä»¶ã¯åžžã«å¢å ããŠããŸãã ã°ãŒã°ã«ã¯ã2005幎ã«Google MapsãšGmailã¯ã©ã€ã¢ã³ãããªãªãŒã¹ããããšã§æ°ŽæºãåŒãäžããŸãããããã¯ããã€ãŠãªãã¬ãã«ã®äœ¿ãããããåããã€ã³ã¿ã©ã¯ãã£ãSPAïŒã·ã³ã°ã«ããŒãžã¢ããªã±ãŒã·ã§ã³ïŒã§ãã ãã®ãããªã¢ããªã±ãŒã·ã§ã³ã¯æžãã®ãé£ããããã¹ãŠã®äŒæ¥ããããè³Œå ¥ã§ããããã§ã¯ãããŸããã ãããã¯æ¯èŒçæè¿ïŒ3ã4幎åïŒåºã䜿çšãããŠããŸãã
äž»èŠãªãã©ãŠã¶ãŒã§ãµããŒããããè€éãªSPAã¢ããªã±ãŒã·ã§ã³ãäœæããã«ã¯ãããŸããŸãªè£å©çãªææ³ã䜿çšããå¿ èŠãããããã®åéã§ã¯åžžã«å€åãèµ·ãã£ãŠããŸãã
SPA
SPAã¯ææ°ã®Webã¢ããªã±ãŒã·ã§ã³ã®æšæºã«ãªãã€ã€ãããæé«ã¬ãã«ã®ãŠãŒã¶ãŒãšã¯ã¹ããªãšã³ã¹ãæäŸããŸãã ã¢ããªã±ãŒã·ã§ã³ã¯ãããŒãžãæåã«ããŒãããããšãã«ã¡ã€ã³ãªãœãŒã¹ïŒã¹ã¿ã€ã«ãã³ãŒããããŒã¯ã¢ããïŒãããŒãããŸãããã®åŸãã¯ã©ã€ã¢ã³ãã§åŸç¶ã®ç¶æ å€æŽãçºçããŸãã ãµãŒããŒããã®ããŒã¿ã¯AJAXãªã¯ãšã¹ããä»ããŠããŒããããHTMLã¯HTMLãã³ãã¬ãŒãã«åºã¥ããŠããŸãã¯JSïŒReactïŒããçŽæ¥ã¯ã©ã€ã¢ã³ãã§ã¬ã³ããªã³ã°ãããŸãã
ããã¯ãç¶æ ãå€æŽãããã³ã«ãµãŒããŒããæŽæ°ãããããŒãžãåããŒãããå¿ èŠãããåŸæ¥ã®ã¢ãŒããã¯ãã£ãšã¯ç°ãªããŸãã
Webã¢ããªã±ãŒã·ã§ã³ã¯ãè€æ°ã®SPAã¢ãžã¥ãŒã«ã®ã»ãããšããŠèšè¿°ããããã¯ã©ã·ãã¯ã©ãŠã³ãããªããã¢ãŒãã§åäœããããŒããšçµã¿åããããã§ããŸãã Contosoã§ã¯ãèªèšŒããŒãžã¯ãã¹ãããã¯ãéããŠæ©èœããæ®ãã®ã¢ããªã±ãŒã·ã§ã³ã¯SPAãšããŠäœæãããŸãã
ã¹ã¿ã€ã«ããªããã»ããµ
CSSæ§æã«ã¯ãããªããã»ããµã«ãã£ãŠæé€ãããå€ãã®æ¬ ç¹ããããŸã-CSSã¢ããªã³èšèªïŒLESS / SASS / Stylus
æšæºCSSã®å€§å¹ ãªæ¹åïŒ
- ãã¹ããããã»ã¬ã¯ã¿ãŒïŒ
.my-class { background-color: blue; div { background-color: red; // -> .my-class div { background-color: red; } } }
- å€æ°ãåŒãããã³é¢æ°ïŒ
@myPadding = 10px; .my-class { padding-top: @myPadding; // 10px padding-bottom: @myPadding + 5px; // 15px }
- ããã·ã³ã°ïŒ
.error { color: red; font-weight: bold; } .admin-error { border: 1px solid black; .error // -> .error styles inserted here }
ããªããã»ããµã䜿çšãããšãç¹ã«ã¹ã¿ã€ã«ãå€æ°ããå Žåã«ãã¹ã¿ã€ã«ã®èšè¿°ãšä¿å®ãç°¡åã«ãªããŸãã Contosoã¯LESSã䜿çšããŸãããçŸåšã¯SASSã®æ¹ãäžè¬çã§ãããäž¡è ã®éãã¯ããã»ã©å€§ãããããŸããã
CSSãã¬ãŒã ã¯ãŒã¯ã®éžæ
CSSãã¬ãŒã ã¯ãŒã¯ã¯ãèŠçŽ ã®é 眮ïŒã°ãªããã·ã¹ãã ïŒãç°¡åã«ããäžé£ã®ãã³ãã¬ãŒãã¹ã¿ã€ã«ãæäŸããããã©ã«ãã®ã¹ã¿ã€ã«èšå®ïŒããã©ã«ãã§ã¯HTMLã®èŠæ ããè¯ãïŒããªãŒããŒã©ã€ãããã¢ãŒãã«ãŠã£ã³ããŠãããã²ãŒã·ã§ã³ã¡ãã¥ãŒãæ¥ä»ããã«ãŒãªã©ã®JSãæå¹ãªãŠã£ãžã§ããã®ã»ãããæäŸããŸãdã
äž»ãªãªãã·ã§ã³ïŒ
ããŒãã¹ãã©ããã¯äž»èŠãªéžæã§ãããæåã®å€§èŠæš¡ãªCSSãã¬ãŒã ã¯ãŒã¯ã§ãã ããšããšã¯Twitterã«ãã£ãŠäœæããããã®ã§ããã¹ã¯ããããšã¢ãã€ã«ã®äž¡æ¹ã®éçºã«é©ããŠããŸãã ã³ã³ããŒãã³ãã®å€§èŠæš¡ãªã»ããã 人æ°ãé«ããããããŒãã¹ãã©ããã®ãµã€ãã¯ã¹ãã¬ãªã¿ã€ãã«èŠãããããããŸããã
Foundationã¯ãäžè¬çãªéžæè¢ã§ãããã³ã³ããŒãã³ãã®é©åãªéžæã§ããã䟿å©ãªäœçœ®æ±ºãã·ã¹ãã ã§ãã
ã»ãã³ãã£ãã¯UI-ããèšèšãããèŠçŽ ã¯ã©ã¹ã®ã»ãã³ãã£ã¯ã¹ïŒåœåïŒã«çŠç¹ãåœãŠãŠããŸãããã¢ãã€ã«éçºã«ã¯ããŸãé©ããŠããŸããã
ãããªã¢ã«ãã¶ã€ã³ã¯ãã¬ãŒã ã¯ãŒã¯ã§ã¯ãããŸããããäŒç€Ÿã®è£œåïŒAndroidïŒã§äœ¿çšãããŠããGoogleã¹ã¿ã€ã«ã®ã¬ã€ãã©ã€ã³ã§ãã React Material UIããã³ä»ã®JSãã¬ãŒã ã¯ãŒã¯ã«ã¯ããã®èšèšã®å®è£ ããããŸãã
ããã«ãé¡äŒŒã®Font Awesomeã§æã人æ°ã®ãããã©ã³ã圢åŒã®ã¢ã€ã³ã³ã»ããã§ã©ã€ãã©ãªã䜿çšã§ããŸãã
Contosoã¯Font AwesomeãšBootstrapã䜿çšããŸã ã
ã¯ã©ã€ã¢ã³ãJSãã¬ãŒã ã¯ãŒã¯ã®éžæ
äž»ãªãªãã·ã§ã³ãèŠãŠã¿ãŸãããã
JQueryã¯ãããŸããŸãªãã©ãŠã¶çšã®åäžã®ã€ã³ã¿ãŒãã§ã€ã¹ã§DOMèŠçŽ ãç°¡åã«çŽæ¥æäœã§ããã©ã€ãã©ãªã§ãããååã«ææžåãããŠãããAJAXèŠæ±ãšãã©ã°ã€ã³ã®èšè¿°ããµããŒãããŠããŸãã è€éãªã¯ã©ã€ã¢ã³ãã¢ããªã±ãŒã·ã§ã³ã®äœæã«ã¯ããŸãé©ããŠãããããªã¢ã¯ãã£ãããŒã¿ãã€ã³ãã£ã³ã°æ©èœãæäŸããŸããã
ã¯ã©ã€ã¢ã³ãJSã©ã€ãã©ãªã®åå¿æ§ã¯ãããŒã¿ïŒã¢ãã«ïŒãšè¡šç€ºïŒHTMLãã¥ãŒïŒãåçã«ãªã³ã¯ããæ©èœã§ãã ã¢ãã«ãå€æŽããããšã衚瀺ã¯èªåçã«ïŒåå¿çã«ïŒå€æŽãããéãåæ§ã§ãã衚瀺ç¶æ ã®å€æŽïŒå ¥åå€ãå€æŽãããïŒã«ããã¢ãã«ãå€æŽãããŸãã Vue.jsã䜿çšããåçŽãªåå¿ã®äŸãžã®jsfiddleãªã³ã¯ã¯ããã¹ãŠã®DOMæäœãæåã§è¡ããããã¯ããã«ç°¡åã§ããããšãè©äŸ¡ããŸãã
Angular 1.Xã¯ãæåã®å€§äººæ°ã®ãªã¢ã¯ãã£ããã¬ãŒã ã¯ãŒã¯ã§ãïŒKnockoutãªã©ãä»ã«ããããŸããïŒã Angularã¯ãåå¿æ§ã«å ããŠãã¢ããªã±ãŒã·ã§ã³ã®æ§é åãåå©çšå¯èœãªã³ã³ããŒãã³ãïŒãã£ã¬ã¯ãã£ãïŒã®ãµããŒããªã©ãæäŸããŸãã æ®å¿µãªãããAngular 1.xã¯äžå¿ èŠã«æ··ä¹±ãæããå€ãã®æŸèæãæã¡ãç¹ã«åå¿æ§ã®ç 究ãšéçºãå°é£ã§ãã ããã©ãŒãã³ã¹ã®åé¡ããããŸãã åœåãAngularã¯ç¬ç«ãããªãŒãã³ãœãŒã¹ã©ã€ãã©ãªã§ããã ãã®åŸãGoogleã«ãã£ãŠéçºããã³ä¿å®ãããŸãã Angularã¯2014幎ã«ããŒã¯ã«éããReactã«ãã£ãŠç©æ¥µçã«çœ®ãæããããŠããŸãã
React -Angularãšã¯ç°ãªããã¯ã©ã€ã¢ã³ããããã³ã°ãçæããããã«èšèšããããã¬ãŒã ã¯ãŒã¯ã§ã¯ãªããã©ã€ãã©ãªã§ãã ä»®æ³DOMææ³ã䜿çšããŠãã¬ã³ããªã³ã°ãé«éåããŸãã ããã«ãããReactã¯ããã©ãŒãã³ã¹ã«å€§ããªåœ±é¿ãäžããããšãªããããŒã¿ãå€æŽããããã³ã«è¡šç€ºãå®å šã«åã¬ã³ããªã³ã°ã§ããŸãã
Reactã¯ãããŒã¿ãåžžã«äžæ¹åã«å€åããFluxã¢ãŒããã¯ãã£ã§äœ¿çšããããšããå§ãããŸãã ãŸããã¢ãã«ããŒã¿ãéå§ããããããã«ãããã³ã°ãæ§ç¯ããããã£ã¹ãã¬ã€ãã¢ãã«ã®ç¶æ ãå€æŽããã€ãã³ããçæããŸããããã«ããããã£ã¹ãã¬ã€ã®æŽæ°ãå¿ èŠã«ãªããŸãã ããã«ãããã¢ããªã±ãŒã·ã§ã³ã§ç¶æ ãã©ã®ããã«å€åããããç解ãããããªããéçºãå€§å¹ ã«ä¿é²ãããŸãã
Reactã§ã¯ãJSã³ãŒãã䜿çšããŠXMLïŒHTMLïŒæ§æãæäœã§ããJSXã䜿çšããŸãã ããã¯ãåŸæ¥ã®HTMLãã³ãã¬ãŒãã®ä»£ããã«äœ¿çšãããŸãã JSXã䜿çšãããšãJSã®ãã¹ãŠã®æ©èœã䜿çšããŠãã³ãã¬ãŒããçæã§ããŸãããã¬ã€ã¢ãŠããã¶ã€ããšã®ãµããŒãããã³ã³ã©ãã¬ãŒã·ã§ã³ãããå°é£ã«ãªãå¯èœæ§ããããŸãã Reactã¯facebookã«ãã£ãŠäœæããã圌ãã®ãããžã§ã¯ãã®ããã€ãã§äœ¿çšãããŠããŸãã
Angular 2.xã¯ææ°ã®ãã¬ãŒã ã¯ãŒã¯ã§ãïŒæçµãªãªãŒã¹ã¯2016幎9æïŒã è€éãªã¯ã©ã€ã¢ã³ãã¢ããªã±ãŒã·ã§ã³ãåªããããã©ãŒãã³ã¹ã®éçºã«çŠç¹ãåœãŠãŠããŸãã ããã¯ãŒãããäœæãããŠãããAngular 1.xãšã¯ã»ãšãã©äŒŒãŠããŸããã åå¿æ§ãã¯ããã«ç°¡åã«å®è£ ãããŸãããã€ãã£ãHTMLå±æ§ããã€ã³ãã£ã³ã°ã«äœ¿çšãããŸãïŒããšãã°ãngã¯ãªãã¯ã§ã¯ãªãã¯ãªãã¯ïŒã å€ãã®é«åºŠãªTypeScriptæ©èœã䜿çšããŸããããšãã°ãDependency Injectionã¯ãã¯ã©ã¹ã³ã³ã¹ãã©ã¯ã¿ãŒãšå€æ°åïŒCïŒ/ Javaãªã©ïŒãä»ããŠå®è£ ãããŸãã ãã³ã¬ãŒã¿ã¯é »ç¹ã«äœ¿çšãããŸãã Angularã¯ãµãŒãããŒãã£ã®ã©ã€ãã©ãªãå¿ èŠã§ãïŒzone.jsïŒãããªãã¡ã€ã«ã䜿çšããå€ãã®æšæºãã©ãŠã¶æ©èœããªãŒããŒã©ã€ãããŸãã çŸæç¹ã§ã¯ãã·ã¹ãã ã®ç¶æ ãæŽçããããã®æšæºçãªãã©ã¯ãã£ã¹ãã©ããªããã¯ãŸã æ確ã§ã¯ãããŸããã Angular 2ã¯Fluxã¢ãŒããã¯ãã£ïŒããšãã°Reduxã䜿çšïŒã§åäœããŸãããFluxã¯å¯äžã®çã®ã¢ãŒããã¯ãã£ãšããŠã¯æšå¥šãããŸããã
VueJSã¯ãReact / Angularã®åªãã代æ¿æ段ã§ãã åçŽãªãã®ããè€éãªãã®ãŸã§ïŒååçã«ïŒååã«åŸããŸãã åºæ¬çãªãªã¢ã¯ãã£ãæ©èœãåããVueããå§ããã®ã¯éåžžã«ç°¡åã§ãããåæã«ãè€éãªSPAãæ§ç¯ããããã«å¿ èŠãªãã¹ãŠãè¿œå ããããšã§Vueãæ¡åŒµã§ããŸãã Vueã¯ç°¡åã«çµ±åã§ããé«éã§çŽæçã§ãã é·ãéã圌ã¯GitHubã®JSãã¬ã³ããªããžããªãªã¹ãã«åžžã«ååšããŠãããããã«ã¯ååãªçç±ããããŸãã ãã³ãã¬ãŒãæ§æã¯Angular2ã«äŒŒãŠããŸãã Fluxã¢ãŒããã¯ãã£ãåããVuexã¯ãç¶æ ã®ä¿åã«äœ¿çšãããŸãã Vueã®2çªç®ã®ããŒãžã§ã³ã¯ãŸããªãç»å ŽããŸããç¹ã«ãããã©ãŒãã³ã¹ãæ¹åããïŒVirtual DOMã䜿çšïŒãJSXã䜿çšãããªãã·ã§ã³ããªãã·ã§ã³ã§è¿œå ãããŸãã
ãã®ä» -å€ãã®ãã¬ãŒã ã¯ãŒã¯/ã©ã€ãã©ãªããããŸãã ä»ã®ãªãã·ã§ã³ãæ€èšããããšã«èå³ãããå Žåã¯ãããŸããŸãªMV *ãã¬ãŒã ã¯ãŒã¯ã§ã®ç°¡åãªTODOã¢ããªã±ãŒã·ã§ã³ã·ãŒãã®å®è£ ãåéãããŠããTodoMVC Webãµã€ããã芧ãã ããã
äœãéžã¶ã
ç¹å®ã®ãããžã§ã¯ãã«äŸåããŸãã æŽç·ŽãããSPAã¢ããªã±ãŒã·ã§ã³ãæåããæ§ç¯ããããšãèšç»ããŠããå Žåã¯ãä»æ¥æã人æ°ã®ãããªãã·ã§ã³ãšããŠReactãè©ŠããŠãã ããã ããããæ°ããæŠå¿µãåŠç¿ããç°å¢ãã»ããã¢ããããã«ã¯æéãããããŸãã
ãããžã§ã¯ãã®éçºã«åãããŠæ¡åŒµã§ããã·ã³ãã«ãªãœãªã¥ãŒã·ã§ã³ãå¿ èŠãªå ŽåãVueã¯çŽ æŽããããªãã·ã§ã³ã§ãããããŸã人æ°ããªããèåãªéçºäŒç€Ÿã«ãã£ãŠãµããŒããããŠããŸããã
ããã«ãªãªãŒã¹ãããªãè€éãªã¢ããªã±ãŒã·ã§ã³ããããå°æ¥å¿åã§ããã°ãAngular2ãè©Šãããšãã§ããŸãã
Angular1ã§æ°ãããããžã§ã¯ããéå§ããããšã¯ãå§ãããŸãããããã«ã¯Vueã䜿çšããããšããå§ãããŸããå€ãã®ç¹ã§åæ§ã®æ§æããããŸãããäœæ¥ã¯ã¯ããã«åçŽã§äŸ¿å©ã§ãã
ãŸã ããã©ãŒãã³ã¹ã®åé¡ããããŸãã ããŸããŸãªãã¬ãŒã ã¯ãŒã¯ãæ¯èŒããå€ãã®èšäºãããã®åé¡ã«å€ãã®æéãè²»ãããŠããŸãã ã»ãšãã©ã®ã¢ããªã±ãŒã·ã§ã³ã§ã¯ãã¯ã©ã€ã¢ã³ãã®ããã©ãŒãã³ã¹ã¯åé¡ã«ãªããªãããšãç解ããå¿ èŠããããŸãã倧éã®ããŒã¿ãåçã«ã¬ã³ããªã³ã°ããå¿ èŠãããå ŽåããŸãã¯ã¢ããªã±ãŒã·ã§ã³ãäœããã©ãŒãã³ã¹ã®ã¢ãã€ã«ããã€ã¹ã§ã¢ã¯ãã£ãã«äœ¿çšãããå Žåãããã©ãŒãã³ã¹ãéèŠã§ãã ããã«ãããããããããã«ããŸããŸãªJSãã¬ãŒã ã¯ãŒã¯ã®ãã¹ãã®è¡šããããŸã ã
å¥ã®éžæåºæºã¯ãç¹å®ã®ãã¬ãŒã ã¯ãŒã¯çšã®ãã©ã°ã€ã³/ã©ã€ãã©ãªã®ã»ããã§ãã ãã®ç¹ã§ãReact / Angular1ã¯æããã«ãªãŒããŒã§ãããVueJã®ãã«ããŒã³ã³ããŒãã³ãã©ã€ãã©ãªã¯æ¢ã«å€ããããŸãããAngular2ã®æ°ã¯æè¿ã®ãªãªãŒã¹åŸã«æ¥éã«å¢å ããã¯ãã§ãã Awesome Listsãªããžããªã«ã¯ãèå³ã®ãããã¬ãŒã ã¯ãŒã¯ã®ãªãœãŒã¹ã®ãã°ãããïŒæ¥œããïŒãªã¹ãããããŸãã
å°æ¥çã«ã¯ãReact / Vueã®å®è£ æ©èœã䜿çšããŠã¯ã©ã€ã¢ã³ãã¢ããªã±ãŒã·ã§ã³ãäœæããããŸããŸãªåŽé¢ã«ã€ããŠèª¬æããŸãã Contosoã§ã¯ã Reactã䜿çšããŠã¡ã€ã³ããŒãžã§ã³ãäœæãããVueã«ä»£æ¿ãã©ã³ãããããAngular2ã«å®è£ ããããã©ã³ããè¿œå ãããã£ãã®ã§ãããæ®å¿µãªããããã¬ãŒã ã¯ãŒã¯ã®ãšã³ã·ã¹ãã ã¯å®å®ããŠããŸããïŒAngular2ã䜿çšããã©ã€ãã©ãªãšããŒã«ã¯ãŸã å®å šã«æ°ãããªãªãŒã¹ã«é©å¿ããŠããŸããïŒ ã
æ§é
ã¯ã©ã€ã¢ã³ãéšåã®æ§é ã¯ãéžæãããã¬ãŒã ã¯ãŒã¯ã«äŸåããŸãã Contosoã§ã¯ãã¯ã©ã€ã¢ã³ãå®è£ ïŒReact / VueïŒ ã®å ±ééšåã¯æ¬¡ã®ãšããã§ãã
ãµãŒãã¹ -APIãä»ããŠããŒã¿ã«ã¢ã¯ã»ã¹ããããã®ã¢ãžã¥ãŒã«ã å¿ èŠã«å¿ããŠãè¿œå ã®ããŒã¿å€æãããã§è¡ãããŸãã
ãã©ãŒããã¿ ïŒãã©ãŒããã¿ïŒ-ã¯ã©ã€ã¢ã³ãã§ãã©ãŒãããããŒã¿ïŒæ¥ä»ãé貚ã衚瀺åãªã©ïŒãæäŸããŸãã
ãã«ã㌠ïŒãã«ããŒïŒ -AJAXãªã¯ãšã¹ããèšå®ãžã®ã¢ã¯ã»ã¹ããããã¢ããã¡ãã»ãŒãžã®è¡šç€ºãªã©ãã¯ã©ã€ã¢ã³ãã®äžè¬çãªæäœãå®è¡ããŸãã
ããã«ãéžæãããã¬ãŒã ã¯ãŒã¯ã«å¿ããŠå®è£ ãããéšåããããŸãã
ã³ã³ããŒãã³ã -ã¯ã©ã€ã¢ã³ãã€ã³ã¿ãŒãã§ã€ã¹ã®æ§æèŠçŽ ã ææ°ã®ãã¬ãŒã ã¯ãŒã¯ã¯ãã¹ãŠãã³ã³ããŒãã³ãããªãŒãšããŠUIã®äœæããµããŒãããŠããŸãããå ·äœçãªå®è£ ã¯ç°ãªããŸãã éåžžãã³ã³ããŒãã³ãã¯æ©èœïŒProjectãUserAccountãOrdersãªã©ïŒã«å¿ããŠãã©ã«ããŒã«ã°ã«ãŒãåãããŸãã
ç¶æ ïŒããŒã¿ïŒãšã·ã¹ãã ã€ãã³ãã¯å¥ã ã«ä¿åãããŸããReactã®å Žåããããã¯ãã©ã«ã㌠'actions'ã 'store'ã 'reducers'ãVueã®å Žåã¯ãã©ã«ã㌠'vuex'ã§ãã
ã«ãŒãã£ã³ã°
Webã¢ããªã±ãŒã·ã§ã³ã®åŸæ¥ã®æ§æã§ã¯ãç°ãªãã«ãŒãïŒURLïŒããµãŒããŒããç°ãªãããŒãžãããŒãããŸãã SPAã¢ããªã±ãŒã·ã§ã³ã§ã¯ããã¹ãŠã®ããŒã¿ãããã«ããŒããããŸãã å¥ã®ããŒãžã«ç§»åããŠãããµãŒããŒããæ°ããããŒãžãèªã¿èŸŒãŸããããšã¯ãªããURLã¯å€ãããŸããã
ããã¯ãŠãŒã¶ãŒã«ãšã£ãŠããŸã䟿å©ã§ã¯ãããŸãããçŸåšã®ãªã³ã¯ããã©ãŠã¶ãŒã«ä¿åã§ãããããŒãžéã®ç§»åã«é²ã/æ»ããã¿ã³ã䜿çšã§ããŸããã
SPAã«ã«ãŒãã£ã³ã°ãè¿œå ããæ¹æ³ã¯ããã€ããããŸãã
- ããã·ã¥ã¿ã°-å€ããã©ãŠã¶ïŒIE9ïŒããµããŒãããããã«äœ¿çšãããã¢ãã¬ã¹ã¯www.mysite.com/#/product/listã®ããã«ãªããŸã
- HTML5 History APIã䜿çšãããšãã¢ãã¬ã¹ã¯éåžžã®Webã¢ããªã±ãŒã·ã§ã³www.mysite.com/product/listãšåãããã«èŠããŸã
åã¯ã©ã€ã¢ã³ããã¬ãŒã ã¯ãŒã¯ã«ã¯ãã«ãŒãã£ã³ã°çšã®åå¥ã®ã©ã€ãã©ãªããããŸãã
Contosoã¯ãHistory APIïŒpushStateïŒã¢ãŒãã䜿çšããŸãã
ã¯ã©ã€ã¢ã³ãã§ã«ãŒãã£ã³ã°ã䜿çšããã«ã¯ããµãŒããŒã§å°ãèšå®ããå¿ èŠããããŸãã äžæãªãµãŒããŒã«ãŒãã¯ãã¹ãŠãã¢ããªã±ãŒã·ã§ã³ã®ã¡ã€ã³ããŒãžã«ãªãã€ã¬ã¯ãããå¿ èŠããããŸãã 次ã«ããµãŒããŒããã®æåã®ããŒãžã®ããŒãåŸãã¯ã©ã€ã¢ã³ãã«ãŒãã£ã³ã°ãæ©èœããŸãã
AJAXãªã¯ãšã¹ã
ããã¯ãéžæããJSãã¬ãŒã ã¯ãŒã¯ã«ããŸãäŸåããªãã¿ã¹ã¯ã§ãã Vueããã³Angularçšã«ç¹å¥ã«èšèšãããã©ã€ãã©ãªããããŸããããããã®äœ¿çšã¯ãªãã·ã§ã³ã§ãã AJAXã©ã€ãã©ãªã¯éåžžã«å€ãååšãããããããã€ãã®åªãããªãã·ã§ã³ãæäŸããŸãã
ãããžã§ã¯ãããŸã äœãã«JQueryã䜿çšããŠããå Žåã¯ãAJAXãªã¯ãšã¹ãã«äœ¿çšã§ããŸãã Contosoã§ã¯ã jQueryã¯promiseã«ã©ãããããhttpHelperã¢ãžã¥ãŒã«ãéããŠäœ¿çšãããŸãã
å¥ã®è¯ããªãã·ã§ã³ã¯axiosã§ãã ãã®ã©ã€ãã©ãªã«ã¯äŸ¿å©ãªAPIããããPromiseããµããŒãããŸããããã¯ãã«ã¹ã¿ãã¯éçºã«ãšã£ãŠéåžžã«éèŠã§ããããµãŒããŒãšã¯ã©ã€ã¢ã³ãã®äž¡æ¹ã§åãããã«æ©èœããŸãã
JSããXMLHttpRequestãçŽæ¥äœ¿çšããããšã¯å°é£ã§ããããããã€ãã£ãFetchã¡ãœããã眮ãæããããã«ææ¡ãããŠããŸããããã¯ãã¹ãŠã®äž»èŠãªãã©ãŠã¶ãŒã§ãŸã ãµããŒããããŠããŸãããããã®ãããªå Žåã«ã¯ãã€ãã®ããã«ãåãAPIã§åäœãããã§ããããªãã£ã«ããªãã£ã«ãæã€ã©ã€ãã©ãªããããŸãã
ãã¹ãŠã®AJAXãªã¯ãšã¹ãã§å®è¡ã§ããã¢ã¯ã·ã§ã³ãããã€ããããŸãã
UIããããã¯ããŠãAJAXèŠæ±ãå®äºããŠã·ã¹ãã ã¹ããŒã¿ã¹ãæŽæ°ããããŸã§ããŠãŒã¶ãŒãä»ã®ã¢ã¯ã·ã§ã³ãå®è¡ã§ããªãããã«ããããšãã§ããŸãã
èŠæ±äžã«ãšã©ãŒãçºçããå Žåãããã©ã«ãã§ã¯ããã¹ãŠã®èŠæ±ã«å¯ŸããŠäžè¬çãªã¡ãã»ãŒãžïŒããµãŒããŒãšã©ãŒããªã©ïŒã衚瀺ã§ããŸãã
ãªãã·ã§ã³ã§ããã¹ãŠã®AJAXèŠæ±ã®ããŒã«ã«ãã®ã³ã°ããã©ãŠã¶ã³ã³ãœãŒã«ã«è¿œå ã§ããŸãã
æ€èšŒ
ã¯ã©ã€ã¢ã³ãã§ã®æ€èšŒã¯ããµãŒããŒã§ã®æ€èšŒãšã¯ç°ãªããŸãã ãµãŒããŒã§ããã¹ãŠã®åä¿¡ãã©ã¡ãŒã¿ãŒãæ€èšŒããå¿ èŠããããŸãã ã¯ã©ã€ã¢ã³ãã§ããŒã¿ãæ€èšŒãããããšããŸãã¯æªæã®ãããŠãŒã¶ãŒã®ãªã¯ãšã¹ãã§ã¯ãªããã¯ã©ã€ã¢ã³ãã³ãŒãããã®åŒã³åºãã§ããããšãä¿¡é Œããããšã¯ã§ããŸããã
ã¯ã©ã€ã¢ã³ãã®ç¶æ³ã¯ç°ãªããŸããããŠãŒã¶ãŒãééããç¯ãå¯èœæ§ã®ããå Žæã®ã¿ãæ€èšŒããå¿ èŠããããŸãã ãã ããããšãã°ããµãŒãããŒãã£ã®ã³ã³ããŒãã³ãã䜿çšããŠæ¥ä»ãå ¥åããããã«ééã£ãæ¥ä»ã空ã®æ¥ä»ãå ¥åããããšãäžå¯èœãªå Žåãæ€èšŒããå¿ èŠã¯ãããŸããã åæã«ãã©ã®ãšã©ãŒãã©ã®ããã«è¡šç€ºãããã«ã€ããŠããã«èããå¿ èŠããããŸãã
ã¯ã©ã€ã¢ã³ãæ€èšŒã¯éåžžã䜿çšãããã¯ã©ã€ã¢ã³ããã¬ãŒã ã¯ãŒã¯ãšå¯æ¥ã«é¢é£ããŠããŸãã ã¢ãã«å ã®ããŒã¿ã®ãã§ãã¯ã«çµã³ä»ãããããšã©ãŒã¯ã¢ãã«ããŒã¿ã®ç¶æ ã«åçã«äŸåããŸãã
Contosoã§ã¯ãReactã§ã¯æ€èšŒã«è£å©ã©ã€ãã©ãªã¯äœ¿çšãããŸããããVueã§ã¯ãvue-validatorãããã±ãŒãžã䜿çšãããŸãã
æ§æ
éåžžãã¯ã©ã€ã¢ã³ãã«ã¯å€æ°ã®æ§æèšå®ã¯ãããŸããããããã§ãå¿ èŠã§ãã ããšãã°ãã¯ã©ã€ã¢ã³ãã®ããŒã¿ã®æžåŒèšå®ïŒæ¥ä»ãæ°åãé貚ïŒã®èšå®ããªãã·ã§ã³ã§ãã¹ãŠã®AJAXèŠæ±ãã³ã³ãœãŒã«ã«èšé²ããããã®ãã©ã°ãªã©ã䜿çšã§ããŸãã
䟿å®äžããµãŒããŒæ§æããã¯ã©ã€ã¢ã³ãæ§æå€ãèªã¿åããã¯ã©ã€ã¢ã³ãã§è£å©ã¢ãžã¥ãŒã«ã䜿çšã§ããŸããè£å©ã¢ãžã¥ãŒã«ã¯ãå¥ã®AJAXèŠæ±ãéããŠãµãŒããŒããå€ãæžç®ããŸãã
Contosoã§ã¯ãããã¯ãã®ããã«å®è£ ãããŠããŸãããhelpers / clientConfigããã¡ã€ã«ãåç §ããŠãã ããã
ãšã©ãŒåŠç
ã¯ã©ã€ã¢ã³ããšã©ãŒã®äž»ãªåå ã¯AJAXãªã¯ãšã¹ãã§ãã ã¯ã©ã€ã¢ã³ãéšåãšãµãŒããŒéšåã®äž¡æ¹ãéçºããŠããå Žåãã¯ã©ã€ã¢ã³ãã«è¡šç€ºã§ãããšã©ãŒããã¹ããããã«è»¢éããæ¹ãç°¡åãªå ŽåããããŸãã APIãåå¥ã«éçºããå Žåããšã©ãŒã¯HTTPã³ãŒããŸãã¯ã«ã¹ã¿ã æååã³ãŒãã䜿çšããŠåŠçãããŸã;ããã¯ãAJAXãªã¯ãšã¹ããè¡ããµãŒãã¹ã¡ãœããã§ããã«è¡ãã®ãæé©ã§ãã
ä»ã®ãšã©ãŒã¯ã»ãšãã©ã®å ŽåãŸã£ããåŠçããããåŠçãã¹ãã§ã¯ãªããšæ³å®ãããŸããçºçããå ŽåããŠãŒã¶ãŒã¯ããŒãžã®åèªã¿èŸŒã¿ãæšæž¬ããŸãã
ãã ãã å®çšŒåç°å¢ã§ã¯ãã¯ã©ã€ã¢ã³ããããšã©ãŒããã°ã«èšé²ã§ããŸããããã«ã¯ã logentriesãªã©ã®ããã€ãã®ãµãŒãã¹ããããŸãã
ãããã³ã°
倧èŠæš¡ãªã¯ã©ã€ã¢ã³ãã¢ããªã±ãŒã·ã§ã³ãäœæããå Žåããã©ãŠã¶ãå€æ°ã®å°ããªã¢ãžã¥ãŒã«ã«åå²ããå¿ èŠããããŸããããã©ãŠã¶ã¯å€æ°ã®ãã¡ã€ã«ã§ããŸãæ©èœããŸããïŒHTTP2ã¯ãããä¿®æ£ããŸãïŒã ãããã£ãŠãã³ãŒããŸãã¯ã¹ã¿ã€ã«ãæã€è€æ°ã®ãã¡ã€ã«ã1ã€ãŸãã¯è€æ°ã®ã¢ã»ã³ããªïŒãã³ãã«ïŒã«çµåããå Žåãã¯ã©ã€ã¢ã³ããã«ãã®ãã©ã¯ãã£ã¹ããããŸãã ãã®ããã«ãããŸããŸãªããŒã«ã䜿çšãããŸãã
ã¿ã¹ã¯ãããŒãžã£ãŒ ïŒã¿ã¹ã¯ã©ã³ããŒïŒã¯ãJSãã¡ã€ã«ã®çµåãšå§çž®ãSASS / LESSã®ã³ã³ãã€ã«ããã¡ã€ã«ã®ã³ããŒãååå€æŽãªã©ãå¹ åºãã¿ã¹ã¯çšã«èšèšãããŠããŸãã å¿ èŠãªäœæ¥ã¯ãCLIïŒã³ã³ãœãŒã«ïŒãä»ããŠåå¥ã«å®è¡ã§ããã¿ã¹ã¯ã«åå²ãããŸãã ããŸããŸãªã¿ã¹ã¯ãå®è¡ããã«ã¯ãç¹å®ã®ãããŒãžã£ãŒã«å¯ŸããŠãã©ã°ã€ã³ã䜿çšãããŸãã æã人æ°ã®ããã¿ã¹ã¯ãããŒãžã£ãŒã¯GulpãšGruntã§ãã æè¿ãã¿ã¹ã¯ãããŒãžã£ãŒãšãã®ãã©ã°ã€ã³ã䜿çšããã«ãnpmããŒã«ã䜿çšããŠã¹ã¯ãªãããå®è¡ããNodeã§ã¹ã¯ãªããèªäœãèšè¿°ããåŸåããããŸãã
ã¯ã©ã€ã¢ã³ãã¢ã»ã³ããªã®äžè¬çãªã¿ã¹ã¯ã«å ããŠãã¢ãžã¥ãŒã«ãã³ãã©ãŒã¯JavaSrcriptãã¡ã€ã«ã®äŸåé¢ä¿ãåæããããã«å¿ããŠå ã®ã¢ã»ã³ããªãçµåããŸãã ããšãã°ãmodule2.jsãã€ã³ããŒãããmodule1.jsããããããã«module3.jsãšlodashãã€ã³ããŒããããå Žåã å ã®ã¢ã»ã³ããªã§ã¯ãã¢ãžã¥ãŒã«ã¯ç®çã®é åºã«ãªããŸãïŒããã·ã¥ã3ã2ã1ïŒã ã¢ãžã¥ãŒã«ãã«ããŒã¯ãããã©ã«ãã§ãå€éšã¢ãžã¥ãŒã«ããnode_modulesããã©ã«ããŒå ã®npmããã±ãŒãžãšããŠè¡šç€ºããããšãæ³å®ããŠããŸãã
ä»æ¥æã人æ°ã®ããã®ã¯WebPackã§ãã ãã®ã¿ã€ãã®æåã®ããŒã«ã¯Browserify㧠ã WebPackãããç°¡åã§ãããããå€ãã®æ§æãå¿ èŠã§ãã ããŒã«ã¢ããã®äººæ°ãé«ãŸã£ãŠããŸã-ã€ã³ããŒãã«ES6æ§æã䜿çšããå Žåãå€éšã©ã€ãã©ãªã®ã©ã®éšåã䜿çšãããã決å®ãããããã®ã¿ãå«ããããšãã§ãããããã¯ã©ã€ã¢ã³ãã¢ã»ã³ããªã®ãµã€ãºãå°ããã§ããŸãã
Contosoã¯ãã¯ã©ã€ã¢ã³ããã«ããnpmããŸãã¯ã³ã³ãœãŒã«èªäœã«WebPackã䜿çšããŠã¿ã¹ã¯ãå®è¡ããŸãã WebPackã¯ãã¢ãžã¥ãŒã«ã®çµåãTypeScriptã®ES5ãžã®ãã©ã³ã¹ã³ã³ãã€ã«ãLESSããCSSãžã®ã¹ã¿ã€ã«ã®å€æãåäžã®ãã¡ã€ã«ãžã®çµåããã«ã補åã®ããã®JSãšCSSã®çž®å°ãè¡ããŸãã
éçºã®ããã«ãWebPackãç£èŠã¢ãŒãã§å®è¡ããå¿ èŠããããŸããã¯ã©ã€ã¢ã³ããã¡ã€ã«ãå€æŽãããšãã¢ã»ã³ããªãåæ§ç¯ããããã©ãŠã¶ãŒã§ããŒãžããªããŒãããå¿ èŠããããŸãã
webpack --watch //-w shorter
WebPackã§ã¯ãäžéšã®JSãã¬ãŒã ã¯ãŒã¯ã§HotReloadã¢ãŒãããµããŒãã§ããŸããããã¯ãããŒãžãå®å šã«ãªããŒãããã«JSãšCSSãæŽæ°ããå Žåã§ãã Reactããã³Vueã§ãµããŒããããŠããŸãããæ§æãé£ãããæ£ããæ©èœããªãå ŽåããããŸãã Contosoã§ã¯äœ¿çšãããŸããã
ç§ã¯ã³ã¡ã³ããåãã§ã³ã¡ã³ãããŸãã
ã楜ãã¿ã«ïŒ