JavaScriptã¢ããªã±ãŒã·ã§ã³ã®éçºã¯ããããªãããã¯ã§ããã人ã ã¯ã©ã®ãã¬ãŒã ã¯ãŒã¯ãéžæããã®ãè¯ãã®ããšèããŠããŸãã ãã®èšäºã§ã¯ããã®ãã¡ã®2ã€ãæ¯èŒããŸãã
MarionetteãšChaplinã¯ã人æ°ã®ããBackbone.jsã©ã€ãã©ãªã®äžã§åäœãããã¬ãŒã ã¯ãŒã¯ã§ãã ã©ã¡ãããåäžããŒãžã®JSã¢ããªã±ãŒã·ã§ã³ã®éçºãä¿é²ããããšèããŠããŸãã ãã®ãããªã¢ããªã±ãŒã·ã§ã³ã§ã¯ãããã³ããšã³ãã¯ä»¥åã«ãµãŒããŒã§å®è¡ãããŠããã¿ã¹ã¯ïŒããŒã¿ããHTMLãã¬ã³ããªã³ã°ãããªã©ïŒãå®è¡ããŸãã
Backboneã¯ãæ¬æ Œçãªãã¬ãŒã ã¯ãŒã¯ãšããŠã§ã¯ãªããæå°éã®ã©ã€ãã©ãªãšããŠèšèšãããŠããŸãã ç§ã®çµéšã§ã¯ãBackboneã¯JSã¢ããªã±ãŒã·ã§ã³ã¢ãŒããã¯ãã£ã®ã³ã¢ãšããŠã®ã¿åªããŠããããšã瀺ãããŠããŸãã Bacbonã¯å®éã®ã¢ããªã±ãŒã·ã§ã³ã«ã»ãšãã©æ§é åãæäŸããªããããPuppetãšChaplinã®äž¡æ¹ãç»å ŽããŸããã 圌ãã¯åãåé¡ã解決ããŸãã ãã®ããããããã®éã«ã¯ããªãã®æ°ã®é¡äŒŒç¹ããããŸã-ããããéããããå€ãã®ç¹ã§ãã
äœããããŸããç§ã¯ãã£ãããªã³ã®å ±èè ã§ããããšã宣èšããããšæããŸãã ããããç§ã¯PuppetãšãååããPuppetã®éçºããã©ããŒããŸããã å¥ã®éå¿çãªããã¯ããŒã³ãã¬ãŒã ã¯ãŒã¯-ThoraxããããŸãã ç§ã¯åœŒãšä»äºãããªãã£ãã®ã§ããã®æ¯èŒã«ã¯åœŒãå«ããŸããã§ããã
å 容
- éæè¡çåŽé¢
- ããã¯ããŒã³ã®æ¬ é¥ã解æ¶ããäžè¬çãªæ©èœ
- Puppetã®å©ç¹
- 人圢ã®äžå©ãªç¹
- ãã£ãããªã³ã®ã¡ãªãã
- ãã£ãããªã³ã®æ¬ ç¹
- ãããã«
éæè¡çåŽé¢
æè¡çãªè©³çŽ°ã«ã€ããŠã¯åŸã§èª¬æããŸãããããã«çŽé¢ããŸããã-ãããã®ããŒã±ãã£ã³ã°ãè©å€ãæåäºäŸãããã³ããã¥ã¡ã³ãã¯ãããã°ã©ã ãéžæãã決å®ã«å€§ãã圱é¿ããŸãã
PuppetãšChaplinã¯ãMITã©ã€ã»ã³ã¹ã®äžã§ãªãªãŒã¹ããããªãŒãã³ãœãŒã¹ãããžã§ã¯ãã§ãããGithubã§ç©æ¥µçã«éçºãããŠããŸãã èè ã¯ãããã€ãã®å€§èŠæš¡ãªããã¯ããŒã³ã¢ããªã±ãŒã·ã§ã³ã®éçºã«åå ããåãã¬ãŒããèžãå¿ èŠããªãããã«ãåªããã¢ãŒããã¯ãã£ãäœæããçµéšã移転ããŸããã
æåãªäŒæ¥ã¯PuppetãšChaplinã䜿çšããŠããŸãã 確ãã«èšãã®ã¯é£ããã§ãããå šäœçã«ãŠãŒã¶ãŒã®æ°ã¯ã»ãŒåãã§ãã Puppetãšã³ã·ã¹ãã ã¯ãã倧ãããå€ãã®äººãPuppetå šäœã§ã¯ãªãäžéšã®ã¿ã䜿çšããŠããŸãã
ãã£ãããªã³ã¯æåã¯ãã人æ°ããããŸãããã人圢ã¯åŸã«æåã«ãªããŸããã 人圢ã¯åå¿è ã«ãšã£ãŠãã芪ãã¿ããããååã«ææžåãããŠããŸããããã¯æããã«ã圌ãããããéžãã çç±ã®1ã€ã§ãã 人æ°ã®ãã1ã€ã®çç±ã¯ã人圢ã®äœæè ã§ããDaryk Baileyã®è²¢ç®ã§ããDarykBaileyã¯ãBackboneã¢ãããªã±ã®éçºã«é¢ããäžé£ã®èšäºãå·çããŸããã ãŸããäŒè°ã§è¬æŒãã ãããªã¬ãã¹ã³ãèšé²ããŠããŸãã
ããã¯ããŒã³ã®æ¬ ç¹ã解æ¶ããäžè¬çãªæ©èœ
æ··ä¹±ã®ãªãã€ãã³ãæåã®ã¢ãŒããã¯ãã£
Backbonã®éèŠãªæ©èœã¯ããã¥ãŒãšã¢ãã«éã®è²¬ä»»ã®åå²ã§ãã ã€ãã³ãïŒ Publish / Subscribe ïŒãä»ããŠå¯Ÿè©±ããŸãã
Backbone.Events
ã䜿çšãããšãã€ãã³ãæåã®ã¢ãŒããã¯ãã£ãäœæã§ããŸã ã ããã¯ãã¢ããªã±ãŒã·ã§ã³ã®åéšåãäºãã«åé¢ããã®ã«é©ããæ¹æ³ã§ãã
PuppetãšChaplinã¯ã©ã¡ãããBackboneã®ã¢ããªã±ãŒã·ã§ã³ã®ããã«ããã¯ãç¹å®ããŸãã ã€ãã³ãããªãã³ã¢ãŒããã¯ãã£ã§ã¯ãã€ãã³ããªã¹ããŒãã¯ãªã¢ããããšãéèŠã§ãã ã©ã€ããµã€ã¯ã«ã¯éèŠã§ããä»ã®ã³ã³ããŒãã³ããäœæããã³ã³ããŒãã³ãããããåé€ãã責任ããããŸãã PuppetãšChaplinã¯ããããã®åé¡ãããŸããŸãªæ¹æ³ã§è§£æ±ºããŸãã ãããªãã·ã¥/ãµãã¹ã¯ã©ã€ãã®äœ¿çšãæšå¥šããã ãã§ãªããäžè¬çãªã¢ãããŒããšã©ãŒãåé¿ããããŒã«ãæäŸããŸãã
ã¢ããªã±ãŒã·ã§ã³ã®æ§é å
ã¢ãã«ãšãã¥ãŒã¯äœã¬ãã«ã®ãã¿ãŒã³ã§ãã ããã«ãBackbonã¯Routerã®ã¿ãæäŸããŸã ã ããã¯éåžžã«èãå±€ã§ãããããããŒã³ã³ã®æãåé¡ã®ããéšåã§ãã çŽç²ãªããã¯ããŒã³ã«ãŒã¿ãŒã§ã¯ãã¡ã¢ãªç®¡çãåããéåžžã®é«ã¬ãã«ã¢ãŒããã¯ãã£ãäœæã§ããŸããã PuppetãšChaplinã¯äž¡æ¹ãšãã³ã³ãããŒã©ãŒã«ãã£ãŠå°å ¥ãããŸãã
匷åãªãã¥ãŒã®èŠå
ããŒã³ã³ã®ã·ã³ãã«ãã«åŸã£ãŠã圌ã®ãã¥ãŒãšã¬ã³ããªã³ã°ã¯æœè±¡çãªèŠçŽ ã§ãã Backboneãã¥ãŒã¯1ã€ã®DOMèŠçŽ ãæ åœããŸãããBackboneã¯ãããŒã¿ãèŠçŽ ã«æ¿å ¥ããŠããŒãžã«æ¿å ¥ããããã®ããŒã«ãããã¯ã¹ããæäŸããŸãã-ããã©ã«ãã§ã¯ã
View#render
ã¡ãœããã¯ç©ºã§ãã
PuppetãšChaplinã¯ãå ç¢ãªã¬ã³ããªã³ã°ãšã³ãžã³ãåãããã¥ãŒã¯ã©ã¹ãæäŸããŸãïŒ Marionette.ItemViewããã³Chaplin.Viewãåç §ïŒã ããã«ã Mustache / Hogan ã HandlebarsãŸãã¯HAML-coffeeãªã©ã®ãã³ãã¬ãŒãèšèªãéžæããå¿ èŠããããŸãã
äž¡æ¹ã®ã©ã€ãã©ãªã«ã¯ããã¥ãŒãã¬ã³ããªã³ã°ããã¿ã€ãã³ã°ãšãããããDOMã«åã蟌ãæ¹æ³ã«é¢ããèŠåããããŸãã ã¢ãã«ããŒã¿ããã³ãã¬ãŒãã«éä¿¡ããåã«å€æã§ããŸãã ããã¯ãèšç®ããããã£ãªã©ã«äŸ¿å©ã§ãã
ãã¥ãŒã¯ããããã¢ããªã±ãŒã·ã§ã³ã®æãé£ããéšåãªã®ã§ãPuppetãšChaplinã¯ããã«ãã«ããŒãæäŸããŸãã ãããã䜿çšããŠããã¹ãããããã¥ãŒãäœæããååä»ãé åã宣èšã§ããŸãã 宣èšçã«ã¢ãã«ã€ãã³ããç»é²ã§ããŸãïŒ
this.listenTo(this.model, ...);
ããç°¡åã§èªã¿ãããïŒã
Pure Backboneã¯ãã³ã¬ã¯ã·ã§ã³ãã¥ãŒãã¥ãŒã®ãã€ãã¹ã§ããããŸãïŒ Marionette.CompositeViewããã³Chaplin.CollectionViewãåç §ïŒã èŠããã«ãåã³ã¬ã¯ã·ã§ã³ã¢ãã«ã«åå¥ã®ãã¥ãŒã䜿çšããŸãã ããã«ãããåçŽãªæ§é åã³ãŒãã䜿çšããŠè€éãªãªã¹ããå®è£ ã§ããŸãã ã³ã¬ã¯ã·ã§ã³ãã¥ãŒã¯ããèªäœãã¹ããŒãã§ããã1ã€ã®ã¢ãã«ã®ããã«ãªã¹ãå šäœãåçæããŸããã
Puppetã®å©ç¹
人圢-æçšãªãã¿ãŒã³ã®å庫ã ã¢ãžã¥ãŒã«åŒã§ãããPuppetã®ãã¹ãŠã®éšåã䜿çšããå¿ èŠã¯ãããŸããã ããã€ãã®éšåããå§ããŠãæ®ããåŸã§çµåã§ããŸãã Puppetã®æ©èœã®äžéšã¯ãããšãã°Backbone.BabySitterãBackbone.Wreqrãªã©ãBaconã®åå¥ã®ãã©ã°ã€ã³ããæ¥ãŠããŸãã
Puppetã«ã¯ãŠããŒã¯ãªæ©èœããããŸãã ç§ã®æèŠã§ã¯ãæã匷åãªã®ã¯ã¢ããªã±ãŒã·ã§ã³ã¢ãžã¥ãŒã«ãšã¹ããŒããã¥ãŒç®¡çã§ãã
ã¢ãžã¥ãŒã«
ã¢ããªã±ãŒã·ã§ã³ã¢ãžã¥ãŒã«ã¯ã¢ãŒããã¯ãã£ã®ç¬ç«ããéšåã§ãããã«ãŒã¿ãŒãã³ã³ãããŒã©ãŒãã¢ãã«ãããã³ãã¥ãŒã§æ§æã§ããŸãã ã¢ãžã¥ãŒã«ã¯éå§ããã³åæ¢ã§ããŸãããåæ¢ããåã«å®è¡ããããããã¯ããå®çŸ©ã§ããŸãã ãŸããã«ãŒããã¢ãžã¥ãŒã«ã«èšå®ãããã«ãŒããšäžèŽããå Žåãé 延ããŒãããããšãã§ããŸãã
BBCloneMailã¯ã2ã€ã®ã¢ãžã¥ãŒã«ïŒ mailããã³contact ïŒã§æ§æããããµã³ãã«ã¢ããªã±ãŒã·ã§ã³ã§ãã ãã®äŸã§ã¯ã1ã€ã®æéã«1ã€ã®ã¢ãžã¥ãŒã«ã®ã¿ãã¢ã¯ãã£ãã§ãã ããããäžè¬çã«ãã¢ãžã¥ãŒã«ã¯äºãã«ã眮æãããããšã¯ã§ããŸããã ã¢ãžã¥ãŒã«ã«ã¯ç¬èªã®ã«ãŒã¿ãŒããããæåããèµ·åããå¿ èŠããããŸãïŒ é£çµ¡å ã«ãŒã¿ãŒãã¡ãŒã«ã«ãŒã¿ãŒ ïŒã
ã¢ãžã¥ãŒã«ã¯äºãã«å ¥ãåã«ããããšãã§ããŸãã ã¡ã€ã³ã¢ããªã±ãŒã·ã§ã³ã§ããMarionette.Applicationãã¢ãžã¥ãŒã«ã§ãã æè¡çã«ã¯ãMarionette.ApplicationãšMarionette.Moduleã«ã¯ããã€ãã®éãããããŸãããå°æ¥çã«ã¯ããåäžã«ãªãããšãé¡ã£ãŠããŸã ã
ã»ãšãã©ã®å Žåãæåããããã€ãã®ã¢ãžã¥ãŒã«ã䜿çšããå¿ èŠã¯ãããŸããããããã¯ã¢ããªã±ãŒã·ã§ã³ãå°ããªæ¥ç¶ãŠãããã«åå²ããã®ã«åœ¹ç«ã€åªããæ©èœã§ãã
ãã¥ãŒç®¡ç
Puppetã®ãã1ã€ã®åŒ·åãªéšåã¯ãã¹ããŒããã¥ãŒç®¡çã§ãã BabySitterã䜿çšãããšããã¥ãŒãç°¡åã«ãã¹ãã§ããŸãã ããã«ãPuppetã¯ã¬ã€ã¢ãŠãããªãŒãžã§ã³ãªã©ã®ããã€ãã®æœè±¡åãè¿œå ããŸãã ã¬ã€ã¢ãŠã -ååä»ãé åãå«ããã¥ãŒã ãªãŒãžã§ã³ -DOMèŠçŽ ãæ åœãããªããžã§ã¯ãã é åã®äŸã«ã¯ãããããŒãããã²ãŒã·ã§ã³ãã¡ã€ã³ããµã€ãããŒãããã³ããã¿ãŒããããŸãã
ãã¥ãŒãã¬ã³ããªã³ã°ããŠDOMã«åã蟌ãå¿ èŠãããã®ã¯ã©ãã§ããïŒ å°åã§ïŒ DOMèŠçŽ ãçŽæ¥å¶åŸ¡ãã代ããã«ãRegionãäžåºŠå®çŸ©ããŠãããããšãã°
mainRegion.show(view)
èšè¿°ããã ãã§ãã ããã«ããããã¥ãŒãã¬ã³ããªã³ã°ããããªãŒãžã§ã³ã«å¯Ÿå¿ããDOMèŠçŽ ã«è¿œå ãããŸãã ãªãŒãžã§ã³ã«ã¯äžåºŠã«1ã€ã®ãã¥ãŒããä¿æãããªããããå€ããã¥ãŒã¯ãéããŸããïŒDOMããåé€ãããã¡ã¢ãªããå®å šã«è§£æŸãããŸãïŒã
ãã¹ããããé åã䜿çšãããšãèªã¿åãå¯èœã§ãµããŒããããŠããã³ãŒãã䜿çšããã ãã§è€éãªã€ã³ã¿ãŒãã§ã€ã¹ãæ§ç¯ã§ããŸãã
人圢ã®äžå©ãªç¹
ç°¡æœã«ããããã«ãPuppetã®ãŠããŒã¯ãªæ©èœãããã€ã説æããŸããã
匱ãæœè±¡åãå¹æçãªäœ¿çšã®ããã®æ確ãªæšå¥šã¯å¥œãã§ã¯ãããŸããã
ã«ãŒãã£ã³ã°ãšã³ã³ãããŒã©ãŒ
ããšãã°ãPuppetã¯Backbone.Routerã®äžã«éåžžã«å°æ°ã®ã¢ããªã³ãæäŸããŸãã ç§ã®æèŠã§ã¯ãããã¯ããŒã³ã«ãŒã¿ãŒã¯ã次ã®ã«ãŒããã¢ã¯ãã£ãã«ãªã£ããšãã«ãäœæããããªããžã§ã¯ããã¡ã¢ãªããã¯ãªã¢ããããšã«é¢ããŠåæãæäŸããªããããããã¯éèŠã§ãã ååãšããŠã
route
ã€ãã³ãã䜿çšããŠéäžã¯ãªãŒãã³ã°ãå®è£ ã§ããŸãããããã¯æŸèæã§ãã
Puppetã«ã¯ã åæ¢ã§ããã¢ãžã¥ãŒã«ãšéããããšãã§ããé åããããŸãã ãã ããã¢ãžã¥ãŒã«ãèµ·åããã³åæ¢ãããã³ã«ããŸãã¯ãªãŒãžã§ã³ãéãããã³ã«ãæããã«é¢åãªããšã¯ãããŸããã
Marionette.AppRouterã¯æ£ããæ¹åãžã®äžæ©ã§ãã 圌ã®ã¢ã€ãã¢ã¯ãã³ãŒãããã«ãŒãæ§æãåé¢ããããšã§ãã ã«ãŒããäžèŽããå ŽåãAppRouterã¯Controllerã®å¯Ÿå¿ããã€ã³ã¹ã¿ã³ã¹ã«ã¢ã¯ã»ã¹ããŸã ã
Puppetã®ã³ã³ãããŒã©ãŒã«ã¯ç¹å®ã®ç®çã¯ãªããäœãããå¶åŸ¡ãããã ãã§ãã
Backbone.Events
ãä»ããŠã€ãã³ãããµãã¹ã¯ã©ã€ãã§ããŸãããŸãã
initialize
ã¡ãœãããš
close
ã¡ãœããã
close
ãŸãã ããã¯ééããªã䟿å©ã§ããããã€ã©ã®ããã«äœ¿çšããããèªåã§èããå¿ èŠããããŸãã éåžžãã¢ãã«ãšãã¥ãŒã¯ããã«äœæãããŸãã
ã°ããŒãã«ãªããžã§ã¯ããšãã©ã€ããŒããªããžã§ã¯ã
Puppetã§ã¯ãã¢ãžã¥ãŒã«ãšã¯ã©ã¹ã¯ã
window.BBCloneMail.MailApp.Controller
ãªã©ã®ã°ããŒãã«å€æ°ã«
window.BBCloneMail.MailApp.Controller
ãŸãã 人圢ã䜿çšãããšãã¯ã©ã¹ã®ã°ããŒãã«ã«ã¢ã¯ã»ã¹å¯èœãªã€ã³ã¹ã¿ã³ã¹ãäœæããã®ã¯é åçã§ãããããããããšã¯ãŸã£ããã¯ãŒã«ã§ã¯ãããŸããã BBCloneMailã®äŸã§ã¯ãäžéšã®ãªããžã§ã¯ãã¯é¢æ°ãã転éãããŠè¿ãããŸãããä»ã®ãªããžã§ã¯ãã¯ã°ããŒãã«ã«ã¢ã¯ã»ã¹å¯èœã§ãïŒããšãã°ã BBCloneMail.MailApp.controller ïŒã
ã³ãŒããèªããšããã©ã®ãªããžã§ã¯ããã°ããŒãã«ã«ã¢ã¯ã»ã¹å¯èœã§ãã©ã®ãªããžã§ã¯ããã°ããŒãã«ã«äœ¿çšãããŠãããã¯æããã§ã¯ãããŸããã Puppetã§ã¯ãã°ããŒãã«åå空éãªãã§ãªããžã§ã¯ããé¢é£ä»ããããšãã§ãããªããžã§ã¯ãæ©èœãã¿ãŒã³ã䜿çšããããšããå§ãããŸãã
ããã©ã«ãã®ãã³ãã¬ãŒã
ããã©ã«ãã§ã¯ããã¥ãŒã¯DOMãããã³ãã¬ãŒããèªã¿åãããã³ãã¬ãŒãã®AnderskorèšèªïŒ _.template ïŒã§ã³ã³ãã€ã«ããŸãã ã·ã³ãã«ã§ãããHTMLã«ãã³ãã¬ãŒããåã蟌ãããšã¯ãå§ãããŸããïŒããšãã°ãChromeãŠã§ãã¹ãã¢ã®ã¬ã€ãã©ã€ã³-ãªã³ã¶ãã©ã€ã§ã³ã³ãã€ã«ããããã³ãã¬ãŒãã䜿çšããã¢ããªã±ãŒã·ã§ã³ã¯ãåã«ããããèš±å¯ããŸããïŒã æåŸã«ããã³ãã¬ãŒãã¯å¥ã ã®ãã¡ã€ã«ã«ããªã³ã³ãã€ã«ãããŠããå¿ èŠããããŸãã ãããããã¡ããããããPuppetã«ç°¡åã«è¿œå ã§ããŸã-Rendererã䜿çšããã ãã§ãã
ãã£ãããªã³ã®ã¡ãªãã
Puppetãšæ¯èŒããŠãChaplinã¯ãã¬ãŒã ã¯ãŒã¯ã«äŒŒãŠããŸãã 圌ã¯ããé åºã§ãããŸããŸãªåéã§ãã匷ãåæãæã£ãŠããŸãã 圌ã¯ãRuby on Railsãªã©ã®ãµãŒããŒããŒã¹ã®MVCãã¬ãŒã ã¯ãŒã¯ãããæ§æããèŠçŽã®ååã«åŸãã¢ã€ãã¢ãåãå ¥ããŸããã Chaplinã®ç®æšã¯ãå®çžŸã®ãããã¹ããã©ã¯ãã£ã¹ãšäŸ¿å©ãªéçºç°å¢ãæäŸããããšã§ãã
ã³ãŒããŒã¹ã¯ãªãããšOOP
Chaplinã¯ãJavaScriptã§ã³ã³ãã€ã«ãããã¡ã¿èšèªã§ããCoffee Scriptã§èšè¿°ãããŠããŸãã ãã ããChaplinã¯JSã©ã€ãã©ãªã«ãããªããããChaplinäžã®ã¢ããªã±ãŒã·ã§ã³ã§ã¯ã³ãŒããŒã䜿çšã§ããªãå ŽåããããŸãã
ã³ãŒããŒã¹ã¯ãªããã䜿çšããããšã¯ãéçºãåçŽã§ãªããã°ãªããªããšãããã£ãããªã³ã®èãã®äžéšã§ãã ã³ãŒããŒã¹ã¯ãªããã¯ããJavaScript-The Good Partsããšããæ¬ã®Douglas Crockfordã®ã¬ã€ãã©ã€ã³ãå®æœããŠããŸãã æã人圢ãšããŠãChaplinã¯ECMAScript 5 Strict Modeã®äœ¿çšãä¿é²ããŠããŸã ã
coffeeã¹ã¯ãªããã䜿çšãããšã
Backbone.extend
ãããç°¡åã«ã¯ã©ã¹ãå®çŸ©ããŠç¶æ¿ã§ããŸãã
Chaplinã¯ãŸããåã¯ã©ã¹ã§ã®ã¡ãœããã®åå®çŸ©ãšcoffeã¹ã¯ãªãã
super
ïŒãŸãã¯JavaScriptã§ã®åçç©ïŒã®äœ¿çšãç©æ¥µçã«ä¿é²ããã¯ã©ã¹ã®ç¶æ¿ãæ確ã«æ©èœãããããšããŸãã ããšãã°ãã¯ã©ã¹ãšãã®åå«ã«å¯ŸããŠïŒ
View#events
ãä»ããŠïŒå®£èšçã«ã€ãã³ããå®çŸ©ãããšãäž¡æ¹ãé©çšãããŸãã
AMDãŸãã¯CommonJSãä»ããã¢ãžã¥ãŒã«å
Chaplinã«ã¯ã¢ãžã¥ãŒã«ã®äœ¿çšãå¿ èŠã§ã-CommonJSãŸãã¯AMDãããŠã³ããŸãã åã¢ãžã¥ãŒã«ã¯ããã®äŸåé¢ä¿ãå€å¥ããäœãïŒã³ã³ã¹ãã©ã¯ã¿ãŒé¢æ°ãŸãã¯åäžãªããžã§ã¯ãïŒããšã¯ã¹ããŒãããå¿ èŠããããŸãã éåžžãChaplinã§ã¯ã1ã€ã®ã¯ã©ã¹ãš1ã€ã®ã¢ãžã¥ãŒã«ã1ã€ã®ãã¡ã€ã«ã«åé¡ãããŸãã
AMDã®äœ¿çšã¯ç°¡åã§ã¯ãããŸãããreboot.jsã®ãããªããŒãããŒããŒãšr.jsã®ãããªãªããã£ãã€ã¶ãŒãç¥ãå¿ èŠããããŸãã å¥ã®æ¹æ³ãšããŠãCommonJSã¢ãžã¥ãŒã«ãšBrunchã³ã¬ã¯ã¿ãŒã䜿çšã§ããŸããããã§ã¯ãã¹ãŠãã¯ããã«ç°¡åã§ãã
人圢ã¯AMDããµããŒãããŠããŸããã匷å¶çã«äœ¿çšããããšã¯ãããŸããã
åºå®ã¢ããªã±ãŒã·ã§ã³æ§é
ãã£ãããªã³ã¯åºå®æ§é ãæäŸããŸãã ãã¹ãŠã®ã¢ã¯ã·ã§ã³ã®å€§éšåãåŠçããŸãã
-
Application
ã¯ããããã®éšåãå®è¡ããã«ãŒãã¯ã©ã¹ã§ã -
Router
ã¯Backbone.Router
眮ãæããŸã - ã«ãŒããäžèŽãããšã
Dispatcher
ã¯ã³ã³ãããŒã©ãŒãéå§ããã³åæ¢ããŸã -
Layout
ã¯ããªã³ã¯ã®ã¯ãªãã¯ãç£èŠããã¡ã€ã³ãã¥ãŒã§ã
ãã£ãããªã³ã§ã¯ããã¹ãŠã®ã«ãŒããç¹å®ããäžå¿çãªå ŽæããããŸãã ã«ãŒãã¯ãã³ã³ãããŒã©ãŒã®ã¢ã¯ã·ã§ã³ã瀺ããŸãã ããšãã°ã
cars/:id
ãªã³ã¯ãã³ãã¬ãŒãã¯ã
cars#show
ãã€ãŸã
CarsController
ã³ã³ãããŒã©ãŒã®
show
ã¢ã¯ã·ã§ã³ïŒã¡ãœããïŒã
CarsController
ãŸãã
ã³ã³ãããŒã©ãŒã¯ãã¢ãã«ãšãã¥ãŒãåæåãããå Žæã§ãïŒãµã€ãããŒããããŒçšã§ã¯ãªããç»é¢ã®äž»èŠéšåçšïŒã äžè¬ã«ãã³ã³ãããŒã©ãŒã®ã¢ã¯ã·ã§ã³ã¯éåžžãã¢ããªã±ãŒã·ã§ã³ã®1ã€ã®ç»é¢ã«å¿çããŸãã
ã¡ã¢ãªç®¡ç
Chaplinã®äž»ãªã¢ã€ãã¢ã¯ãã³ã³ãããŒã©ãŒãã¡ã¢ãªããæ¶å»ãããããšã§ãã äž»ãªã«ãŒã«ã¯ãçŸåšã®ã³ã³ãããŒã©ãŒãšãã®ãã¹ãŠã®ãããã㣠ïŒã¢ãã«ãã³ã¬ã¯ã·ã§ã³ããã¥ãŒïŒã次ã®ã³ã³ãããŒã©ãŒã§åé€ãããããšã§ãã ã«ãŒããåãã³ã³ãããŒã©ãŒã®å¥ã®ã¢ã¯ã·ã§ã³ãæããŠããå Žåã§ããå€ãã³ã³ãããŒã©ãŒã€ã³ã¹ã¿ã³ã¹ã¯åé€ãããæ°ããã€ã³ã¹ã¿ã³ã¹ãäœæãããŸãã
次ã®ã«ãŒããäžèŽãããšãã«åã®ãªããžã§ã¯ããåé€ããããšã¯ããªã³ã¯ãã¯ãªã¢ããç°¡åã§å¹æçãªæ¹æ³ã§ãã ããããããã€ãã®ãªããžã§ã¯ãã¯ãããã€ããŸãã¯ãã¹ãŠã®ã¢ã¯ã·ã§ã³ã®ããã«ã¡ã¢ãªã«ä¿æããæ¹ãè¯ãã§ãããã ãã®ç®çã®ããã«ãã¢ãã«ãšãã¥ãŒãå ±æã§ããChaplin.ComposerããããŸãã ä¿åããããªããžã§ã¯ãã次ã®ã«ãŒãã§äœ¿çšãããªãå Žåãèªåçã«ã¯ãªã¢ãããŸãã
Chaplinã®ã¢ããªã±ãŒã·ã§ã³ã§ã¯ããã¹ãŠã®ãªããžã§ã¯ããç°¡åã«ã¯ãªãŒãã³ã°ã§ããŸãã ãã¹ãŠã®Chaplinã¯ã©ã¹ã«ã¯ããªããžã§ã¯ãã䜿çšäžå¯ã«ãããã¹ãŠã®æ¥ç¶ãåé€ãã åçµ
dispose
ã¡ãœããããããŸãã
ã¯ã©ã¹ã®é衚瀺ã€ã³ã¹ã¿ã³ã¹ãšãããªãã·ã¥/ãµãã¹ã¯ã©ã€ã
ããç¥ãããŠããJavaScriptããã°ã©ãã³ã°ã«ãŒã«ã¯ãã°ããŒãã«å€æ°ãé¿ããããšã§ãããChaplinã¯ãããã䜿çšããªãããã«åŒ·å¶ããããšããŠããŸãã Chaplinã®ã¯ã©ã¹ã¯ãã°ããŒãã«åå空éã§ã¯äœ¿çšã§ããªãCommonJS / AMDã¢ãžã¥ãŒã«ã§ãã 次ã«ããã¹ãŠã®ã€ã³ã¹ã¿ã³ã¹ãé衚瀺ã«ãªããŸãã 2ã€ã®ã€ã³ã¹ã¿ã³ã¹ã¯ããã¥ãŒãšãã®ã¢ãã«ã®ããã«å¯æ¥ã«é¢é£ããŠããå Žåãé€ããçžäºã«ãªã³ã¯ããªãã§ãã ããã
ãªããžã§ã¯ãã¯ã ãããªãã·ã¥/ãµãã¹ã¯ã©ã€ããã¿ãŒã³ã䜿çšããŠãç¡é¢ä¿ãªåœ¢åŒã§çžäºã«éä¿¡ã§ããŸãã ãã®ç®çã®ããã«ã Chaplin.MediatorããããŸã ã ã¡ãã£ãšãŒã¿ãŒã¯ãçŸåšã®ãŠãŒã¶ãŒã®ã¢ãã«ãªã©ãé »ç¹ã«äœ¿çšããããã®ãä¿ç®¡ããããã«ã䜿çšã§ããŸãã å¿ èŠãªããããã£ãäœæããåŸãã¡ãã£ãšãŒã¿ã¯ã¢ããªã±ãŒã·ã§ã³ã®ã°ããŒãã«ã¬ããŒãžãã³ãã«ãªããªãããã«ã·ãŒã«ãããŸãã
ãŽã£ã·ã¥ã¯ã®ç®¡ç
ãã£ãããªã³ã¯ãã¥ãŒã®ç®¡çãåŸæã§ãã ååä»ãé åãšãã¹ãããããã¥ãŒããããŸãã Chaplinã¯ããã¥ãŒãã¬ã³ããªã³ã°ããŠDOMã«æ¿å ¥ããããã®ç°ãªãã¢ãããŒããæ¡çšããŠããŸãã ãã¥ãŒã«ã¯
autoRender
ãã©ã°ãš
container
ãªãã·ã§ã³ããããŸãã ããã§ããå Žåããã¥ãŒã¯äœæçŽåŸã«ã¬ã³ããªã³ã°ãããDOMã«èªåçã«æ¿å ¥ãããŸãã
container
ãªãã·ã§ã³ã®ä»£ããã«ãDOMèŠçŽ ã«çŽæ¥ãªã³ã¯ãã代ããã«ã以åã«ç»é²ãããé åã«ãã¥ãŒãã¢ã¿ããããããã«
region
ãæå®ã§ããŸãã
ãã£ãããªã³ã«ã¯ãã°ããŒãã«å°åã«å ããŠã
Marionette.Layout
ããã³
Marionette.Region
ããããã®æœè±¡åã¯ãããŸããã Puppetã䜿çšããã¢ããªã±ãŒã·ã§ã³ã§ã¯ãéåžžãããã€ãã®ãã¹ããããé åãšã¬ã€ã¢ãŠãããããŸãã Chaplinã䜿çšããã¢ããªã±ãŒã·ã§ã³ã§ã¯ãã¡ã€ã³ãªãŒãžã§ã³ãå°ãªããªãããããã«åã蟌ãŸãããã¥ãŒãå¢ããŸãã ãã¡ããã
ThreePaneView
ãªã©ã®
Marionette.Layout
ã®åäœã䜿çšããŠãåå©çšå¯èœãªãã¥ãŒãäœæããããšãã§ããŸãã
ãã£ãããªã³ã®æ¬ ç¹
ãã£ãããªã³ã®å ±èè ãšããŠãç§ã¯åèŠããããããããŸããã ãããã匱ç¹ãšæ¹åã®å¯èœæ§ãèŠãŠããŸãã æããã«ãããããã¯ããã€ãã®åé¡ã«å¯ŸããŠããé©åãªè§£æ±ºçãèŠã€ããŸããã
ãã§ã«è¿°ã¹ãããã«ãChaplinã¯åã³ã³ããŒãã³ãã®ã©ã€ããµã€ã¯ã«ã®æŠèŠã瀺ããŠãããããã¡ã¢ãªã®ç®¡çã«åªããŠããŸãã ããã¯ãBackboneã§Webã¢ããªã±ãŒã·ã§ã³ãäœæããéã®äž»ãªåé¡ã®1ã€ã§ãã ãã£ãããªã³ã¯ããŸãæ©èœãã解決çãèŠã€ããŸããããããã¯å®å šã§ã¯ãªãè«äºã®çã§ããããŸããã ãã®æ©èœã¯éçºãããŠãããããã«éçºãããã¯ãã§ãã
åå¿è ããã£ãããªã³ã®å šäœåãããã«ç解ããããšã¯å°é£ã§ãã Chaplinã®ã¡ã¢ãªç®¡çãã¢ãžã¥ãŒã«æ§ãããã³ãã®ä»ã®æŠå¿µã¯ãå€ãã®JavaScriptéçºè ã«ãšã£ãŠæ°ãããã®ã§ãã åæã«ãæåã«ãããã®æ©èœããè² æ ããšæãããå Žåãã¢ããªã±ãŒã·ã§ã³ã¯é·æçã«ãããã®æ©èœã®æ©æµãåããŸãã
ãããªãã·ã¥/ãããããšæ¯èŒããå Žåããããªãã·ã¥/ãµãã¹ã¯ã©ã€ãã¯ãã£ãããªã³ã®ãŠããŒã¯ãªæ©äŒã§ã¯ãããŸããã å®éãåã¢ãžã¥ãŒã«ã«ã¯ç¬èªã®ã€ãã³ãã¢ã°ãªã²ãŒã¿ãŒãä»å±ããŠãããããã¢ããªãã³ãã¯ããæè»ã§ãã
Chaplinã¯ãã€ãã³ãã®ãããŒããã£ã¹ãã ãã§ãªããã³ãã³ãã®èµ·åã«ãPub / Subã䜿çšããŸããããã¯pubsubã®æªçšã§ãã Backbone.Wreqrã¯ããã®å Žåã®ã³ãã³ã/ãªã¯ãšã¹ã/ã¬ã¹ãã³ã¹ãã¿ãŒã³ãå®è£ ããŸãã ãã£ãããªã³ã¯ãããããããã®æ©äŒãå©çšãã¹ãã§ãã
ãããã«
ããããã¯ããã¢ãžã¥ãŒã«åãããŠããã奜ããªéšåã®ã¿ã䜿çšã§ããŸãïŒã¢ããªã±ãŒã·ã§ã³ãæ¹åã§ããããããããã®ã»ãšãã©ã䜿çšããå¿ èŠããããšæããŸãïŒã åäžã®äžå€®æ§é ã®ä»£ããã«ãç¬ç«ããã¢ãžã¥ãŒã«ã§è€åã¢ãŒããã¯ãã£ãäœæã§ããŸãã ããã«ãããã³ã³ããŒãã³ããããåé¢ãããŸãããããããæ£ãã䜿çšããæ¹æ³ãç解ããå¿ èŠããããŸãã
Chaplinã¯ãã¬ãŒã ã¯ãŒã¯ã«äŒŒãŠãããäžå åããå³å¯ã§ãã Chaplinã®èè ã¯ãå¥çŽã«ãããŠãŒã¶ããªãã£ãšçç£æ§ãåäžãããšèããŠããŸãã ãããããã¡ããããã®äž»é¡ã«é¢ããããªãã®æèŠã¯ç°ãªãå ŽåããããŸãã
圌ã®ç®æšã«ããããã£ãããªã³ã¯ä»ã®å³æžé€šãããå€ãã®åé¡ãæ±ã£ãŠããŸãã ããšãã°ãBackbone.Routerã眮ãæããæ©èœè±å¯ãªã«ãŒãã£ã³ã°ããã³ãã£ã¹ãããã·ã¹ãã ããããŸãããBackbone.Historyã䜿çšããŸãã
人圢ãšæ¯èŒããŠããã£ãããªã³ã¯ã¢ããªã·ãã¯ã§ãã ããã¯ãããªããå¥ã®ããšãããããšãã§ããªããšããæå³ã§ã¯ãããŸããã åºæ¬ã¯ã©ã¹ã調æŽãå€æŽããŸãã¯å€æŽãããã¹ãŠã®ã«ãŒã«ãç Žãããšãã§ããŸãã
巚人ã®è©ã®äžã«ç«ã£ãŠ
ã§ã¯ãã©ã®ã©ã€ãã©ãªãéžæããã®ã§ããããïŒ ç§ã¯éžæãæ確ã ãšã¯æããªãã æããã«ãããŒãºã«ããé©ããã©ã€ãã©ãªäžã«ã¢ãŒããã¯ãã£ãæ§ç¯ããå¿ èŠããããŸãã ãããããã®ãã¹ããã©ã¯ãã£ã¹ãé©çšããããã®ç解ãšåŠç¿ãå¿ èŠã§ãã
Backboneã䜿çšããŠãã¹ã±ãŒã©ãã«ãªã¢ããªã±ãŒã·ã§ã³ã¢ãŒããã¯ãã£ãèªåã§éçºããå¿ èŠããããŸãã çŽç²ãªBackboneã§ã¢ããªã±ãŒã·ã§ã³ãäœæããã ãä»ã®ã¬ãŒããšåãã¬ãŒããèžãã ãããªãã§ãã ãã ã 人圢åãèžéã ãªãŒã© ããã£ãããªã³ãªã©ã®å»ºç¯ãæ£çããŠãããããç 究ããŠãã ããã
Chaplinã®äœ¿çšãéå§ããã«ã¯ãåºæ¬çãªãã€ã©ãŒãã¬ãŒãã®1ã€ã䜿çšããããšããå§ãããŸããHandlebarsãã³ãã¬ãŒãããµããŒãããCoffeeScriptãã€ã©ãŒãã¬ãŒã ããŸãã¯çŽç²ãªJavaScriptã®åçç©ã ãããã«ã¯ããã©ã«ãæ§é ãšãã¡ã€ã«ã®åœåèŠåãã³ãŒãã£ã³ã°ã¹ã¿ã€ã«ããã³ãã¬ãŒããšã³ãžã³ãªã©ãéåžžã«åœ¹ç«ã€èŠåãå«ãŸããŠããŸãã
ã¯ã€ãã¯ã¹ã¿ãŒãã®ããã«æçããéçºç°å¢ãæ¢ããŠãããªããè©ŠããŠã¿ãŠãã ãã
ãã£ãããªã³ãŸãã¯ãã£ãããªã³+ã¬ãŒã«ãã€ã©ãŒãã¬ãŒã ä»ããã©ã³ã ã
Puppetã®ããå®çšçãªçŽ¹ä»ã«ã€ããŠã¯ãSmashing Magazineã®èšäºãèªãã§ãã ããïŒ ç¬¬1éšã 第2éšïŒã Puppets wikiã«ã¯ãå€æ°ã®èšäºããããªãã¥ãŒããªã¢ã«ãããã³ãã¬ãŒã³ããŒã·ã§ã³ããããŸãã
è¬èŸ
Derik BaileyãSebastian DeutschãPaul MillerãPaul Wittmannã«ããã®èšäºã®ã¬ãã¥ãŒãšPuppetãšChaplinã®éçºãžã®è²¢ç®ã«æè¬ããŸãã