Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Web 应用架构指南
Search
island205
March 27, 2016
Technology
370
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Web 应用架构指南
45 分钟学会5个前端框架
island205
March 27, 2016
More Decks by island205
See All by island205
Doorman
island205
1
78
Other Decks in Technology
See All in Technology
二歩目のフロントエンド・ウェブアクセシビリティ
camiha
2
430
事業成長とデータ活用を止めないためのマネジメントへ挑戦
hiracky16
0
330
無理せず続ける、子育てエンジニアの学び
codmoninc
PRO
0
720
自主式軟體工廠
philipz
0
260
V8のArray.prototype.flatを最大約20倍速くするまでと、巨大OSSへの大規模コミットの道のり
riyaamemiya
0
280
FactoryBotアンチパターン / factory_bot anti-patterns
toshimaru
0
160
触りたくないデータに、どう触るか AI時代のRBACアクセスガバナンス
ivry_presentationmaterials
0
140
自作バイナリを動かす「入口」8選
puhitaku
2
1.3k
Post AI時代のリファクタリング実践記 / Refactoring in the post AI era
kaminashi
1
180
夫婦で子育てするための育児標準化
codmoninc
PRO
0
210
AIに攻撃される前に、AIに攻撃させる
tsuchikazu
0
170
宣言型部分更新は何を解決しどこへ向かうのか
shuta13
1
360
Featured
See All Featured
So, you think you're a good person
axbom
PRO
2
2.2k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
1.3k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
Docker and Python
trallard
47
4.2k
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
430
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6.1k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
530
How to Think Like a Performance Engineer
csswizardry
28
2.9k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
33
5.2k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
1.1k
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
5
810
Building an army of robots
kneath
307
47k
Transcript
Web 应用架构指南 45分钟学会五个前端框架 @island205
@寸志 是我的真名 前端架构师@陆金所 陆金所大前端招聘! https://github.com/island205/Lu-Hire ᅩᦧ̵Teambition̵ᴭᰂಅૡ JavaScript ཛྷࣘ۸̵ڹᒒຝ̵ڹᒒᚆս۸ ٟԡ̵ᘉᦲ̵Github̵ஙܗ̵ᎣԒ ᘷѺ
前端外刊评论 qianduan.guru ᴨ᯾̵ᚸᦔᒵ 10 ֖ૢݦጱڹᒒૡᑕᕟ౮ጱᖫᬋࢫᴚ҅ྯޮӞᓤᴅጱڹᒒܻڠᘉᦲᒍ ᕁ۱Ѻ
辣么多的前端框架?! 2010.10 2010.06 2011.12 2010.10 reborn in 2016? 2013.03 2014.03
Backbone.js Knockout Ember.js Angular 2 React Vue ெԍᬦҘ
፡፡ TodoMVC 1. ᬯԍग़ຝ҅ᥝکՋԍײҘ 2. ፡ TodoMVC ጱֺৼ҅᪙፳؉ԧ҅ᓌܔ҅֕॔ጱଫአெԍ؉Ҙ
万变不离其宗[指南] ԧᥴԧਤ҅܈كቔྎᜏ҅ռग़ຝḘӤտ ԧᥴԧਤ҅܈كቔྎᜏ҅ռग़ຝמಋೈ ᬯӻਤ҅੪ฎ౯Քॠᥝᦖጱܖ
第一式: 学会编写组件 ፘྲ Angular 1 ଲጱ༷ஷᘒ҅React ڊጱᕟկཛྷୗᓌܔ҅֕Ԟஉ୩य̶़React ጱၞᤈ҅ߥԧෆӻڹᒒຝಅ׀ጱݎཛྷୗ——ݻԭ׀ᕟկ۸ݎጱොୗ
<check-box></check-box> ਖ਼ଫአӾጱձ֜ UI ፘىጱ᮱ړ᮷፡౮ԧӞӻӻᕟկ҅੪ই HTML ຽᓋӞ ᮎ؟ᬯጱ HTML ᕟկᧆই֜ᖫٟޫҘ
按照 MVC 的思路解构组件! ᕟկ۸ݎጱ໐ஞཛྷࣳฎ MVC҅౯তᕣᦊԅ MVC ฎᦡᦇཛྷୗӾ๋᯿ᥝጱ༷ஷѺ
Ӟӻᕟկړ౮ӣ᮱ړғᥤࢶ̵ഴګ̵ᇫா ຝ׀ԧߺԶᥝᔰ҅ԭ౯ժᖫٟӞӻᕟկҘ 1. M ᕬਧک Vғහഝๅෛ҅View ᛔۖๅෛ 1. ໑ഝ M
ๅෛک V ጱොୗӧӞ҅ݢզຝړ౮ӷᔄ 1. React Virtual DOMғྲᡦ DOM 2. ӧฎ Virtual DOM ጱ 2. ໑ഝ M ݒ۸༄ၥጱݎොୗ҅Ԟݢզຝړ౮ӷᔄ 1. Angular Ӟ 1 $apply ᚍ༄ၥ҅2 Zone.js 2. ᶋ Angular ጱ Setter 2. V ᕬਧک Cғᕬਧ DOM Ԫկ 3. C ๅෛ M 1. Ԟݢզړ౮ӷᐿຝ 1. ፗള֢ M 2. ӧፗള֢ M ጱ
var checkbox = new Checkbox() $(document.body).append(checkbox.el) Backbone ᕟկ๋चᏐጱአဩ
export default Backbone.View.extend({ tagName: 'span', className: 'Checkbox', events: {'click .fake':
'toggle'}, initialize: function () { this.state = new Backbone.Model({ checked: false }) this.state.on('change:checked', this.render.bind(this)) this.render() }, toggle: function () { this.state.set({checked: !this.state.get('checked')}) }, render: function() { var checked = this.state.get('checked') this.$el.html(` <i class="fake${checked ? ' checked' : ''}"></i> <input type="checkbox" ${checked ? 'checked' : ''}></input> `) } }) state ฎ M events ฎ C render ฎ V
{{check-box}} Backbone ᕟկ๋चᏐጱአဩ
<span class="Checkbox"> <i class="fake {{if checked 'checked' ''}}" {{action 'toggle'
on="click"}}></i> <input type="checkbox" checked="{{if checked true false}}"/> </span> export default Ember.Component.extend({ checked: false, actions: { toggle() { this.set('checked', !this.get('checked')); } } }); checked M hbs V actions C
<check-box></check-box> Vue ᕟկጱԡٟොဩ੪ HTML चӞᛘ
var Checkbox = Vue.extend({ template: ` <span class="Checkbox"> <i class="fake"
:class="{checked: checked}” @click="toggle"></i> <input type="checkbox" v-model="checked"> </span> `, data: function () { return { checked: false } }, methods: { toggle: function () { this.checked = !this.checked } } }) Data M Template V methods C
<Checkbox /> React ጱԞฎইྌ
export class Checkbox extends React.Component { state = { checked:
false } toggle() { this.setState({ checked: !this.state.checked }) } render() { var checked = this.state.checked return ( <span className="Checkbox"> <i className={checked ? 'fake checked' 'fake'} onClick={this.toggle.bind(this))}></i> <input type="checkbox" checked={checked}/> </span> ) } }
没有 Angular 的例子? ࣁ Angular 1 Ӿ҅౯ժݢզአ Directive ਫሿᕟկຝ҅ᤰᵍᐶࣁ॔ጱଫአᶎڹฎஉํԎጱ̶
第二式: 用组件搭积木
ੜᕟկᕟݳ౮य़ᕟկ҅ړᘒလԏ ৼᕟկਂࣁىᘶىᔮ҅ݢզ᭗ᬦय़ᕟկ॒ቘ य़ᕟկ᭗ᬦં҅ဳفᯈᗝԪկࢧ᧣҅ഴګੜᕟկጱᤈԅ҅ߥଫੜᕟկጱԪկ
var checkbox = new Checkbox({ checked: true, onChange: function(checked) {
console.log(checked ? 'checked' : 'uncheck') } }) $(document.body).append(checkbox.el) փفᯈᗝࢧ᧣
initialize: function (options) { this.options = Object.assign({ checked: false, onChange:
function() {} }, options) this.state = new Backbone.Model({ checked: options.checked || false }) this.state.on('change:checked', this.render.bind(this)) this.render() }, toggle: function () { this.state.set({checked: !this.state.get('checked')}) this.options.onChange(this.state.get('checked')) }
{{checkbox checked=checked onChange=(action 'onCheckChange')}}
<div class="Todos"> <todos-header @add-todo=“addTodo" :all-done.sync="allDone"></todos-header> <todo-list :todos="filteredTodos"></todo-list> <todo-footer :todos="filteredTodos" :visibility="visibility"></todo-footer>
</div>
第三式: 把模块的 Template、Style、 JavaScript̵Images 放到一个目 录下!
None
None
组件和样式约定 <span class="Checkbox"> <i class=“fake" :class="{checked: checked}” @click="toggle"></i> <input type=“checkbox"
v-model="checked"> </span> .Checkbox { .fake { text-align: center; width: 40px; height: 40px; } input { display: none; } } Checkbox / checkbox-component 1. ֵአᕟկݷ֢ԅୗጱݷᑮᳵ 2. ୗֵአᶼ॒ቘ҅አ્ॺጱොୗᖫٟ
组件和样式约定 .Todo { position: relative; font-size: 24px; border-bottom: 1px solid
#ededed; .Checkbox { position: absolute; top: 0; bottom: 0; margin: auto 0; } } כᦤܔӻᕟկ CSS ጱᕍଶ҅Өᕟկᳵ൫ᯈጱ̵ྲইᳵ᪗̵ਧ֖ᒵמ௳ٟ҅ࣁᆿᕟկӾѺ
如何把散沙捏在一起? դᎱೆව҅੪؟වဉ҅ԧනࣁӞӻᕟկկ४Ӿ҅ᮎᧆই֜کӞ᩸ᬩᤈනࣁၨᥦӾᬩᤈޫҘ 1. Ḓضཛྷࣘ۸ࣈᖫٟᬯԶᕟկ 2. ᭗ᬦၨᥦᒒጱ Loader ᘏ Build ૡٍਖ਼ཛྷࣘᕟݳ᩸
3. ӥᶎฎӞԶݢᭌጱොໜದૣ 4. ୮ᆐ҅ፓڹ፡๋҅অጱ੪ฎᐦڊय़ Webpack
// app.css @import "./components/todos.less"; @import "./components/todos-header.less"; @import "./components/check-box.less"; @import "./components/todo-footer.less";
@import "./components/todo-list.less"; @import "./components/todo.less"; ಅํ CSS կጭᦕࣁӞӻկӾ҅᭗ᬦᶼ॒ቘݳଚ̶
import Template from './template.dot' import './style.less' export default Backbone.View.extend({ tagName:
'span', className: 'Checkbox', ... ਖ਼ٌ՜կ᮷ Import ک index.js ӾѺ
祭出 Webpack! browserify/grunt/gulp 其实也能做 Webpack ӧฎ JavaScript module Loader ᘒฎ
Component module loader ଉአጱൊկՕᕨ
<template> <span class="Checkbox"> </span> </template> <script> export default { …
} </script> <style lang="less"> .Checkbox { … } </style> Checkbox.vue
Tips: 开发运行时和线上运行时分开!
第四式: 用路由把组件链成应用
ӷ੶ MVC ጱᕮ̶
常用的 Route 模块 Backbone Backbone.Router Ember.js App.Router Angular ng-router/ui-router angular
2 router React react-router Vue vue-router
app.get('/app/*', function (req, res, next) { res.render('app') }) ԅԧعଫአࣁֵአᬦᑕӾڬෛ҅๐ۓᒒᦏಅํᧆᶭᶎಥጱ᪠ኧ҅᮷ᬬࢧ APP
ᶭ
业务复杂时,按照业务切 分为多个独立的单页应用
第五式: 聪明、准确的数据层 ᧗ ᖨਂ ݶྍ ݎ
鉴于时间关系,以及目前已 有的方案并没有达到理想的 要求,我们下次再聊吧!
Q&A