Upgrade to Pro — share decks privately, control downloads, hide ads and more …

新版阿尔法城背后的前端MVC实践

 新版阿尔法城背后的前端MVC实践

Dexter.Yy

July 09, 2011
Tweet

More Decks by Dexter.Yy

Other Decks in Programming

Transcript

  1. ၂۱“ྴ୅གྷൌ”ႋႨ • Bring real-life to software, rethought for the web

    čGoogle+֥sloganᕞĆXX෮࡮੻๝đᕫᕫḣĎ • ྴ୅֥൞Ԏའ֥གྷൌđ҂ླေЯᆇ֥3D๭ཞ • GUIླေ௜߁ሱಖ౔్֥ႅნčMetaphorĎğ໭ԩ҂ᄝ ֥ݖ؈׮߂ིݔ
  2. 1. ଆॶ߄ഡ࠹ • έغمӬࠎႿOzJS • ෮Ⴕս઒ֆჭ׻ٿልӮ CommonJSڄ֥۬module • ᆺႵཁൔലૼ၇ঠܱ༢đҌ ିӻႵః෰ଆॶᇏؓའ֥ႄ

    Ⴈđ࣌Ⴈಆअଁ଀ॢࡗ • ሱ׮ܵ৘၇ঠđѩྛࡆᄛđ اྟࡆᄛđοླࡆᄛ • u๙ႨJSൈս֥ଆॶࠏᇅބщ ၲ۽ऎv
  3. • ູཛଢਈദקᇅ֥“ັॿࡏ” čmicro-frameworkĎ • Thomas Fuchs: Zepto and the rise

    of the JavaScript Micro-Frameworks • Dustin Diaz: Ender.js - The open submodule library
  4. 2. ཨ༏Ԯ־čmessage passingĎ • Alan Kay: "OOP to me means

    only messaging, ..." • ࠇᆀӫޫ෱PubSub / EventEmitter / CustomEvent / ... ෛь൉હ׻ྛ • ᄝέغمӬ֥ս઒৚෱ࢡObserver • MVCٳҪ֥ࠎԤđઆࠠٳ৖֥భิ
  5. 3. భ؊URL Router • ෮Ⴕڛༀఖ؊webॿࡏ֥ѓ஥ • ູSingle-page WebAppഡ࠹URL҂čࣇĎ൞ູਔSEO • URLॖսูDOM൙ࡱ

    • URL൞၂ᇕႨ޼౨౰֥ൻೆٚൔ • URL൞၂ᇕሑ෿ • UNIXഡ࠹ᆀྏଢᇏ֥৘མҠቔ༢๤ğPlan 9 • “Plan 9 Ӑ֝ႋႨӱ྽ᄝᄎྛൈ׻Ϝሱ֥࠭ଽ҆ሑ෿ ԎའӮ၂۱໓ࡱ༢๤” • URL൞WebApp֥“໓ࡱ༢๤”
  6. • धն؟ඔ౦ঃ༯ᆺླေ ႨclassName႘ഝ൙ࡱ • ܣၩ҂ᆦӻ҆ٳ௄஥đ ؟۱classॖၛіൕሑ෿ ֥ڿэࠇןࡆ • UI൙ࡱ҂ᆰࢤ႘ഝ֞ Viewؓའ֥ٚمđЌᆣ

    Viewؓའ֥ٚم҂ࢤ൳ DOMҕඔ • ᄝViewҪᆭຓсྶିᄜ གྷ಩ၩUI൙ࡱ֥ۿି • ൌ২ğႨ޼ׄࠌ——> ࣉೆཬ׋֥ٜࡗ——> Ⴈ޼඗ྍ်૫——>ሱ ׮߫گٜࡗ൪๭
  7. έغمӬ֥ViewҪ • ๭ྙᛴಙႄౣ + UIቆࡱࠢކčView widget/ ViewؓའĎ • Viewؓའ҂ᄍྸᆰࢤҰ࿘ࠇྩڿඔऌđ҂၇ ঠModelބControllerđᆺି஘ԛ൙ࡱ/ཨ༏

    čMartin Fowler֥ӫޫğPassive ViewĎ • Viewؓའ҂ݣြༀઆࠠđ֌ॖၛӻႵሑ෿ބ ഈ༯໓č۵Ԯ๤web MVC҂๝Ďđwebభ؊ ۵ም૫GUI၂ဢऎСӻࣲ֥UIؓའđDOM൞ ჰളViewđViewؓའ൞DOM֥ۚҪٿል
  8. έغمӬ֥ViewҪ • ႮViewҪڵᄳԩ৘টሱUI֥Ⴈ޼ൻೆčط҂൞ ControllerĎđၹູğ • ᛍফఖUI൙ࡱ֥ҕඔ൞DOMؓའ • གྷսwebႋႨ֥UIࢌ޺ϴෛնਈݖ؈ིݔ/ڬ ቔႨ •

    ൌ২ğࣉೆཬ׋aGoogle+೷Ԣcircle • ಆअ൙ࡱ຾ກཞCocoa၂ဢ৵ࢤUIჭࡱބViewؓ འđטႨViewᆷ਷భсྶ༵ϜDOMሑ෿ሇߐӮ ՂඔऌҕඔđЌᆣᄝViewҪᆭຓ္ିᆰࢤטႨ ᆃུٚمᄜགྷཌྷ๝֥ۿି
  9. έغمӬ֥MVC View Model Controller / App Server Model Server Contorller

    Pluggable Widgets ໭ሑ෿֥http ൌൈࢤ१ ൪๭ࢤ१ ൙ࡱ/ཨ༏ ൙ࡱ/ཨ༏ ൙ࡱ/ཨ༏ ᛴಙ/ྩڿ Ұ࿘ UI/DOM൙ࡱ URL ࡯஍ ॥ᇅ෻ HTMLളӮ/๭ྙ߻ᇅ/׮߂ིݔ
  10. MVCĤIt's no big deal • ໡֥׸ϵᇶ်ğhttp://www.douban.com/people/Dexter_Yy/ • ໡֥blogğhttp://www.limboy.com • ྍϱέغمӬğhttp://site.douban.com/118836/

    č࣍௹ഈཌĎ • ॖႨႿMVCႋႨ֥moduleğhttps://github.com/dexteryy/OzJS/tree/master/ mod č࣍௹۷ྍĎ Thanks