| 架構的不同: |
|
我們從11個方面來分析這兩種技術的不同.
- 應用開發架構
- 組件
- 路由
- 測試
- 資料繫結
- SEO
- 移動解決方案
- Dom 演算法
- Deferred and Promises
- 髒檢查
- Deferred bootstrap
|
摘要:
ExtJS 是基於組件的 (表格、樹、表單、繪圖);代碼開始於對現有類的擴充,配置模型,自訂顯示和行為/事件,將這些組件加入到container/layout中。 它遵循物件導向的設計思想和MVC設計模式,很少直接操作DOM元素
AngularJS,走的是另外的一條路,是一種聲明式的程式。在HTML標籤上新增AngularJS指令,配置模型,使用模版和路由配置視圖;架構最終實現了DOM的建立。我們仍然是基於HTML架構,操作DOM元素 |
| 應用設計架構 |
Ext JS:
- 支援 MVC 和 MVVM
- 隨著ExtJS 應用規模和複雜度的增加, Sencha Touch 和 Ext JS 能夠通過 Deft JS 實現依賴注入
- 它是基於組件,模組化的
|
AngularJS:
- AngularJS是一個對於web應用的HTML擴充。
- 它被描述為了 ‘Model-View-Whatever‘ 架構,它並沒有規定使用特定的開發架構。但是它非常容易支援 Model-View-Controller 或者 Model-View-ViewModel.
- 它是模組化的。 它自動裝盤HTML元素中的依賴注入模組
|
| 組件: |
Ext JS:
ExtJS和其他javascript架構最大的區別,就是擁有一套強大的UI組件 好處:
完整的組件體系,能夠大大的減少開發時間 壞處:
ExtJS的組件會產生冗長的DOM代碼,這樣會影響效率 |
AngularJS:
- AngularJS 並不具有一個完整的組件庫
- 但是,這裡有非常多的第三方組件,比如 AngularUI Bootstrap, Kendo (and Angular-Kendo), Wijmo 等等
|
| 路由: |
ExtJS:
ExtJS 5 支援路由
- ExtJS 5 路由通過使用瀏覽器曆史堆棧,實現了應用程式狀態跟蹤
- 它允許深度連結到應用程式。 允許直接連結到應用程式的一個部分
- 它支援瀏覽器收藏夾和瀏覽器前進/後退導航
|
AngularJS:
- AngularJS路由將 controllers, view templates, 和瀏覽器當前 URL 地址聯絡在了一起。使用這個特性,我們實現了深度連結
- 通過使用深度連結,實現了使用一個超連結,導航到本頁面的特定位置。它使我們能夠使用瀏覽器曆史(前進/後退導航)和瀏覽器收藏夾
|
| 測試; |
ExtJS:
- ExtJS應用能夠使用第三方的測試架構來測試,比如 Siesta (專門為 Ext JS 最佳化),Jasmine 和Mocha.
- 自身並不包含測試架構和測試載入器
|
AngularJS:
- AngularJS在設計之初,就考慮到了應用的可測試性
- 支援單元測試,整合測試和功能
- AngularJS 團隊開發了 Karma 測試載入器。 另外,第三方的工具 Protractor也可以用於AngularJS的測試
|
| 資料繫結雙向資料繫結是串連頁面UI和資料模型的紐帶,及更改模型的資料,頁面UI能夠同步響應 |
ExtJS:
- ExtJS 5 組件有新的綁定配置,用於實現此功能
- 在早期的ExtJS版本中,使用Store對象來實現此功能。但是任然有一些工作需要做,比如載入Store等
|
AngularJS:
AngularJS的雙向資料對應執行的範圍,是基於一個原型繼承樹範圍的嵌套模型 (models).
Cons:
如果模版中有2000-3000個繫結應用程式會變慢
當許多資料呈現在了頁面上的時候,Bindonce是一種很好的方法來減少監視。一旦渲染完成,就不會改變,你不需要在對其改變進行監視 |
SEO:Most of the single page apps which work behind authentication need not be indexed for SEO. If you have some pages in your app which are public and which needs to be indexed, you can create them separately, either with static HTML/CSS or if you do need to use dynamic content, consider Ajax based SEO as described below.
Ajax based SEO: For the indexing of dynamic / ajax-based single page web apps, all you have to do is to generate the additional static content so that when the crawlers access your page, they get easy access to that static content and when the users access your page, they see the app. To achieve this functionality you could either use some tools like Prerender.io: fully open-source or you have to set up the headless browser support in your web-server which is an additional effort. |
ExtJS:
Ajax based seo is possible in ExtJS with hashbang urls‘ support in your web-server. |
AngularJS:
- AngularJS seo with Prerender.io: When a crawler visits your page at hashbang url, the Prerender service will check and see if it has a snapshot or already rendered page for that URL, if yes, it will send it to the crawler, if not, it will render a snapshot on the fly and send the rendered HTML to the crawler for correct indexing.
- Alternatively, you can also build support for hashbang URLs which may require you to set-up your web-server to summon-up the headless html browser.
|
| 移動解決方案: |
ExtJS:
- Sencha Touch - 企業級高效能的移動HTML5架構,用於開發強大的、健壯的移動APP或者移動網站。
- Sencha touch 整合Cordova/Phonegap,實現了跨平台的混合應用。
|
AngularJS:
- AngularJS 能夠用於開發響應式的web應用/網站。
- 為了開發跨平台的混合應用,AngularJS整合了以下組件
- Trigger.io
- Ionic Framework - Advanced Html5 hybrid mobile framework and optimized for AngularJS
- Cordova/Phonegap
|
| Dom演算法 |
ExtJS:
深度優先、自底向上 |
AngularJS:
Directives are linked in a Depth-First, Bottom-Up approach to the DOM tree. Controllers are linked in a top-down manner. |
| Deferred and Promises:Deferred and Promises break the complexities of asynchronous programming, separate out the synchronous and asynchronous world, remove the tight coupling between the two They are for asynchronous programming what try, catch and throw keywords are for synchronous programming. |
ExtJS:
ExtJS augmented with DeftJS may provide Deferred and Promises. |
AngularJS:
AngularJS offers an implementation of the Q API for Deferred and Promises. |
| 髒檢查髒檢查:架構比對舊值和新值,如果他們不一致,就觸發change事件 |
ExtJS:
- ExtJS 4.x使用store的binding特性來實現髒檢查。
- ExtJS 的store允許你通過設定autoSync為false,來延遲髒檢查行為。使用者對資料的改變,會在UI上給上舉打上一個標記,當更新store的時候,能夠批量提交這些更新。
- 將資料的變化放映到UI上,需要做一點點工作,比如reloading store的資料
|
AngularJS:
- Angular 使用Digest Cycle 實現了髒檢查
- 使用Angular api,你不需要手動處理,angular 會自動進行髒資料的回收。但是對於第三方的api,你需要調用$apply方法來回收髒資料。
- 髒資料回收完成,資料的改變就會呈現在UI上。
- 髒檢查是非同步
|
Deferred bootstrap:Bootstrap指的是初始化的過程,Deferred bootstrap用於延遲啟動進程載入很重、很大的依賴檔案或者目標。 Deferred bootstrap主要用於端對端測試。
雖然deferred bootstrap對於開發和單頁應用測試沒有意義,但是它對AngularJS 應用的端對端測試很有用。一些javascript測試載入器,比如 Batrang 和 Angular Scenario Runner (AngularJS團隊開發的,用於AngularJS項目的端對端測試) 需要 deferred bootstrap. |
ExtJS:
多種受歡迎的JavaScript 測試架構,比如Siesta (專為 Ext JS 最佳化), Jasmine 和 Mocha,並不需要延遲EXT JS應用程式的啟動 |
AngularJS:
- Batrang是一個新的angular 團隊推薦的 Chrome外掛程式,提供了一個顯示應用效能瓶頸,應用DEBUG的工具。
- AngularJS Batarang and Angular Scenario Runner require Deferred Bootstrap feature to hook into angular‘s bootstrap process and sneak in more modules into the DI registry which can replace or augment DI services for the purpose of instrumentation or mocking out heavy dependencies.
|
AngularJS的消化周期:
- 消化周期指的是資料改變的相應周期
- 一般情況下, 瀏覽器的event-loop等待事件到達,當它接收到事件,會在輸入控制項上發出事件,對於的事件控制代碼會捕獲到此事件,觸發對應的函數,將其作為參數傳入AngularJS的執行內容中。
- 函數中將實現模型的改變,在消化周期結束的時候,異常控制代碼會被觸發
- 在所有的消化周期機制中,在觀察列表中的觀測者會進行迭代,通過每個觀測者的運算式,擷取到特定的範圍, 範圍中的新值和舊值會進行比較,判斷是否改變,然後 對應的函數就會被執行。這時,可能會發生下面兩種情況:
- 如果監聽函數沒有改變範圍,瀏覽器會重新標記DOM元素為髒資料,然後模型會被聲明為穩定的,消化周期結束。
- 如果範圍改變中,那麼就會觸發其他的監聽,這時,觀測者保持運行狀態直到沒有其他的觀察者被觸發。對多能觸發10個觀測者,否則會拋出‘Maximum iteration limit exceeded‘ 錯誤
- 髒資料檢查請看 asynchronously.
三種髒資料檢查機制
- 基於引用的髒資料檢查: 使用===來進行新舊值的比較。這種方式對於記憶體和計算都效率都是最好的,因為這種方式不需要複製、遍曆資料。它只是進行引用比較。
- 基於值的髒資料檢查:它會進行深度-對象-樹比較。這意味著,在每一個 $digest 周期, AngularJS 將檢查新老資料是否具有相同的結構。
- 基於集合的髒資料檢查: 它比較物理對象引用。集合觀察者維護了一個對於數組和對象的值複製,在每個消化周期,遍曆新舊值,通過===來比較是否改變。比如,不同於基於引用的髒資料檢查, it goes one-level deep and performs an additional, shallow reference check of the top level items in the collection.
髒檢查的關鍵點:
如果一個模型有2000-3000個觀測者,那麼系統會變慢
就算你的應用足夠快,使使用者不會感到相應延遲,你也不能直接在一頁上展示2000個資訊給使用者。因為這是一個很壞的UI設計,使用者會感動無所適從,但是,使用排序組件或者具有雙向繫結功能的表格,你能夠很好的組織這2000條資料,給使用者更好的展現。
觀測者:
預設情況下,所有綁定到UI的模型資料都被觀察。比如,他們都有一個觀測者註冊到了觀察列表上。你也可以通過$watch 函數手動觸發觀測者。一個觀測者有兩個函數:一個觀察函數和一個觀察運算式。觀察函數是用於資料改變時被觸發的監聽函數,觀察運算式是確定那些資料需要被觀察(範圍)。
Asynchronous nature of dirty cycle:
通過賦值,比如 $scope.username="angular" ,並不會馬上觸發$watch,而是在 $digest 階段才會觸發。這個延遲的好處,是可以將多個模型的更新操作,合并到一個$watch訊息通知中,這樣,可以確保這個$watch通知運行時,沒有其他的 $watches 在允許。如果一個$watch改變了模型的值,它就會被加入$digest周期
|