Angular 2ã¯ããŒã¿çã«å°éãã2016幎ã«ããããšã³ããã¬ãŒã ã¯ãŒã¯ã®æ å ãæã¡ç Žããã£ã³ã¹ããããŸãã 察決æéã 2015幎ã®ææã®äººãReactãšã®å¯Ÿæ¯ãèŠãŠã¿ãŸãããã
å 責äºé ïŒæåã®Angularã§äœæ¥ããŸãããã2015幎ã«Reactã«åãæ¿ããŸããã Complete React and Flux Courseãçºè¡ããŸããã ãããç§ã¯åèŠããããŸãã ããããç§ã¯äž¡åŽãæ»æããŸãã
ãããå§ããŸãããã ãããŠãè¡ããããŸãã
ããªãã¯äžžããŠæããããæ¯èŒããŸãã
*ããæ¯*ã¯ããAngularã¯ãã¬ãŒã ã¯ãŒã¯ã§ãããReactã¯ã©ã€ãã©ãªã§ãã 誰ããéãããããã®ãã®ãæ¯é¡ã®ãªããã®ã«ããŠãããšèšãã§ãããã ã©ããªã«ïŒ
AngularãšReactã®éžæã¯ããã«ãããããã¹ã¯ãããPCãéžæããããšãšãåå¥ã®ã³ã³ããŒãã³ãããç¬èªã®PCãçµã¿ç«ãŠãããšã«äŒŒãŠããŸãã
ãã®æçš¿ã§ã¯ãæ¬è³ªçã«ããã2ã€ã®ã¢ãããŒãã«ã€ããŠèª¬æããŸãã ReactãšAngularã®æ§æãšã³ã³ããŒãã³ãã¢ãã«ãæ¯èŒããŸãã ããã¯ãå®æããCPUãšraw CPU 1ãæ¯èŒããæ¹æ³ã§ãã ã€ãŸã ãœãããšãœãããæ¯èŒããŠãã ããã
Angular 2ã®å©ç¹
Reactã«å¯ŸããAngular 2ã®å©ç¹ãèŠãŠã¿ãŸããããã¯ã€ãã¯ã¹ã¿ãŒã
Angularã¯ãããå€ãã®æ©èœãããã«äœ¿çšã§ãããã¬ãŒã ã¯ãŒã¯ã§ãã Reactã§ã¯ãã¢ããªã±ãŒã·ã§ã³ããã«ãããããã«ãµãŒãããŒãã£ã©ã€ãã©ãªã®ããŒã«ããã«ããå¿ èŠããããŸãã ãã¡ãããã«ãŒãã£ã³ã°ãåæ¹åãããŒã®ç·šæãAPIãžã®ã¢ã¯ã»ã¹ããã¹ããäŸåé¢ä¿ãããŒãžã£ãŒãªã©ã®ã©ã€ãã©ãªãå¿ èŠã§ãã ãœãªã¥ãŒã·ã§ã³ã®æ°ã¯éåžžã«åºç¯å²ã§ãã ãã®ãããReactã«ã¯å€ãã®ã¹ã¿ãŒã¿ãŒããã¯ããããŸãïŒ 2〠æçš¿ããŸãã 2 ïŒã
Angularã¯ãå€ãã®ææ決å®ãè¡ãããšãæããããšãªãããã«äœ¿ãå§ããã®ã«åœ¹ç«ã€å€ãã®ããã«äœ¿ãããœãªã¥ãŒã·ã§ã³ãæäŸããŸãã çµ±åãœãªã¥ãŒã·ã§ã³ã¯ãéçºè ãéçºããã»ã¹ã«åå ¥ããããšãªããããžã§ã¯ããå€æŽããã®ã«ã圹ç«ã¡ãŸãã
Angularéçºè ãTypeScriptãç¿åŸããŠããããšãå¬ããæããŸããããã«ããã次ã®å©ç¹ãåŸãããŸã...
TypeScript =çŽåºŠã®ãã¹
ãã¡ãããTypeScriptã«ã¯æ®éçãªåŽæã¯ãããŸããããAngular 2ã§äœ¿çšããããšã¯å€§ããªåå©ã§ãã Webå šäœã§ãReactã®2ã€ã®äœ¿çšæ³ã«ééããŸããããã¯ES5ãšES6ã§ã»ãŒåãããã«è¡šããã ã³ã³ããŒãã³ãã宣èšããããã®3ã€ã®ç°ãªããªãã·ã§ã³ã«ã€ãªãããŸã ã ããã¯åå¿è ãæ··ä¹±ãããŸãã ïŒç¢ºãã«ãAngularã¯æ¡åŒµæ©èœã®ä»£ããã«ãã³ã¬ãŒã¿ã䜿çšããããšãææ¡ããŠããŸããå€ãã®äººããããå©ç¹ãšèããŠããŸãã
Angular 2ãTypeScriptãå¿ èŠãšããªãå ŽåãéçºããŒã ã¯ããã©ã«ãã§ããã¥ã¡ã³ãã§TypeScriptã䜿çšãç¶ããŸãã ããã¯ããªãŒãã³ãœãŒã¹ãããžã§ã¯ããšé¢é£ãããµã³ãã«ãã³ãŒããããåäžã«ããããšãæå³ããŸãã Angularã¯ãã§ã«TypeScriptã³ã³ãã€ã©ã®äœ¿çšæ¹æ³ã瀺ãå®äŸãæäŸããŠããŸãã ïŒç§ã¯ãTypeScriptã®åºç¯ãªæ®åããŸã å©çšå¯èœã§ã¯ãªãããšãèªããªããã°ãªããŸããããçºå£²åŸããã«ãããäºå®äžã®æšæºã«ãªããšæããŸãïŒã ãã®ã¢ãããŒãã¯ãReactã§äœæ¥ãéå§ãããšãã«çããããšã§ã¯ãªãã誀解ãé¿ããã®ã«åœ¹ç«ã¡ãŸãã
æµåºåæž
2015幎ã¯Javascriptã®ç²åŽã®å¹Žã§ããã åå¿ã¯éèŠãªèŠçŽ ã§ããã ReactãããŒãžã§ã³1.0ã«å°éããªãã£ããšããäºå®ã¯ãå°æ¥ã®éèŠãªå€æŽã«ã€ããŠæããŠãããŸãã Reactãšã³ã·ã¹ãã ã¯ãç¹ã«Fluxã·ã§ãŒããšã«ãŒãã£ã³ã°ã«é¢ããŠãæ¥æ¿ãªããŒã¹ã§çºå±ããŠããŸãã ããã¯ãReact 1.0ããªãªãŒã¹ããããšãä»æ¥æžããã¹ãŠãé³è åããå¯èœæ§ãé«ãããšãæå³ããã»ãšãã©ã®å Žåãå®å šã«æžãçŽãå¿ èŠããããŸãã
ãã®æå³ã§ãAngular 2ã¯å æ¬çãªãã¬ãŒã ã¯ãŒã¯ã培åºçãã€ç³»çµ±çã«åèãããã®ã§ãã ãããã£ãŠãAngular 2ã§ã¯ããªãªãŒã¹åŸã«ãã®ãããªé¡§å®¢ã®æµåºãé çãçºçããããšã¯ãããŸããã ãŸããå šäœçãªãã¬ãŒã ã¯ãŒã¯ãšããŠãAngularã¯1ã€ã®ããŒã ãæ瀺ããé·æçãªãœãªã¥ãŒã·ã§ã³ã«ããé©ããŠããŸãã Reactã§ã¯ãæ¥éã«éçºãããŠããå€ãã®ãªãŒãã³ãœãŒã¹ã©ã€ãã©ãªã1ã€ã®å®å®ããã¢ããªã±ãŒã·ã§ã³ã«ãŸãšãã責任ããããŸãã ããã¯ãé¢åã§äžå¿«ã§ç¶ç¶çãªããã»ã¹ã§ãã
ãŠããã¿ã¹ãµããŒã
以äžã«ç€ºãããã«ãJSXã¯çŽ æŽãããææã ãšæããŸãã ãã ããJSX察å¿ã®ããŒã«ãå¿ èŠã§ãã Reactã¯éåžžã«äººæ°ãé«ãŸã£ãŠãããããããŒã«ã¯ãã¯ãåé¡ã§ã¯ãããŸããã ããããIDEããªã³ã¿ãŒãªã©ã®æ°ããããŒã«ã¯ã 3æ¥ç®ã®åæ¥ã«ãã®åœ¢åŒãããã«ãµããŒãããããšã¯ãŸããããŸããã æååãŸãã¯åå¥ã®HTMLãã¡ã€ã«ã«æ ŒçŽãããAngularããŒã¯ã¢ãããã³ãã¬ãŒãã¯ãåå¥ã®ãµããŒãããŒã«ãå¿ èŠãšããŸããïŒãã ããAngularæååãã³ãã¬ãŒãããã®å Žã§æäœããããã®ã¹ããŒãããŒã«ã¯æ¢ã«ãããŸãïŒã Angularã¢ãããŒãã«ã¯å€ãã®èœãšãç©ŽããããReactã®å©ç¹ã®ãããã¯ã«å¯Ÿããåªããã¢ã€ã©ã€ããŒãšããŠæ©èœããŠãããšèšãããã®ã§ãã...
Reactã®å©ç¹
ã§ã¯ãReactãæäŸãããã®ãèŠãŠã¿ãŸãããã
Jsx
JSXã¯ãJavaScriptã§ã³ã³ãã€ã«ãããHTMLã«äŒŒãæ§æã§ãã ããŒã¯ã¢ãããšã³ãŒãã¯åããã¡ã€ã«ã«ãããŸãã ãã®ãœãªã¥ãŒã·ã§ã³ã䜿çšãããšãé¢æ°ãã³ã³ããŒãã³ããããã³å€æ°ãžã®ãªã³ã¯ãæ¿å ¥ã§ããŸãã éã«ãAngularã©ã€ã³ãã³ãã¬ãŒãã«ã¯æãããªæ¬ ç¹ããããŸããå€ãã®ãšãã£ã¿ãŒã«ã¯æ§æã®åŒ·èª¿è¡šç€ºããªããã³ãŒãå ã®ãšã©ãŒã®èªåã³ã³ãã€ã«ãšåŒ·èª¿è¡šç€ºã¯å®å šã«ãµããŒããããŠããŸããã ããã¯ã²ã©ããšã©ãŒã¡ãã»ãŒãžã«ã€ãªããã¯ãã§ãããAngularããŒã ã¯ç¬èªã®HTMLããŒãµãŒãäœæããŸããã ïŒãã©ããŒïŒïŒ
Angularå°æåã®ãã³ãã¬ãŒããæ°ã«å ¥ããªãå Žåã¯ããã³ãã¬ãŒããå¥ã®ãã¡ã€ã«ã«å ¥ããããšãã§ããŸããããããããæããšåŒã°ãããã®ãæã«å ¥ããããšãã§ããŸãã Reactå ã§ã®ç掻ã楜ãããŸã§ãããã¯å€§ããªåé¡ã§ã¯ãªãããã§ãã æ§æãã§ãã¯ä»ãã®åäžãã¡ã€ã«å ã®ã³ã³ããŒãã³ãã¯ããããJSXã®åªäœæ§ã®æãéèŠãªçç±ã®1ã€ã§ãã
Angular 2ãšReactãéããããŠããªãã¿ã°ãåŠçããæ¹æ³ãæ¯èŒããŠãã ããã
JSXã®å©ç¹ã®ããè¯ãç解ã«ã€ããŠã¯ã JSXïŒThe Other Side of the Coinãåç §ããŠãã ãã
ãã°ã«å¯Ÿå¿-é«éãã€æ確
Reactã®JSXã§ã¿ã€ããã¹ããããšãã³ã³ãã€ã«ããããªãã§ãããã ããã¯çŽ æŽãããããšã§ãã ãšã©ãŒãã©ã®è¡ã«ããããããã«ããããŸãã ãããéããããŠããªãã¿ã°ãŸãã¯å®£èšãããå€æ°ãžã®åç §ã§ããããšã¯æããã§ãã å®éã JSXã³ã³ãã€ã©ãŒã¯ãééããè¡çªå·ã瀺ããŸã ã ããã«ãããéçºé床ãå€§å¹ ã«åäžããŸãã
éã«ãAngular 2ã§å€æ°ã®åç §ãééããå Žåãäœãèµ·ãããŸããã Angular 2ã¯ãã³ã³ãã€ã«ããã®ã§ã¯ãªããå®è¡æã«éãã«ã¯ã©ãã·ã¥ããŸãã ãã®ãããªãšã©ãŒã¯é ãã§ãã ã¢ããªã±ãŒã·ã§ã³ãå®è¡ãããªãããŒã¿ã衚瀺ãããªãã®ãçåã«æããŸãã ããã¯ååã«æ¥œãããã®ã§ã¯ãããŸããã
React JavaScriptäžå¿4
ããã«ããã ããã¯ãReactãšAngularã®éèŠãªéãã§ãã æ®å¿µãªãããAngularã¯HTMLæåã®ãŸãŸã§ãã Angular 2ã¯ãæãåºæ¬çãªã¢ãŒããã¯ãã£ã®åé¡ã解決ã§ããŸããã§ããã
Angular 2ã¯åŒãç¶ãJSãHTMLã«å ¥ããŸãã Reactã¯HTMLãJSã«é 眮ããŸã
ç§ã¯ãã®åè£ãååã«åŒ·èª¿ããŸããã§ããã ããã¯ãéçºçµéšã«æ ¹æ¬çã«åœ±é¿ããŸãã Angular HTMLã§ã¯ãæåèšèšã¯äŸç¶ãšããŠåŒ±ç¹ã§ãã JSXïŒThe Other Side of the Coinã§åŒ·èª¿ããããã«ãJavaScriptã¯HTMLããã匷åã§ãã ããžãã¯ã§HTMLãæ¡åŒµããããããããŒã¯ã¢ãããµããŒãã®ããã«JavaScriptæ©èœã匷åããæ¹ãã¯ããã«è«ççã§ãã HTMLãšJavaScriptã¯ãŸã äœããã®åœ¢ã§çµã³ä»ããããŠããã¯ãã§ãããJavaScriptæåã®Reactã¢ãããŒãã¯ãHTMLæåã®ã¢ãããŒãã§AngularãEmberãKnockoutãããæ確ã«åªããŠããŸãã
ãããçç±ã§ã...
JavaScriptæåã®React =ã·ã³ãã«ã
Angular 2ã¯ãHTMLããã匷åã«ããããã«ãããŒãžã§ã³1ã®ã¢ãããŒããç¶ç¶ããŠããŸãã ãããã£ãŠãã«ãŒããæ¡ä»¶ã¹ããŒãã¡ã³ããªã©ã®åçŽãªãã®ã«ã¯ãAngularã®ç¹å¥ãªæ§æã䜿çšããå¿ èŠããããŸãã ããšãã°ãAngularã¯ãäžæ¹åãšåæ¹åã®ããŒã¿ãã€ã³ãã£ã³ã°ã«ç°ãªãæ§æãæäŸããŸãã
{{myVar}} //One-way binding ngModel="myVar" //Two-way binding
React, ( , , ). :
{myVar}
Angular :
<ul> <li *ngFor="#hero of heroes"> {{hero.name}} </li> </ul>
. .
- «» .
- hero . ( var).
- ngFor HTML c Angular .
Angular, React «» JS: ( key ).
<ul> {heroes.map(hero => <li key={hero.id}>{hero.name}</li> )} </ul>
JS. React JSX JS .
Angular 2 Cheat Sheet. HTML. JavaScript. Angular.
Angular Angular
React JavaScript
React . JavaScript /:
Ember: {{# each}} Angular 1: ng-repeat Angular 2: ngFor Knockout: data-bind=âforeachâ React: JUST USE JS. :)
, React, JS . React. JavaScript , .
Angular 2 :
(click)=âonSelect(hero)"
React JavaScript, :
onClick={this.onSelect.bind(this, hero)}
, , React ( Angular 2), .
, ? JS?
JSX , , . Hot Reloading with Time Travel .
/, :
Ember: 580k
Angular 2: 565k (759k with RxJS)
React + Redux: 204k
Angular 1: 145k
Tour of Heroes Angular React ( React React Slingshot)
Angular 2: 764k minified
React + Redux: 216k minified
Angular 2 React + Redux 5. ( Angular )
, .
, , , , . , , .
,
â Tom Dale
. Angular Ember .
, , . , React . 200 000 npm .
React UNIX
React . , Angular Ember. React, , , . . JavaScript , React .Unix . :
, ,React , , . . ( Angular )
Angular 2 1. , / , 3â10 . Angular 2 React. , , âJavaScript â.
Angular 2 . Angular HTML- JavaScript- React. React, HTML ngWhatever. JavaScript. .
Reddit Hacker News.
: âBuilding Applications with React and Fluxâ, âClean Code: Writing Code for Humansâ Pluralsight. VinSolutions . Microsoft MVP, Telerik Developer Expert, outlierdeveloper.com
1 â , raw CPU
2 â
3 â IDE ( MS )
4 â
5 â comparable simplicity
.. ( ) React, . , . . TypeScript ES6. :)
, !