ãã®è³ªåã«çããæãæ¥ãŸããã ãã以æ¥å°ãç· ããŸãã Y. Subbotnikã®åããããã¯ã«é¢ããã¬ããŒããäŒãããã£ãã®ã§ãã ã¬ããŒãã¯éââåžžã«çããå€ãã®éèŠãªãã€ã³ããæšãŠãªããã°ãªããŸããã§ããã ãã®èšäºã¯å€ããå°ãªããå®å šçã§ãã
ãã®èšäºã§ã¯ãã¢ãŒããã¯ãã£ãã¢ãããŒããã«ãŒã«ãªã©ã倧èŠæš¡ãªWebã¢ããªã±ãŒã·ã§ã³ãæ¡åŒµå¯èœãã€ãµããŒãããæ¹æ³ã«ã€ããŠèª¬æããŸãã
Webã¢ããªã±ãŒã·ã§ã³ã§äœæ¥ããŠããå Žåãã»ãšãã©ã®æéãã³ãŒãã®äœæã«è²»ããããã°ãä¿®æ£ããŸãã æ°ããæ©èœãè¿œå ããéšåã¯ãããããã§ãã é«åºŠãªWebã¢ããªã±ãŒã·ã§ã³ã¯åžžã«å€åããŠããŸãã ä»æ¥-1è¡ãææ¥-20ãæåŸæ¥-300ã
ãµã€ãã«ã©ã®ãããªã³ãŒããããã®ãââèŠãŠã¿ãŸãããã
$(function () { // $('#button').click(function (event) { alert(this.innerHTML); }); $('#list').uberScrollerPluginStart({ "theme": "red" }); $('#lazy_thing').click(function () { $.get('/lazy/thing/body.html', doLazyLoad.bind(this)); }); /* */ });
å€ãã®å ŽåãjQeuryã§ãããã€ãã³ãããã³ã°ããããã©ã°ã€ã³ãæ¥ç¶ããajaxãªã¯ãšã¹ããå®è¡ããŸãã ãã©ã°ã€ã³ãåé€ãããšããã¹ãŠãå£ããŸãã ãã¬ãŒã ã¯ãŒã¯ããã©ã°ã€ã³ãããã³ã³ãŒããæ··åšããäžçš®ã®ã³ãŒãã®ãã€ããååŸããŸãã ãã®ãã€ãã¯ããã»ã©å€§ãããªãïŒ100è¡ç®ïŒãååãšããŠ1人ãäœæããã³ç®¡çããŸãã ã»ãšãã©ã®ãµã€ãã¯1åäœæãããŸããããŸã£ãããµããŒããããŠããªãããããµã€ãã«ãšã£ãŠããæ害ãªãã®ãããããµã€ãå šäœã®ã³ã¹ããå¢å ããå¯èœæ§ããããŸãã
ãã®ã¢ãŒããã¯ãã£ãGMailãYandex.MailãYahooïŒPortalïŒãTwitterã«é©çšãããšãã³ãŒãã®å·šå€§ãªããŒã«ïŒ10000è¡ä»¥äžïŒãåŸãããæ°äººãäœæãããŸãã 巚倧ãªãã€ãã解ãã®ã¯éåžžã«é£ãããäœãå£ããªãããã«ããã«æ··ä¹±ãããããšã¯å°é£ã§ãã Webã¢ããªã±ãŒã·ã§ã³ã¯åžžã«é²åããŠããããããã®ãããªæ··ä¹±ã¯çµ¶ãã解æãããæ··ä¹±ããªããã°ãªããŸããã
ãµã€ãã³ãŒãã¯æ§é åãããŠãããããã®ã¢ãŒããã¯ãã£ã¯é«åºŠã«æ¥ç¶ãããŠããŸãã Webã¢ããªã±ãŒã·ã§ã³ã®å Žåããã®ãããªã¢ãŒããã¯ãã£ã¯äœ¿çšã§ããŸããã
建ç¯
ã¹ã±ãŒã©ãã«ãªã¢ããªã±ãŒã·ã§ã³ã®äœæã容æã«ããããã€ãã®ã¢ãŒããã¯ãã£ã®1ã€ãæ€èšããŠãã ããã ã¢ãŒããã¯ãã£ã¯NC Zakasããåã£ããã®ã§ãæ¬åœã«æ°ã«å ¥ã£ãŠããŸãïŒåœŒã®ãã¬ãŒã³ããŒã·ã§ã³ãèŠãŠããããäœã§ãã£ãããèŠããŠãããšçŽ æŽãããã§ãããïŒãã³ãŒã¹ã§å°ãå€æŽããæçµçµæãäŸã§åãäžããŸãã
æ çµã¿
ã©ã®ã¢ããªã±ãŒã·ã§ã³ã«ããååãšããŠãã¬ãŒã ã¯ãŒã¯ãå«ãŸããŠããŸãã jQueryãMootoolsãYUIãdojoãªã©ããã¹ãŠã®ã¯ã©ã€ã¢ã³ããã¬ãŒã ã¯ãŒã¯ã¯åãªãããŒã«ããã¯ã¹ã§ãã ããŒã«ã¯ãéãæã¡ãããŒããåãã®ã«åœ¹ç«ã¡ãŸãã ããã€ãã®ããŒã«ã¯éåžžã«å¿ èŠã§ãããã»ãããéããŠãããã®ããããŸãã åºæ¬çãªããŒã«ãã»ãšãã©ãªãå Žåã¯ãBackbone.js + Underscore.jsãªã©ãããéãããŒã«ãæ¥ç¶ãããŠããŸã
人çã§ã¯ãjQueryããã¯ã¹ãMootoolsã«çœ®ãæããã®ã¯ç°¡åã§ãã jQueryãŸãã¯ãæ°ã«å ¥ãã®ã©ã€ãã©ãªãä»ããæŸæ£ããã³ã¹ãã«ã€ããŠèããŠã¿ãŠãã ããã ç°¡åã«äº€æããã«ã¯ãã©ã€ãã©ãªé¢æ°ã«ã©ãããŒãè¿œå ããå¿ èŠããããŸã-ããã¯ã¢ããªã±ãŒã·ã§ã³ã®ã³ã¢ãããããŸããã
ã³ã¢
ã©ã€ãã©ãªã©ãããŒã«å ããŠãã«ãŒãã«ã¯ä»ã®æ©èœãå®è¡ããŸããã·ã¹ãã ã®äžéšã®å¯¿åœãå¶åŸ¡ããéä¿¡ã€ã³ã¿ãŒãã§ã€ã¹ãæäŸããã¢ããªã±ãŒã·ã§ã³å šäœã®ãšã©ãŒãç£èŠããŸãã
ã¢ãžã¥ãŒã«
ã¢ããªã±ãŒã·ã§ã³ã¯ã¢ãžã¥ãŒã«ã§æ§æãããŸã-ãããã¯ã«ãŒãã«ã«ãã£ãŠç®¡çãããã¢ããªã±ãŒã·ã§ã³ã®ç¬ç«ããéšåã§ãããã«ãŒãã«èªäœã«ã¯çŽæ¥æ¥ç¶ãããŠããŸããã éãJavaScriptã¢ããªã±ãŒã·ã§ã³ã¯ãå®å®ã¹ããŒã·ã§ã³ãšåããããè€éã§ãã ISSã«ã¯ãæ°ååã®ã¢ãžã¥ãŒã«ãå«ãæ¡åŒµå¯èœãªã¢ãŒããã¯ãã£ãããããããããç¬èªã®åœ¹å²ãæãããŸãã ã¹ããŒã·ã§ã³ã¢ãžã¥ãŒã«ã¯ããŸããŸãªåœã§äœæãããããŸããŸãªææã«é ä¿¡ãããå€ãã®ã¢ãžã¥ãŒã«ããããŸããããããã¯ãã¹ãŠå šäœãšããŠæ©èœããŸãã
HTML + CSS + JavaScript +ãªãœãŒã¹ã§æ§æãããWebã¢ããªã±ãŒã·ã§ã³ã¢ãžã¥ãŒã«
ã¢ãžã¥ãŒã«ãªãœãŒã¹-ããŒã«ãªãŒãŒã·ã§ã³ãèšè¿°åãããã³ãã®ä»ã®ãã©ã€ããŒãã¢ãžã¥ãŒã«ããŒã¿ã
åã¢ãžã¥ãŒã«ã¯ãã¢ããªã±ãŒã·ã§ã³å šäœãšã¯å¥åã«ååšããå¿ èŠããããŸãã åã¢ãžã¥ãŒã«ã®ã¿ã¹ã¯ã¯ãçŠç¹ãçµã£ãæ©èœãå®è¡ããããšã§ãã ã¢ãžã¥ãŒã«ã¯åé¢ããå¿ èŠããããã¢ãžã¥ãŒã«ãä»ã®ã¢ãžã¥ãŒã«ã«ã€ããŠç¥ããªãã»ã©ãã¢ããªã±ãŒã·ã§ã³å šäœãç°¡åã«ãµããŒãã§ããããã«ãªããŸãã æ°ããã³ãŒããäœæããŠäŸåé¢ä¿ãè¿œå ãããšãã¯ãææ¥ãããæšãŠãå¿ èŠããããšèããŠãã ããã
匱ãæ¥ç¶æ§ã確ä¿ããã¢ãžã¥ãŒã«ã®èªç±åºŠãå¶éããã«ã¯ãç¹å¥ãªäžçšåºŠã®ãªããžã§ã¯ãã§ãããµã³ãããã¯ã¹ã§å²ãå¿ èŠããããŸãã åã¢ãžã¥ãŒã«ã¯ãã®ãµã³ãããã¯ã¹å ã«ããããããšã®ã¿éä¿¡ããå¿ èŠããããŸãã ããã¯ãã¢ãžã¥ãŒã«ãç¥ã£ãŠããå¯äžã®ãªããžã§ã¯ãã§ãã ãµã³ãããã¯ã¹ã®åœ¹å²ã¯ç°¡åã§ãã 圌女ã¯èŠåå¡ãšããŠè¡åããŸããã¢ãžã¥ãŒã«ãäœãã§ããããã¢ãžã¥ãŒã«ã誰ãšéä¿¡ã§ããããç¥ã£ãŠããŸãã ãµã³ãããã¯ã¹ã¯ãã¢ãžã¥ãŒã«ãšã«ãŒãã«éã®æ¥ç¶ãæäŸããŸãã
ã¢ãžã¥ãŒã«ã¯ãã®ã¡ãœãããšãµã³ãããã¯ã¹ãåŒã³åºããç¬èªã®HTMLèŠçŽ ã䜿çšã§ããŸãã ã¢ãžã¥ãŒã«ã¯ãã¢ã¯ã·ã§ã³ãå®è¡ããåã«èš±å¯ãæ±ããå¿ èŠããããŸãã ã¢ãžã¥ãŒã«ã¯ãã°ããŒãã«ã®äœæãéæšæºã°ããŒãã«ã®äœ¿çšãä»ã®ã¢ãžã¥ãŒã«ãšã®çŽæ¥éä¿¡ãçŠæ¢ãããŠããŸãã
ãµãã¢ãžã¥ãŒã«
åã¢ãžã¥ãŒã«ã¯ãç¬èªã®ã«ãŒã«ãæã€ããšãã§ãããã€ã¯ãã¢ããªã±ãŒã·ã§ã³ãšããŠæ©èœããŸã;ã«ãŒã«ã¯ã°ããŒãã«ãªã«ãŒã«ãšççŸããã¹ãã§ã¯ãããŸããã åã¢ãžã¥ãŒã«ã¯ããã®ãµã³ãããã¯ã¹ããã®ããŒãã«å§ä»»ããä»ã®ã¢ãžã¥ãŒã«ãæ¥ç¶ã§ããŸãïŒãããžã§ã¯ãã®ã¢ã»ã³ããªäžïŒã
ã«ãŒãã«ã¯ãã¢ãžã¥ãŒã«ããã®ããŒããã©ã®ããã«ç®¡çããããæ°ã«ããŸãããåã¢ãžã¥ãŒã«ã®ã°ããŒãã«ã«ãŒã«ãå°éãããããšãéèŠã§ãã
å£åŸ
ã·ã¹ãã å ã®æ¥ç¶æ°ãæžããã«ã¯ãå³æ ŒãªåŸå±ãå¿ èŠã§ã
-ã©ã€ãã©ãªãŒã®ã¿ããã©ãŠã¶ãŒãšæ¢åã®APIã«ã€ããŠç¥ã£ãŠãã
-ã³ã¢ã®ã¿ãã©ã€ãã©ãªã«ã€ããŠç¥ã£ãŠãã
-ãµã³ãããã¯ã¹ã®ã¿ãã«ãŒãã«ãèªèããŸã
-åã¢ãžã¥ãŒã«ã¯ããµã³ãããã¯ã¹ã«ã€ããŠã®ã¿ç¥ã£ãŠããŸã
ã©ã®ãªããžã§ã¯ããã¢ããªã±ãŒã·ã§ã³å šäœãèªèãã¹ãã§ã¯ãããŸããã
ã¢ããªã±ãŒã·ã§ã³ã¯åžžã«å€åããŠããå¿ èŠããããŸãã ãŠãŒã¶ãŒã¯æ°ããæ©èœãå¿ èŠãšããŠããŸã-ãããè¿œå ããŸãã ãã©ãŠã¶ã«æ°ããæ©èœãè¿œå ãããŸãã-ãããåºå®ããŸãã
ãããã£ãŠãåãªããžã§ã¯ãã¯å€æŽããå¿ èŠããããŸã
-ãã©ã°ã€ã³ãåå ã§ã©ã€ãã©ãªãæ¡åŒµãããŠãã-ãã©ãŠã¶ãæ°ããAPIãååŸãã-ãã©ã°ã€ã³ãè¿œå ãã
-æ¡åŒµã«ããã«ãŒãã«ãæŽæ°ãããŸã-ãããã³ã«ãXMLããJSONã«çœ®ãæããéä¿¡ãããããŒã¿ã®åœ¢åŒãå€æŽããAJAXãã©ã³ã¹ããŒããå€æŽããŸãã-æ¡åŒµãè¿œå ããŸãã
-ã¢ãžã¥ãŒã«ãåå ã§ã¢ããªã±ãŒã·ã§ã³å šäœãæ¡å€§ããŠããŸã-ãŠãŒã¶ãŒã¯æ°ããæ©èœãå¿ èŠã§ã-ã¢ãžã¥ãŒã«ãè¿œå ããŸã
ã³ãã¥ãã±ãŒã·ã§ã³
HTML DOMãã€ãã³ãã§ããµããŠããããšã¯èª°ããç¥ã£ãŠããŸãã ã€ãã³ãã¯ã©ãã«ã§ããããŸã-èŠçŽ ã«ã¯ããããããAPIïŒXHRãã¯ãŒã«ãŒïŒã«ãããŸãã DOMã®ã€ãã³ãã«ãããããã¥ã¡ã³ããªããžã§ã¯ãã¢ãã«ãç¡æéã«æ¡åŒµããæ¡åŒµå¯èœãªã¢ããªã±ãŒã·ã§ã³ãäœæã§ããŸãã ã€ãã³ãã¯Webã¢ããªã±ãŒã·ã§ã³ã®æé©ãªããŒã¹ã§ãããšèããŠããŸãã
äŸãèããŠã¿ãŸãããïŒ
var Module1 = { "someAction": function () { Module2.getSomeValue(); } }; var Module2 = { "getSomeValue": function () { return 'data'; } };
éåžžã®ã¹ããŒã ã§ã¯ãã¢ãžã¥ãŒã«ã¯äºãã«çŽæ¥éä¿¡ããŸãã ã¢ãžã¥ãŒã«1ã¯ãã¢ãžã¥ãŒã«2ãšãã®
getSomeValue()
ã¡ãœããã«äŸåããŸãã ã¢ãžã¥ãŒã«2ãåé€ãããšããã¹ãŠãå£ããŸãã
ã¡ãœããåŒã³åºããã€ãã³ãã«çœ®ãæããããå Žåãã¢ãžã¥ãŒã«ã¯ç¬ç«ããŸãïŒççµåãããŸãïŒã
// var Module1 = { "init": function ($) { $.on('event', function (e) { // $ - jQuery, sandbox console.log(e.data); }); } }; var Module2 = { "someAction": function ($) { // $ - jQuery $.trigger('event', 'data'); } };
ã¢ãžã¥ãŒã«1ã§ã¯ãã€ãã³ãã€ãã³ãããªãã¹ã³ããŸããã¢ãžã¥ãŒã«2ã¯ãããã€ãã®ããŒã¿ã§ã€ãã³ãã€ãã³ããçºçãããã€ãã³ããã³ãã©ãŒã¯ããŒã¿ãã³ã³ãœãŒã«ã«æç»ããŸã
ã¯ããã¢ãŒããã¯ãã£ã¯å€§ããå€åããŠããŸããã匷åãªæ¥ç¶ãåãé€ãã€ã€ãããŸãã
éåæé¢æ°
ã€ãã³ãã«ã¯å¿ ç¶çã«éåææ§ã䌎ããããHTML DOMã«ã¯éåæã¡ãœãããè±å¯ã§ããããšã¯èª°ããç¥ã£ãŠãããšæããŸãã XHRãJSONPããã¬ãŒã ãããã¬ãŒã ãžã®ããŒã¿ã®éä¿¡ãã¯ãŒã«ãŒãžã®ããŒã¿ã®éä¿¡ãããã³ãã®éã éåæããã°ã©ãã³ã°ã¯ããè€éã§ããããã®äœ¿çšãåžžã«æ£åœåããããšã¯éããŸããã ãããããã®å Žåãéåæé¢æ°ã¯éåžžã«äŸ¿å©ã§ãã
äŸãèŠãŠã¿ãŸãããïŒ
// var Storage = { "read": function (key) { return localStorage[key]; } }; var data = Storage.read('key'), pData = process(data); $.trigger('data', pData);
ããã€ãã®ãŠãŒã¶ãŒããŒã¿ã
localStorage
ã«ä¿åãããããåæçã«æäœãããã¹ãŠãããŸããããšä»®å®ã
localStorage
ã ãŸããåãããŒã¿ããµãŒããŒã«ä¿åãããŸã§ã¯ãäœããå€æŽããå¯èœæ§ãéåžžã«é«ãã§ãã åæã³ãŒããéåæã«å€æããããšã¯ãã€ãã³ãã¢ãã«ã§ãã£ãŠã倧ããªåé¡ã«ãªãå¯èœæ§ããããŸãã
localStorageã眮ãæããŠã³ãŒããããçŽããŸãããïŒ
// var Storage = { "read": function (key, cb) { $.get('/read/' + key, cb); } }; Storage.read('key',function(data) { var pData = processData(data); $.trigger('data', pData); }.bind(this));
ã·ã³ãã«ãªããŒã¿åéæ©èœãš10è¡ã®ãœãŒã¹ã³ãŒãããããŸããã 1è¡è¿œå ãã4è¡å€æŽããŸããã å€æŽã®ã»ãŒ50ïŒ ãåãåããŸããïŒæ¬åŒ§ãèæ ®ããŸããïŒã ã€ãã³ãçšã§ãªãå Žåã¯ãã¹ãã¬ãŒãžã䜿çšããã³ãŒããå€æŽããå¿ èŠããããŸããã ããŒã¿ã®ååŸãšä¿åã®æ©èœã§éåæã¢ãããŒãã䜿çšãããšãå°æ¥ã®ããã€ãã®åé¡ãã身ãå®ãããšãã§ããŸãã
ååãšããŠããã¹ãŠã®éåæã¡ãœããã¯ããŒã¿ã®éåä¿¡ïŒXHRããã±ãŒã·ã§ã³APIããã¡ã€ã«APIïŒã«é¢é£ä»ããããŠãããããããŒã¿ãä¿åããã³åä¿¡ãããã¹ãŠã®æ©èœãéåæã«ããããã€ãã³ããæ¥ç¶ããããšããå§ãããŸãã
ãã®ãããªã¢ãŒããã¯ãã£ã®å©ç¹
- çµæã®ãã¬ãŒã ã¯ãŒã¯ãã¢ãžã¥ãŒã«ãšãã©ã°ã€ã³ã®ã»ããã«åºã¥ããŠãããã€ãã®ã¢ããªã±ãŒã·ã§ã³ãäœæã§ããŸã
- åã¢ãžã¥ãŒã«ãåãã©ã°ã€ã³ãåå¥ã«ãã¹ãã§ããŸãã ããã¯ãã¢ããªã±ãŒã·ã§ã³å šäœããã¹ãããã®ã«æ¯ã¹ãŠéåžžã«æçã§ãã
- ã¢ããªã±ãŒã·ã§ã³ãæè»ã«ã¹ã±ãŒãªã³ã°ã§ããŸã-ã¢ããªã±ãŒã·ã§ã³ã®ããã€ãã®éèŠãªéšåãå€æŽãããããšãæããã«ã¢ãžã¥ãŒã«ãå€æŽãè¿œå ããŸã
- ã€ãã³ãã¯ã¢ããªã±ãŒã·ã§ã³ã®æ¥ç¶æ§ãäœäžãããŸã
- ããŒã¿ãåŠçããå°æ¥ã®ã°ããŒãã«ãªå€æŽã«åããéåææ©èœ
ãããã¯ã JãSubbotnikã®ã¬ããŒãããã®æç²ã§ã ã ãµãããããã¯ã§ã¯ãçè«ãå®è·µã§èª¬æããããšãçŽæããŸããã çè«çã«ã¯ãã¹ãŠçŸããã§ãããå®è·µã®ãªãçè«ã¯ã»ãšãã©äŸ¡å€ããªãã®ã§ãã¢ãŒããã¯ãã£ã«åºã¥ããŠã¢ããªã±ãŒã·ã§ã³ãäœæããŸãããã
äŸïŒä¿å®ãç°¡åãªã¹ã±ãŒã©ãã«ãªJavaScriptã¢ããªã±ãŒã·ã§ã³
ã¢ããªã±ãŒã·ã§ã³ãäœæããããã¢ããªã±ãŒã·ã§ã³ã®ã¹ã¿ããäœæããŸãïŒèšäºã¯éåžžã«å€§ããããããã®éšåãæžãããŸãïŒãã¢ãžã¥ãŒã«æ§ã瀺ããŸãã ã¢ããªã±ãŒã·ã§ã³ãå«ãŸããŸãïŒ
- ã³ã¢
- ãµã³ãããã¯ã¹
- ã¢ãžã¥ãŒã«ïŒããã¹ãã衚瀺ããã¢ãžã¥ãŒã«ã ã¿ã€ããŒã€ãã³ããçæããã¢ãžã¥ãŒã«ã ãã®ã€ãã³ãããã£ã«ã¿ãªã³ã°ããã¢ãžã¥ãŒã«ã ããã€ãã®ã€ãã³ããã³ã³ãœãŒã«ã«èšé²ããã¢ãžã¥ãŒã«ã
å³æžé€šãšãã¯ãããžãŒ
ãã€ãã®ããã«ãjQueryããããŸãã ã¬ã€ã¢ãŠããæŽçããããã«ãåçŽåãããBEMãã¯ãããžãŒïŒãããã¯ãèŠçŽ ã修食åïŒã䜿çšããŸãã ã¹ã¯ãªããã®åçãªèªã¿èŸŒã¿ã«ã¯ã$ script.jsã䜿çšããŸãã ãã³ãã¬ãŒã-Rezigããå€æŽããããã³ãã¬ãŒããšã³ãžã³ã
ãããžã§ã¯ãæ§é
/app /css - /blocks /b-module-name /b-module-name.css ... ... /pages /index.css ... /descriptors - /ModuleName.json ... /locales - /ModuleName.json ... /modules - /ModuleName.js ... /templates - /ModuleName.html ... /views - /ModuleName.html ... /build - /lib - /Core.js /test - /lib /qunit.css /qunit.js /ModuleName - ModuleName /index.html /index.js /TestData.js - /vendors - /Script.js /jQuery.js ... /index.html - /index.js - js , /index.json - ...
ã¢ãžã¥ãŒã«
æåã«ã¢ãžã¥ãŒã«ããå§ããŸãããã ã¢ãžã¥ãŒã«ã®åéšåã¯ãåçããã³éçã«æ¥ç¶ããå¿ èŠããããŸãïŒ1ã€ã®ãã¡ã€ã«ã«ã¢ã»ã³ãã«ããå ŽåïŒããŸãã¯ãã®äž¡æ¹ã éçºè ã«ãšã£ãŠãã¹ãŠãå¯èœãªéãééçã§ããå¿ èŠããããŸããã¢ãžã¥ãŒã«ããããŸã-ããã䜿çšããŸããããã-ããŠã³ããŒãããŠäœ¿çšããŸãã
ç§ãã¡ã®ã¢ãžã¥ãŒã«ã¯ããã€ãã®éšåã§æ§æãããŸãïŒ
- ãµã³ãã«ã¬ã€ã¢ãŠãïŒã¹ã¿ã€ã«ãæ¥ç¶ãããHTMLãã¡ã€ã«ã ãã®ãã¡ã€ã«ã¯åäœãã¹ãã§äœ¿çšããããµã³ãã«ãååŸããŠãã³ãã¬ãŒããäœæã§ããããã«ã¢ãžã¥ãŒã«ãã©ã®ããã«èŠãããã瀺ããŸãã
- ãã³ãã¬ãŒãïŒã¢ãžã¥ãŒã«ã䜿çšããHTMLãããã¯ã
- ã¹ã¿ã€ã«ãšç»åïŒåçŽãªCSSãã¡ã€ã«ãŸãã¯ç»åãã¡ã€ã«
- JavaScriptïŒã¢ãžã¥ãŒã«ã³ãŒã
- èšè¿°åïŒã¢ãžã¥ãŒã«ã®ååãèšå®ãããã³ãªãã¹ã³ããŠçæã§ããã€ãã³ãã®ãªã¹ããå«ãJSONãã¡ã€ã«ã åäœãã¹ããèªåçæããããã«äœ¿çšãããæš©å©ãåºå¥ããããã«ãµã³ãããã¯ã¹ã«ãã£ãŠäœ¿çšãããŸãã
- ããŒã«ãªãŒãŒã·ã§ã³ïŒç°ãªãèšèªã®ããã¹ããå«ãJSONãã¡ã€ã«
ã¢ãžã¥ãŒã«ã®äŸïŒDataGeneratorã¢ãžã¥ãŒã«ïŒ
(function(global){ "use strict"; var intervalId; var DataGenerator = { init: function (sandbox) { intervalId = setInterval(function () { sandbox.trigger('newData', Math.random()); }, sandbox.getResource('interval')); }, destroy: function () { clearInterval(intervalId); } }; // if (!global) { return DataGenerator; } if (!global.exports) { global.exports = {}; } global.exports.DataGenerator = DataGenerator; }(this)) // ; !
ã³ãŒãã«å€ãã®ãŽããããããšã«åæããŸãã ã¢ãžã¥ãŒã«ã®èŠä»¶ã®ããã«ããŸãã«ãã®ãããªåœ¢åŒããããŸããæš©åšäž»çŸ©ã«ãŒãã«ã¯ãã¢ãžã¥ãŒã«èªäœãæ¥ç¶ããéçããã³åçã®äž¡æ¹ã«æ¥ç¶ã§ããŸãã JavaScriptèªäœã«ã¯ã¢ãžã¥ãŒã«ããªãããããããããç¬èªã®å€èŠ³ãäœæããŸãã ã æšæºç㪠ããã®ãããã€ããããŸãããå€ãã®å Žåãç¹å®ã®ã¿ã¹ã¯çšã®èªè»¢è»ã§ãã
èšè¿°åã®äŸïŒDataGeneratorã¢ãžã¥ãŒã«ïŒ
{ "name": "DataGenerator", "acl": { "trigger:newData": true // newData }, "resources": { "interval": 1000 } }
ãã±ãŒã«ã®äŸïŒMessageViewã¢ãžã¥ãŒã«ïŒ
{ "text_label": { "ru": " : ", "en": "He said: " } }
ãµã³ãã«ãã³ãã¬ãŒãïŒMessageViewã¢ãžã¥ãŒã«ïŒ
<div class="b-message-view"> <span class="b-message-view__label">{%=label%}</span> <span class="b-message-view__value">{%=value%}</span> </div>
ãã®åœ¢åŒã®é·æ
åè«çéšåã¯åå¥ã§ãã ãã¹ãŠã®ããŒããç¹°ãè¿ã䜿çšã§ããŸãã ããšãã°ãèšè¿°åã䜿çšããŠãåäœãã¹ãã®ã¹ã±ã«ãã³ãèªåçã«çæã§ããŸãã
ã³ã¢
ã¢ãžã¥ãŒã«ãããŠã³ããŒãããŠç»é²ããå¿ èŠããããŸãã ããã¯ãã¢ã»ã³ããªäžãšåçã®äž¡æ¹ã§å®è¡ã§ããå¿ èŠããããŸãã jQuery Defferedã¯éåžžã«åœ¹ç«ã¡ãŸãã ã¢ãžã¥ãŒã«ã®1ã€ã®éšåã®ããŒãããã»ã¹ã¯å®éã«ã¯ä»ã®éšåãšå€ãããªããããå€ãã®éšåããããããããŒãæ©èœã®çç£çšã®å·¥å Žãéžæããå¿ èŠããããŸãã
var loaderFactory = function (cacheObject, method, format, methodOwner, type) { return function (name) { var dfd = $.Deferred(), self = this; if (cacheObject[name]) { dfd.resolve(); return dfd.promise(); } function successOrFail(object) { var camelCasedType = type.slice(0, 1).toUpperCase() + type.slice(1); self['push' + camelCasedType](name, object); dfd.resolve(); if (object) { // if fail EventManager.trigger(type + ':loaded', {name: name}); EventManager.trigger(type + ':' + name + ':loaded'); } } var path = Core.descriptor.path[type] + format.replace('$0', name); if (type === 'module') { method.call(methodOwner, path, successOrFail); } else if (type === 'template') { method.call(methodOwner, path, successOrFail, 'html').error(successOrFail); } else { method.call(methodOwner, path, successOrFail).error(successOrFail); } return dfd.promise(); } };
ã¢ãžã¥ãŒã«ãããŒãžã£ãŒ
ã¢ãžã¥ãŒã«ãããŒãžã£ã¯ãåã«ã¢ãžã¥ãŒã«ã®äžéšãããŒãããŠãã£ãã·ã¥ããŸãã ããŒãããã«ã¢ãžã¥ãŒã«ãç»é²ããããã®å€ãã®ã¡ãœããããããŸãïŒéçã¢ã»ã³ããªïŒã
var ModuleManager = { modules: {}, descriptors: {}, locales: {}, templates: {}, pushModule: function (name, module) {}, pushDescriptor: function (name, descriptor) {}, pushLocale: function (name, locale) {}, pushTemplate: function (name, template) {}, load: function (name) {} }; ModuleManager.getModule = loaderFactory(ModuleManager.modules, require, '$0.js', this, 'module'); ModuleManager.getDescriptor = loaderFactory(ModuleManager.descriptors, $.getJSON, '$0.json', $, 'descriptor'); ModuleManager.getLocale = loaderFactory(ModuleManager.locales, $.getJSON, '$0.json', $, 'locale'); ModuleManager.getTemplate = loaderFactory(ModuleManager.templates, $.get, '$0.html', $, 'template');
ãªããžã§ã¯ãã®ã¹ã±ã«ãã³ãæ®ããŠãã¹ããŒã¹ãããŸã䜿çšããªãããã«ããŸããã ãããã«ããŠãã誰ãèªãŸãªãã ãœãŒã¹ã«ãã«ããŒãžã§ã³ã
ãã³ãã¬ãŒããšã³ãžã³
John Resigã®ã·ã³ãã«ãªãã³ãã¬ãŒããšã³ãžã³ã䜿çšããŸã
var templateFactory = function(str, data) {}
ã€ãã³ããããŒãžã£ãŒ
ã€ãã³ããããŒãžã£ã¯ãã€ãã³ãã®ç»é²ãåé€ãåŒã³åºããè¡ããŸãã ã¢ããªã±ãŒã·ã§ã³ã®ãã¹ãŠã®ã°ããŒãã«ã€ãã³ããééããŸãã ç§ãã¡ã¯è»èŒªãåçºæããŸããã EventManagerã¯ãæšæºã¡ãœããã«å ããŠ
jQuery.bind jQuery.trigger jQuery.unbind
jQuery.unbindã䜿çšããŸãã
jQuery.bind jQuery.trigger jQuery.unbind
ããããããã¯é¢æ°ãã€ãã³ãã«ããã¯ããŸãã ããã¯é¢æ°ã¯ãã€ãã³ããã©ã¡ãŒã¿ã®å 容ãå€æŽã§ããŸãããŸããã€ãã³ããåŒã³åºãããã®ãé²ãããšãã§ããŸãã
var EventManager = { $: $('<div/>'), hooks: {}, trigger: function (event, data) { if (this.hooks[event]) { // Update event data var result = this.hooks[event](data); // Don't trigger event if (result === false) { return this; } // Trigger with new data data = result || data; } this.$.trigger.apply(this.$, [event, data]); return this; }, bind: function () {}, unbind: function () {}, hook: function (event, hookFunction) { // One hook for example this.hooks[event] = hookFunction; return this; }, unhook: function (event) { delete this.hooks[event]; return this; } };
ã°ããŒãã«ã€ãã³ããããŒãžã£ãŒã®äœ¿çšã«ã¯1ã€ã®éèŠãªå©ç¹ããããŸããã€ãã³ããã°ãèšé²ãããã°ããã€ãã³ãã®ã³ãŒã¹ã埩å ã§ããŸãïŒãŠãŒã¶ãŒåŽã§ãã°ããã£ããããã®ã«äŸ¿å©ã§ãïŒã
ã³ã¢
var Core = { descriptor: {}, runningModules: {}, // , init: function (descriptorOrFileName, callback) {}, // _initModules: function (callback) {}, // initModule: function (name, callback) {}, // destroyModule: function (name) {}, // HTMLElement getBox: function (name) {}, // getTemplateFunction: function (moduleName, templateSelector) {} };
é¢æ°æ¬äœãšJSDocãããã¯ãåé€ããŸããã
å€éšããã¯ããã¹ãŠã®ã«ãŒãã«ã¢ãžã¥ãŒã«ã®ã¡ãœããã®ã¿ãå¿ èŠã§ãã ãããã®ã¿ããšã¯ã¹ããŒãããŸãã
var CorePublic = { trigger: $.proxy(EventManager.trigger, EventManager), bind: $.proxy(EventManager.bind, EventManager), unbind: $.proxy(EventManager.trigger, EventManager), on: $.proxy(EventManager.bind, EventManager), getModule: $.proxy(ModuleManager.getModule, ModuleManager), getDescriptor: $.proxy(ModuleManager.getDescriptor, ModuleManager), getLocale: $.proxy(ModuleManager.getLocale, ModuleManager), getTemplate: $.proxy(ModuleManager.getTemplate, ModuleManager), pushModule: $.proxy(ModuleManager.pushModule, ModuleManager), pushDescriptor: $.proxy(ModuleManager.pushDescriptor, ModuleManager), pushLocale: $.proxy(ModuleManager.pushLocale, ModuleManager), pushTemplate: $.proxy(ModuleManager.pushTemplate, ModuleManager), init: $.proxy(Core.init, Core), destroyModule: $.proxy(Core.destroyModule, Core), initModule: $.proxy(Core.initModule, Core), getTemplateFunction: $.proxy(Core.getTemplateFunction, Core) };
ãµã³ãããã¯ã¹
åã¢ãžã¥ãŒã«ã«ã¯ç¬èªã®ãµã³ãããã¯ã¹ãããããããµã³ãããã¯ã¹ãçæãããµã³ãããã¯ã¹ã³ã³ã¹ãã©ã¯ã¿ãŒãäœæããŸãã ãµã³ãããã¯ã¹ã¯åŒæ°ãšããŠã¢ãžã¥ãŒã«èšè¿°åãåãåããŸãã ãã¹ãŠã®ãµã³ãããã¯ã¹ã¡ãœããã§ã¢ãžã¥ãŒã«ã䜿çšã§ããŸãã
var Sandbox = function (descriptor) { this.descriptor = descriptor || {}; }; Sandbox.prototype.getBox = function () {}; // - Sandbox.prototype.is = function (role) {}; Sandbox.prototype.bind = function (event, callback) {}; Sandbox.prototype.unbind = function (event, callback) {}; Sandbox.prototype.trigger = function (event, data) {}; Sandbox.prototype.hook = function (event, hookFunction) {}; Sandbox.prototype.unhook = function (event) {}; Sandbox.prototype.getText = function (message) {}; Sandbox.prototype.getResource = function (resource) {}; Sandbox.prototype.getTemplate = function (templateSelector) {};
ä»ã®ãªããžã§ã¯ãã«åœ±é¿ãäžããå¯èœæ§ã®ããé¢æ°ïŒ
bind, trigger, hook,
ïŒã§ã¯ããµã³ãããã¯ã¹ã¯ãã®ã¢ãžã¥ãŒã«ã§ïŒã¢ãžã¥ãŒã«èšè¿°åã䜿çšããŠïŒãã®é¢æ°ãå®è¡ã§ãããã©ããããã§ãã¯ããŸãã
ã«ãŒãã«ã¢ã»ã³ããª
ã«ãŒãã«ã®åéšåã¯å¥ã ã®ãã¡ã€ã«ã«çœ®ãããããªããã»ããµã«ãã£ãŠäžç·ã«ã¢ã»ã³ãã«ãããå¿ èŠããããŸãããã®äŸã§ã¯ããªããã»ããµã䜿çšããŠããŸããïŒç空ç¶æ ã§ã¯çç¶ã§ãïŒã
(function(global, $, require, undefined){ "use strict"; var templateFactory = function(str, data){}; var loaderFactory = function (cacheObject, method, format, self, type) {}; var ModuleManager = {}; var Sandbox = function (descriptor) {}; var EventManager = {}; var Core = {}; var CorePublic = {}; if (!global) { return CorePublic; } if (!global.exports) { global.exports = {}; } global.exports.Core = CorePublic; }(this, jQuery, $script));
ã¢ããªã±ãŒã·ã§ã³èšè¿°å
ãŸããã¢ããªã±ãŒã·ã§ã³ã«ã¯ãã¢ããªã±ãŒã·ã§ã³ã«å«ãŸããã¢ãžã¥ãŒã«ãã¢ãžã¥ãŒã«ã®åéšåã®é 眮ãçŸåšã®ãã±ãŒã«ã®æ±ºå®ãåºæ¬çãªããŒã¯ã¢ããã®èšè¿°ãèšè¿°ããèšè¿°åããããŸãã ç°ãªãã¢ã»ã³ããªã«å¯ŸããŠè€æ°ã®èšè¿°åãååšããå ŽåããããŸãã
{ "modules": ["MessageView", "DataGenerator", "Logger", "Hook"], "layout": { "MessageView": ".b-message-view" }, "locale": "ru", "path": { "descriptor": "./app/descriptors/", "module": "./app/modules/", "locale": "./app/locales/", "template": "./app/templates/" } }
ã¢ããªã±ãŒã·ã§ã³ïŒindex.js
ã¢ããªã±ãŒã·ã§ã³èšè¿°åããç解ã§ããããã«ã4ã€ã®ã¢ãžã¥ãŒã«ããããŸãã ã¢ããªã±ãŒã·ã§ã³ã¯ããµãŒããŒãšã®å¯Ÿè©±ãªãã§æãã·ã³ãã«ã§ããããšãå€æããŸããã èšäºã«ã¢ãžã¥ãŒã«ã³ãŒããæ·»ä»ããŸããããªããžããªã«ãããŸãã
MessageView-newDataã€ãã³ãã§ã¡ãã»ãŒãžã衚瀺ããŸã
DataGenerator-1ç§ã«1åãããŒã¿
Math.random()
newDataã€ãã³ããçæããŸã
ãã¬ãŒ-newDataã€ãã³ãããªãã¹ã³ãã
ããã¯ãå°çããããšãã³ã³ãœãŒã«ã«æžã蟌ã¿ãŸã-newDataã€ãã³ãã«ããã¯ãæããŸããæååãã€ãã³ãã«å°çãããšãããã¯ã¯ã€ãã³ããäžæ¢ããŸãã0.5æªæºã®æ°å€ãå ¥åããããšã100åãããŸãã
çµç«
åã¹ããŒãžïŒdevãtestãprodïŒã«ã¯ãç¬èªã®ã³ã¬ã¯ã¿ãŒïŒãŸãã¯ç¬èªã®æ§æïŒãå¿ èŠã§ããéçºã®ããã«ãããã¥ã¡ã³ããåéããå¿ èŠãããããã¡ã€ã«ãå§çž®ããå¿ èŠã¯ãããŸããããã¹ããšå®çšŒåã§ã¯ããã¡ã€ã«ãžã®ãã¹ãç°ãªãå ŽåããããŸãããã¡ã€ã«ãå§çž®ããã³åéããã³ãŒãã®ãšã©ãŒããã§ãã¯ããå¿ èŠããããŸãïŒéçãã§ãã¯ïŒãå€ãã®ãã«ãæŠç¥ãšããŒã«ããããŸããæãç°¡åãªãã®ã説æããŸããã¢ã»ã³ããªäžã«ãã¢ããªã±ãŒã·ã§ã³èšè¿°åã䜿çšããŸã
index.json
ã
ã¢ã»ã³ããªindex.js
index.jsããã«ãããã«ã¯ãrequireãbuildFromã®æ©èœãæã€ç空çããªããã»ããµã䜿çšããŸããããªããã»ããµé¢æ°ã¯ãããã¯ã³ã¡ã³ãã§å²ãŸããŠãããããã¢ããªã±ãŒã·ã§ã³å šäœã®åäœã劚ããããšã¯ãããŸããïŒJavaScriptãšCSSã®äž¡æ¹ã«é©ããŠããŸãïŒãindex.jsã¯ããªããã»ããµã«æž¡ãããããªããã»ããµã¯ãã¡ã€ã«ãã¹ãã£ã³ããŠãããžã§ã¯ããã³ã³ãã€ã«ããŸãã
/*$require: ./lib/Core.js */ (function (Core) { "use strict"; /*$buildFrom ./index.json */ Core.on('ready', function () { Core.trigger('newData', 'Pewpew'); }); Core.init(/*$require*/'./index.json'/*$*/); }(this.exports.Core))
ã¢ã»ã³ããªåŸããã¡ã€ã«ã¯æ¬¡ã®ããã«ãªããŸãã
// Core.js (function (Core) { "use strict"; // + descriptors/Logger.json Core.pushDescriptor("Logger", { "name": "Logger", "acl": { "listen:newData": true, "listen:ready": true } }); // - descriptors/Logger.json // + modules/Logger.js Core.pushModule("Logger", (function(global){ // ... }(this))); // - modules/Logger.js // + locales/Logger.js Core.pushLocale("Logger", {}); // - locales/Logger.js // ... - .... Core.on('ready', function () { Core.trigger('newData', 'Pewpew'); }); Core.init({ "modules": ["MessageView", "DataGenerator", "Logger", "Hook"], "layout": { "MessageView": ".b-message-view" }, "locale": "ru", "path": { "descriptor": "./app/descriptors/", "module": "./app/modules/", "locale": "./app/locales/", "template": "./app/templates/" } }); }(this.exports.Core))
Cã¯
require
ãã¹ãŠæ確ã§ããã
buildFrom
ããå°ãè€éã§ãããã®é¢æ°ã¯ãã¢ããªã±ãŒã·ã§ã³èšè¿°åã䜿çšããŠç¹å®ã®ãã¡ã€ã«ãæ·»ä»ããŸãããã®äŸã§ã¯ãã¢ãžã¥ãŒã«ãçµã¿ç«ãŠãŸãã
Logger
ïŒæ®ãã®éšåãäœããã®æ¹æ³ã§æ¥ç¶ãããŠããŸãïŒãããžãã¯
buildFrom
ã¯ããå°ãè€éã«ãªãå¯èœæ§ããããããŒã«ã©ã€ãºãã¯ãªãŒã³ã«ããïŒãã®å Žåã¯åé€ãã
"en": "He said: "
ïŒãäºåãã§ãã¯ãå®è¡ãããªã©ãã§ããŸãã
éçºç°å¢ã§ã¯ãã¢ããªã±ãŒã·ã§ã³ããã«ããããªãå ŽåããããŸã-ã¢ãžã¥ãŒã«ã¯ã«ãŒãã«ã«ãã£ãŠåçã«ããŒããããŸãã
ã¢ã»ã³ããªindex.css
ãã®äŸã§ã¯ãåçŽãªã¢ãžã¥ãŒã«æ§é ããããŸããåã¢ãžã¥ãŒã«ã«ã¯1ã€ã®ãããã¯ããããããç空äžã§åãçç¶ã®ã³ã¬ã¯ã¿ãŒã«å¶éããŸãã
/*$buildFrom: ../../index.json */ /* app/css/blocks/b-message-view/b-message-view.css */ .b-message-view { color: green; font-family: monospace; }
buildFrom
ã³ã³ããã¹ãã®ããžãã¯ã¯
css
次ã®ãšããã§ãã圌ã¯ã¬ã€ã¢ãŠãã®ã¢ããªã±ãŒã·ã§ã³æ§æãèŠãŠãåã¬ã€ã¢ãŠãã«ã€ããŠã察å¿ãããããã¯ãç§ãã¡ã«æ¥ç¶ã
b-message-view
ãŸããããã¯ãã¹ãŠç°¡åã§ããããã¯ã¢ã»ã³ããªã®éåžžã«åçŽåãããããŒãžã§ã³ã§ãããããè€éãªã¢ããªã±ãŒã·ã§ã³ã«ã¯é©ããªãå¯èœæ§ããããŸãããäŸãšããŠã¯ããã§ååã§ããããšãã°ãBEMãã«ããŒã¯ãã¢ããªã±ãŒã·ã§ã³ã®ãããã¯ãèšè¿°ããjsonãã¡ã€ã«ã䜿çšããŸãã
ã¢ã»ã³ããªindex.html
ã
index.css
ãã
index.js
ãŸããã¢ã»ã³ããªã«ã¯åãããªããã»ããµã䜿çšããŸã
index.html
<!DOCTYPE HTML> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title></title> <!--$require: index.css--> <link rel="stylesheet" href="app/css/pages/index.css" /> <!--$--> </head> <body> <!--$buildFrom: index.json--> <div class="b-message-view"></div> <!--$--> <script type="text/javascript" src="http://yandex.st/jquery/1.6.1/jquery.js"></script> <!--$require: index.js--> <script type="text/javascript" src="./vendors/Script.js"></script> <script type="text/javascript" src="./lib/Core.js"></script> <script type="text/javascript" src="./index.js"></script> <!--$--> </body> </html>
buildFrom
htmlã®ã³ã³ããã¹ãã§ã®ããžãã¯ã¯æ¬¡ã®ãšããã§ãïŒcssã«äŒŒãŠããŸãïŒïŒã¬ã€ã¢ãŠãã®ã¢ããªã±ãŒã·ã§ã³æ§æã調ã¹ãåã¬ã€ã¢ãŠãã§å¯Ÿå¿ããdivãäœæããŸã
b-message-view
ãç¹°ãè¿ããŸãããããã¯ã¢ã»ã³ããªã®æãåçŽãªããŒãžã§ã³ã§ããããã¹ããŒããªxsltã³ã¬ã¯ã¿ãŒã䜿çšã§ããŸãã
åºåã§ã¯æ¬¡ã®ããã«ãªããŸãã
<!DOCTYPE HTML> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title></title> <link rel="stylesheet" href="/index.css" /> </head> <body> <div class="b-message-view"></div> <script type="text/javascript" src="http://yandex.st/jquery/1.6.1/jquery.js"></script> <script type="text/javascript" src="/index.js"></script> </body> </html>
Makefile-äžè¬ã¢ã»ã³ããª
ã³ã¬ã¯ã¿ãŒã®æ©èœïŒ
- ããªããã»ããµãå®è¡ããŠindex.cssãæ§ç¯ããŸã
- index.cssãæé©åããŸãïŒdata / uriãªã©ã
- index.cssãå§çž®ããŸãïŒgzã¯ãªãã·ã§ã³ïŒ
- index.cssãªãœãŒã¹ããã«ãããŸãïŒåç
- èªååãããåäœãã¹ããå®è¡ããŸãïŒäžïŒ
- ããªããã»ããµãå®è¡ããŠãindex.jsããã«ãããŸã
- index.jsãæ€èšŒããŸã
- index.jsãå§çž®ããŸãïŒgzãªãã·ã§ã³ïŒ
- OS .deb .rpmã®ããã±ãŒãžããã«ãããŸã
- ããã±ãŒãžããªããžããªã«é 眮ããŸã
- ããã±ãŒãžãã€ã³ã¹ããŒã«ããŸã
åäœãã¹ã
ããäžåºŠçã¿ã«ã€ããŠãå€ãã®äººã¯ããã¹ãã¯ãã¬ãŒã ã¯ãŒã¯ã«ã®ã¿å¿ èŠã§ãããšèããŠããŸãããã¢ããªã±ãŒã·ã§ã³ã¯ãã¬ãŒã ã¯ãŒã¯ã§ããããã¿ãŒã²ããã¯çããç¹å®ã®ã¿ã¹ã¯çšã«äœæãããä»ã®éçºè ã䜿çšããŸãã
ã¢ããªã±ãŒã·ã§ã³èšè¿°åãšã¢ãžã¥ãŒã«èšè¿°åã䜿çšããŠãåäœãã¹ãã®èªåäœæã䜿çšã§ããŸãããžã§ãã¬ãŒã¿ãŒïŒç空ã§ãçç¶ïŒã¯å¿ èŠãªã¢ãžã¥ãŒã«ãªãœãŒã¹ãåéããã¢ãžã¥ãŒã«èšè¿°åã§aclã䜿çšããŠãã¢ãžã¥ãŒã«ãçæããã³ãªãã¹ã³ããã€ãã³ãã®ãã¹ãã¹ã±ã«ãã³ãäœæããŸãããã以å€ã¯ãã¹ãŠãã³ãã«ã§ãã
ååãšããŠãåã€ãã³ãã«ã¯ç¬èªã®åœ¢åŒããããŸãããã¹ãã¿ã¹ã¯ãç°¡çŽ åããããã«ãã€ãã³ããµã³ãã©ãŒãäœæããŸãã
var TestData = { "newData": function () { var data = [NaN, Infinity, window, Error, 'pewpewpew', '<b>Pewpew</b>', '"', '\'', new Date, Date, Math, 42, 8, -1, 0, false, true]; return data; } };
ãã¹ãã«ã¯ãQUnitã䜿çšããŸããMessageViewã®äŸãèããŠã¿ãŸããããåäœãã¹ããžã§ãã¬ãŒã¿ãŒã¯ã1ã€ã®MessageViewã¢ãžã¥ãŒã«ãããã¹ããïŒèªåçã«ïŒäœæãããã¹ãã¹ã±ã«ãã³ãäœæããŠã¢ãžã¥ãŒã«ã€ã³ã¿ãŒãã§ã€ã¹ïŒãªãã¹ã³ããŠçæããã€ãã³ãïŒã確èªããŸããããã¯ã確èªããå¿ èŠã®ããæå°å€ã§ãã
ãã¹ãã³ãŒãïŒindex.js
// MessageView test (function (Core, $, TestData, ok, test, module, equals, expect, asyncTest, start, stop) { "use strict"; // var ApplicationEnvironment = { "modules": ["MessageView"], "layout": { "MessageView": ".b-message-view" }, "locale": "ru", "path": { "descriptor": "../../app/descriptors/", "module": "../../app/modules/", "locale": "../../app/locales/", "template": "../../app/templates/" } }; Core.on('ready', function () { module("MessageView"); // 1 test("listen:newData", function() { var testItems = TestData["newData"](), $MessageView = Core.getBox("MessageView"), template = Core.getTemplateFunction("MessageView", '.b-message-view'), label = Core.getText("MessageView", "text_label"); expect(testItems.length); // >>> put your code $.each(testItems, function (index, text) { Core.trigger("newData", [text]); // >>> put your code var expected = template({label: label, value: text}); // <<< equals(expected, $MessageView.html(), 'Should be "text_label: value"'); // <<< }); }); // 2 test("trigger:newData:display", function() { var testItems = TestData["newData"](), $MessageView = Core.getBox("MessageView"), template = Core.getTemplateFunction("MessageView", '.b-message-view'); expect(testItems.length); // >>> put your code Core.on("newData:display", function () { // <<< ok(true); // <<< }); // <<< $.each(testItems, function (index, item) { Core.trigger("newData", [item]); // >>> put your code }); }); }); Core.init(ApplicationEnvironment); }(this.exports.Core, jQuery, TestData, ok, test, module, equals, expect, asyncTest, start, stop))
ãã®ãããªå€§éã®ã³ãŒãã®ãã¡ãéçºè ãè¿œå ããå¿ èŠãããã®ã¯5è¡ã®ã¿ã§ãã
<<<
ãã§ããŒã¯ããŸããã
ãã¹ãã³ãŒãindex.htmlã¯æããã§ã-é©çšããŸããã
ãã¹ãèªååãšãã¹ãã«ããã³ãŒãã«ãã¬ããž
, 60 ( , ). , ( ). , ( , ):
â js-test-driver â QUnit, .
â TestSwarm ( ) â Mozilla Labs
â JSCoverage
ãã¹ããå®è¡ããŠãå®éã«æ©èœããã¿ã¹ã¯ãå®è¡ããããã«ããŸããwhat-ifãã¹ããå®è¡ããªãã§ãã ãããèªååãšã³ãŒãã«ãã¬ããžãå°å ¥ããããªãå Žåã¯ãåäœãã¹ãã®å¿ èŠæ§ã«ã€ããŠèããããšããå§ãããŸãã
ã³ãŒãæ€èšŒãšããã¥ã¡ã³ãã®ã¢ã»ã³ããª
ãŸãããã®èšäºã®ãããã¯ã§ã¯ãããŸããããèšåãã䟡å€ããããŸããããã¯ãå¿ èŠãªå Žåãæå®ãããæ§æã«åŸã£ãŠããããžã§ã¯ããã«ããŒã¯Doxãjsdoc-toolkitãªã©ã䜿çšããŠããã¥ã¡ã³ããåéã§ããŸããã»ã³ããããã¥ã¡ã³ããæžã
ãªããžããªã«ã³ãããããåã«ããã¹ãã«ãšã®ãããžã§ã¯ãã®ã¢ã»ã³ããªã®åã«ã¯ãããªããŒã¿ã®ã³ãŒãã§ãã§ãã¯ããå¿ èŠããããŸããäºåã³ãããäžã«ã³ãŒãããã§ãã¯ããªãå ŽåïŒã¢ã»ã³ããªã®åãŸãã¯å¿ èŠã«å¿ããŠãã§ãã¯ããïŒãæé ãã«ãªãå¯èœæ§ããããŸã-倧éã®ã³ãŒããèç©ãã倧éã®ã³ãŒããä¿®æ£ããã®ãé£ãããªããé ããæ©ããæ€èšŒã®ããã«ã¹ã³ã¢ãä»ããããšãã§ããŸãããã«ããšã©ãŒãé²ãã«ã¯ããããžã§ã¯ãããã«ãããåŸã«ã³ãŒãããã§ãã¯ããå¿ èŠããããŸãïŒå³å¯ã§ã¯ãããŸããïŒã
äžè¬çãªãã€ã³ã
ãã®éšåãèŠçŽã®åœ¢ã§äœæããŸããWebã¢ããªã±ãŒã·ã§ã³ã ãã§ãªãæå¹ã§ãã
- ä»ã®äººãããªããšäžç·ã«åããŠããŸã-圌ãã®ä»äºãå°éããæéã倧åã«ããŠããŸã
- ( ). JSLint, JSHint !
- .
- , , !
$textarea.val($textarea.val())
- : . â ! â . â . : foo, temp. , ( tmp), , â !
- JavaScript, HTML CSS ( ). HTML â , . CSS â . JavaScript â .
- . Element.style. , html ( FTW!). CSS Expressions!
- . 2-3 !
- , . â ! (Array.prototype, Function.prototype)
- , â , !
- instanceof, typeof, Object.prototype.toString magic
- ! URL ; ; , ,
- éçºããã»ã¹ã®èªååïŒèªååããããã¹ãããŒã«ïŒjs-test-driverïŒãã³ãŒãæ€èšŒïŒJSLintãJSHintïŒãã³ãŒããã«ããšããã¥ã¡ã³ãïŒJSDocToolkitãDoxïŒã䜿çšããŸãããã¹ããµãŒããŒããªã¢ãŒãã«ããå Žåã¯ãCtrl + Sã§èªåãã¡ã€ã«ã¢ããããŒããæ§æããŸããã³ãŒããžã§ãã¬ãŒã¿ãŒã䜿çšããŸãïŒãã¹ããã¢ãžã¥ãŒã«ã¹ã±ã«ãã³ã
ãµã³ãã«ã¢ããªã±ãŒã·ã§ã³ã³ãŒã
ãœãŒã¹ã¯GitHub scalable-js-appïŒã¢ãžã¥ãŒã«ã®å šæãã³ã¡ã³ãïŒ
ã«ãããŸããã¢ããªã±ãŒã·ã§ã³ã«ã¯ãªããã®ïŒèªåã¢ã»ã³ããªãåäœãã¹ãã®èªåçæããã¹ãŠã®ãã¹ãïŒMessageViewãé€ãïŒãèªåããã¥ã¡ã³ãã¢ã»ã³ããªã
èªã/èŠã
- Andrew DupontïŒGowallaãPrototype.jsãS2ïŒ- ã¡ã³ããã³ã¹å¯èœãªJavaScript
- Nicholas Zakas (Yahoo!, YUI, YUI Test) â Writing Maintainable JavaScript . ,
- Nicholas Zakas â Scalable JavaScript Application Architecture
- " JavaScript " .
é¢çœãã£ããšæããŸããææ¡ãåžæãæ¹å€ã¯å€§æè¿ã§ãïŒå°æ¥ã®èšäºã§ã¯ããããžã§ã¯ãã®çµã¿ç«ãŠãšèªååããããã¹ãã®ããã»ã¹ãããã«è©³ãã説æããŸãã質åãããå Žåã¯ã質åããŠã¿ãŸãããã