從Knockout到Angular的架構演變


2008年第一次在WPF中使用MVVM模式之后,就一直熱衷於耦合隔離、模塊化與重構、UI和邏輯分離、單元測試以及后面的領域模型。談及MVVM模式,自己也開發過一套框架,但沒有長期更新和維護,所以索性就一直使用Prism和MVVM Light。到2012年的時候,看到HTML5的大行其道和Silverlight的衰落,果斷把主要精力投入到ASP.NET MVC和Knockout的開發和研究當中,雖然Knockout比較容易上手且方便使用,但總覺得沒有在WPF和Silverlight中使用MVVM那么酣暢淋漓。

 

WPF/Silverlight

Web

MVVM框架

· Prism

· MVVMLight

· Caliburn(Caliburn.Micro)

· MVVM Helpers

· Cinch

· MVVMFoundation

· AngularJS

· Knockout (or use Durandal)

· Backbone.js

· Ember.js

· Epitome

· Agility.js

盡管后面嘗試過其他框架,比如通過Durandal 實現SPA讓我之前對Knockout的種種不便有所改觀,但始終還是有所缺憾,直至現在使用Angular,尤其是Angular + TypeScript才發現一切問題都不復存在了。

(之前使用WPF/Silverlight的最大問題其實是很難招到合適的人員做美工和設計,因為很少人會專門投入到Blend和XAML的研究當中,但現在使用Web就會發現資源是那么的豐富,不管是人力資源還是開源社區)

功能

WPF/Silverlight

AngularJS

UI

XAML

HTML+CSS

設計工具 Design/Blend and Visual Studio All professional design tools

控件模板和自定義控件

Control Templates or Custom Control

Custom Directives (Element)

動畫

System.Windows.Media.Animation

CSS3 Animations and/or JavaScript via ngAnimate

樣式和模板

XAML/Resources

CSS3 and LESS

樣式繼承和關聯

Implicit Styles and/or BasedOn

LESS Mixins

轉換和過濾

IValueConverter

Filters

綁定Model到UI

ViewModel and DataContext

Controller and Scope

服務重用

Prism Service Locator

Custom Services/Service Factory

事件

Routed Events

$emit and $broadcast

模塊化

MEF and/or Prism Module Catalog

Angular Modules

Services

WCF or WCF RIA Services

RESTful services (accessed via the Angular $http/$resource Services)

導航與路由

UriMapper

Routing

內部組件通信

Prism Event Aggregator  or Messager

Shared Services

視頻

MediaElement

HTML5 Video Element

脫離瀏覽器運行

Yes

Yes, via Chrome Apps

封裝UI邏輯

Behaviors

Custom Directives (Attribute)

UI與邏輯分離

Control or Data Templates

CSS/LESS

跨域請求

Access-Policy

CORS

單向數據綁定

BindingMode.One

Ng-Bind

雙向數據綁定

BindingMode.TwoWay

Ng-Model

單向數據源綁定

BindingMode.OneTime

Ng-Model

開源模板

Modern UI or MahApps

Bootstrap or Foundation

瀏覽器支持

Need silverlight plugin or XBAP

All supported

所以現在將架構由Knockout到Angular的調整並使用到新項目的開發,具體如下:

https://images0.cnblogs.com/blog/47784/201408/312227322046408.png

 

image

 

image

到目前為止,還沒有發現Angular有什么大的技術難題或者性能問題,如果有Angular項目經驗的朋友,不妨留言討論,學習共勉!

另外,很多人發郵件問WPF是否會像Silverlight一樣消亡,其實這個問題很難回答,尤其在目前這個不光是微軟主導的開發環境下(HTML5流行度遠甚於XAML,IOS和Android的大行其道與Windows Phone的不溫不火,Windows的命運尚不知曉),可能連微軟自己也不能很好地解答這個問題,所以一切只能由市場和時間來慢慢決定。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM