Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Vue 和 Angular 開發習慣
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Poy Chang
November 02, 2019
Programming
97
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Vue 和 Angular 開發習慣
Poy Chang
November 02, 2019
More Decks by Poy Chang
See All by Poy Chang
AIoT 智慧物聯網時代
poychang
0
440
Other Decks in Programming
See All in Programming
DynamoDBには集計系のクエリがないけどなんとかしたい
musan
1
130
TSKaigi Night Talks 2026_TypeScriptでサプライチェーンの整合性を型に閉じ込める
geekplus_tech
0
300
AI駆動開発勉強会 広島支部 第一回勉強会 AI駆動開発概要とワークショップ
hayatoshimiu
0
440
LLM Plugin for Node-REDの利用方法と開発について
404background
0
160
GitHub Copilot CLIのいいところ
htkym
2
1.3k
Oxlintのカスタムルールの現況
syumai
5
1k
TypeScript+Orvalで実現する型安全かつ堅牢でスケーラブルなマルチチャネル通知基盤 / TSKaigi Night talks ~after conference~
d0riven
0
290
Claspは野良GASの夢をみるか
takter00
0
170
「AIで開発し、AIを届ける」をEvalでつなぐ 〜AIネイティブに始めるプロダクト開発の実践〜 / Connecting "Develop with AI, deliver AI" with Eval
rkaga
4
2.4k
jQueryをバージョンアップする前に使いたいjQuery Migrate
matsuo_atsushi
0
190
AIエージェントの隔離技術の徹底比較
kawayu
0
460
不変条件と整合性境界—ビジネスが決める設計判断と実現パターン / Invariants and Consistency Boundaries
nrslib
13
3.4k
Featured
See All Featured
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
380
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
71
40k
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
180
Building Adaptive Systems
keathley
44
3k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
200
Build your cross-platform service in a week with App Engine
jlugia
234
18k
First, design no harm
axbom
PRO
2
1.2k
Darren the Foodie - Storyboard
khoart
PRO
3
3.4k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
1
340
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2k
How Software Deployment tools have changed in the past 20 years
geshan
0
34k
Transcript
HTML JS Vue 和 Angular 開發習慣 Poy Chang Developer /
Blogger / Dad
Poy Chang 目前任職于全美 100 大私人企業,負責企業內部 IT 解決方案設計 與開發,專注於 Azure、.NET Core、Angular
等技術研究 ✓ Angular Taiwan 社群核心成員 ✓ Microsoft MVP Developer Technologies ✓ 2019 廣州 Global Azure Bootcamp 講師 ✓ 2018 臺北 Angular TW Conf 講師 ✓ 2018 臺北 Azure Tech Day Party 講師 ✓ 2018 台中 .NET Conf 講師 ✓ 2018 北京 Global Azure Bootcamp 講師
先說說我自己… AngularJS Angular 2 Angular X Vue AngularJS Now JavaScript
Ionic Bootstrap Gulp TypeScript SASS More TS JavaScript Webpack More Library TypeScript Webpack Bulam ?
正規軍 游擊兵
None
None
None
None
None
.vue vue-loder vetur
https://forum.angular.tw/t/topic/771
Library & Framework Framework Library
開發思維 - 自主性 Vue 從原本的偏向 Library 函式庫慢慢朝 Framework 框架走 Angular
一直以完整的 Framework 框架為目標 自由實踐 Freedom Practice 最佳實踐 Best Practice 完整的框架讓人容 易往這方向走
開發思維 - 組件化 VAR 三大前端都有元件化 / 組件化的概念 Vue 常用的 .vue
檔將 HTML JS CSS 合併,認為組件化代表不能太大 (多程式碼) Angular 元件預設將 HTML JS CSS 分開,重點在關注點分離
開發思維 - 架構 Vue 程式碼架構自由度很高,對於喜歡自由奔放的 JS 開發者很有吸引力 Angular 引導了程式碼架構,內建機制讓開發者自然朝物件導向的思維前進
Functional & Object-Oriented 如果物件導向是以物件為基本組成元素的程式設計觀念,函式導向程式 設計便是以函式為基本單元來組織程式。 函式導向的特性 • 避免改變狀態/資料,沒有任何副作用 ( Immutable
) • 純函式,傳入相同的參數會得到相同的結果 (Pure Function) • 延遲評估,參數傳入時才執行,不會預先載入 ( Lazy Evaluation )
5 10 10
5 10 10 (上底 + 下底) x 高 / 2
None
Demo (1) - OOP // Simple Functional with BMI from
OOP // 避免改變狀態/資料,沒有任何副作用 ( Immutable ) // 純函式,傳入相同的參數會得到相同的結果 (Pure Function) // 延遲評估,參數傳入時才執行,不會預先載入 ( Lazy Evaluation ) class Person { height: number; weight: number; constructor(h: number, w: number) { this.height = h; this.weight = w; } getBMI() { return this.weight / ((this.height / 100) * (this.height / 100)); } } let john = new Person(180, 80); console.log(john.getBMI()); // 24.691...
Demo (2) – Extract to Function const bmi = (h:
number, w: number) => w / ((h / 100) * (h / 100)); class Person { height: number; weight: number; constructor(h: number, w: number) { /* 略 */ } getBMI() { return bmi(this.height, this.weight); } } let john = new Person(180, 80); console.log(john.getBMI()); // 24.691...
Demo (3) – High Order Function const square = (num:
number) => num * num; const divide = (a: number, b: number) => a / b; const bmi = (h: number, w: number) => divide(w, square(h / 100)); class Person { height: number; weight: number; constructor(h: number, w: number) { /* 略 */ } getBMI() { return bmi(this.height, this.weight); } } let john = new Person(180, 80); console.log(john.getBMI()); // 24.691...
Demo (4) – Reuse Function const square = (num: number)
=> num * num; const divide = (a: number, b: number) => a / b; const bmi = (h: number, w: number) => divide(w, square(h / 100)); const bmiPerson = (p: Person) => bmi(p.height, p.weight); class Person { height: number; weight: number; constructor(h: number, w: number) { /* 略 */ } getBMI() { return bmiPerson(this); } } let john = new Person(180, 80); console.log(john.getBMI()); // 24.691...
Demo (5) – Handle Bunch Data with Function let john
= new Person(180, 80); let kevin = new Person(180, 90); let will = new Person(170, 60); let personList = [john, kevin, will]; let bmiList = personList.map(bmiPerson); console.log(bmiList); // [24.691, 27.777, 20.761]
若一開始不知如何畫分物件職責 可先以函式為單元進行設計 再將相同職責的函式重構出物件 https://www.ithome.com.tw/node/78331
Function-based (Vue 3) Vue 的核心團隊想將 Vue 的開發習慣 導向以函式為基礎的開發方式 為此把原本的 data
和 methods() 改成 用 step() 來替代 兼容版本:支援 3.0 和所有 2.x API 標準版本:只支援 3.0 和部分 2.x API
Function-based (Vue 3)
Functional in Angular? 函式導向是一種開發典範,Angular 現行架構完全適用,不需大興土木 如果你在使用 RxJS,你已經在玩函式導向開發 除了透過 RxJS /
Ramda / Lodash 等 FP 函式庫來玩函式導向開發,使用 純 JavaScript 也可以透過函式導向的開發思維來解決的問題 https://github.com/stoeffel/awesome-fp-js
狀態管理 Vue 通常起手式就搭配 Vuex 來做狀態管理 Angular 可以透過 Service 做到簡易狀態管理,當然也可以導入 NGRX
來做到 Redux 風格的狀態管理 Service 這玩意在 Angular 中真的是妙用無窮,除了將共用的邏輯抽出 來重用,拿來做狀態管理也是輕鬆寫意
呼叫 API Vue 的開發環境下,習慣使用 axios / superagent / request 或原生的
fetch 來呼叫 API Angular 內建 HttpClient,大多數開發者都選擇使用內建的 API 功能
模組化 Module Vue 本身沒有提供模組化 Module 的概念,都是用元件 / 組件的方式做 疊加,若要建立模組的層級,要靠各位開發者自行實作 Angular
的模組化不僅用在功能 / 特性的隔離,也可用來做延遲載入 Module 的主要貢獻不是在於他怎麼被使用,而是藉由抽象化的概念, 讓架構看得更清楚
或許我們都專注在把專案完成,而忘記自己 的習慣可能造成的影響,如果大家的習慣都 差不多,問題可以少很多 一致的寫法 / 架構 / 工具,能幫助開發過程 中的問題,不會越滾越大
或許我們都專注在把專案完成,而忘記自己 的習慣可能造成的影響,如果大家的習慣都 差不多,問題可以少很多 一致的寫法 / 架構 / 工具,能幫助開發過程 中的問題,不會越滾越大
聽你說 實務上每個開發團隊的習慣都不一 樣,與我們分享您在開發過程中, 遇到的好習慣 / 壞習慣
Thanks! HTML JS 謝謝各位聆聽 Poy Chang 的技術交流中心