Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finish the translation of background.md #69

Merged
merged 6 commits into from
Oct 30, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 54 additions & 32 deletions source/_posts/en/tutorial/background.md
Original file line number Diff line number Diff line change
@@ -1,71 +1,93 @@
---
title: 背景
title: Background
categories:
- tutorial
---

引言
Introduction
-----

2008年,V8 引擎随 Chrome 浏览器横空出世,JavaScript 这门通用的 Web 脚本语言的执行效率得到质的提升。 V8 引擎的出现,注定是 JavaScript 发展史上一个光辉的里程碑。它的出现,让当时研究高性能服务器开发、长时间一筹莫展的 [Ryan Dahl](http://tinyclouds.org/) 有了新的、合适的选择,不久,在2009年的柏林的 JSConf 大会上,基于 JavaScript 的服务端项目 Node.js 正式对外发布。Node.js 的发布,不仅为开发者带来了一个高性能的服务器,还很大程度上推动了前端的工程化,带来了前端的大繁荣。与此同时,因为 JavaScript 执行效率的巨大提升,越来越多的业务逻辑开始在浏览器端实现,前端逻辑越来越重,前端架构随之提上日程。于是,我们谈论的主角,MVVM 模式,走进了 Web 前端的架构设计中。
Chrome released the V8 JavaScript engine in 2008 and enormously improved the performance of JavaScript.
andycall marked this conversation as resolved.
Show resolved Hide resolved

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

V8 engine was shipped with Chrome

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

of running JavaScript?


概念
The emergence of the V8 engine is destined to be a significant milestone in the history of JavaScript development.

It provides the best choice for [Ryan Dahl](http://tinyclouds.org/), who want to write a high-performance server and with no progress for a long time.
andycall marked this conversation as resolved.
Show resolved Hide resolved
andycall marked this conversation as resolved.
Show resolved Hide resolved

Soon after, at the JSConf in Berlin in 2009, JavaScript-based server project Node.js officially released.
andycall marked this conversation as resolved.
Show resolved Hide resolved

It gives JavaScript developer a high-performance server and highly promotes workflow tools for Front-End development.
andycall marked this conversation as resolved.
Show resolved Hide resolved

In the meantime, because of the performance improved, more and more business logic migrate from server side to browser.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

improved -> improvement
migrate -> have migrated

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

诶,这里是用improvement吗?不是性能提升之后才能...


Browser-side business logic becomes complex, and developer realized that they need a framework to solve these problems.

San, the MVVM JavaScript framework. The architecture solution for web development.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这段话不对? The architecture solution for web development


Concept
-----

MVVM 模式,顾名思义即 Model-View-ViewModel 模式。它萌芽于2005年微软推出的基于 Windows 的用户界面框架 WPF ,前端最早的 MVVM 框架 [knockout](https://github.com/knockout/knockout) 在2010年发布。
MVVM(Model-View-ViewModel) pattern. First invented in WPF framework from windows user application framework in 2005.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First invented -> is first introduced
WPF - a Windows UI framework

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里不需要指明是WPF吗?


一句话总结 Web 前端 MVVM:操作数据,就是操作视图,就是操作 DOM(所以无须操作 DOM )。
The earliest MVVM JavaScript framework -- [knockout](https://github.com/knockout/knockout), was released in 2010.
andycall marked this conversation as resolved.
Show resolved Hide resolved

无须操作 DOM !借助 MVVM 框架,开发者只需完成包含 **声明绑定** 的视图模板,编写 ViewModel 中业务数据变更逻辑,View 层则完全实现了自动化。这将极大的降低前端应用的操作复杂度、极大提升应用的开发效率。MVVM 最标志性的特性就是 **数据绑定** ,MVVM 的核心理念就是通过 **声明式的数据绑定** 来实现 View 层和其他层的分离。完全解耦 View 层这种理念,也使得 Web 前端的单元测试用例编写变得更容易。
With MVVM pattern, data are equal to views, and there is no need to write any code to operate the DOM. All the DOM mutations are take over by MVVM frameworks.
andycall marked this conversation as resolved.
Show resolved Hide resolved

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is no need to touch DOM directly?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这样更好吗?


MVVM,说到底还是一种分层架构。它的分层如下:
JavaScript developer only need to write template including **declare bindings syntax**, the business logic focused on application data in ViewModel.
andycall marked this conversation as resolved.
Show resolved Hide resolved

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with business logic focusing on ...

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

templates including ...


- Model: 域模型,用于持久化
- View: 作为视图模板存在
- ViewModel: 作为视图的模型,为视图服务
The template will update automatically when the binding data changed. This design deeply reduces the complexity of the application and increase the efficiency of application development.
andycall marked this conversation as resolved.
Show resolved Hide resolved

### Model 层
The most significant feature of MVVM pattern is the **data bindings**. It use **data bindings** syntax to separate the View layer from other layers and without any UI code. Unit test code becomes more easily.
andycall marked this conversation as resolved.
Show resolved Hide resolved
andycall marked this conversation as resolved.
Show resolved Hide resolved
andycall marked this conversation as resolved.
Show resolved Hide resolved

Model 层,对应数据层的域模型,它主要做`域模型的同步`。通过 Ajax/fetch 等 API 完成客户端和服务端业务 Model 的同步。在层间关系里,它主要用于抽象出 ViewModel 中视图的 Model。
After all, MVVM pattern is a Hierarchical architecture, organized as followed:
andycall marked this conversation as resolved.
Show resolved Hide resolved

### View 层
- Model: used to store persistence data
andycall marked this conversation as resolved.
Show resolved Hide resolved
- View: the template including **data bindings** syntax
andycall marked this conversation as resolved.
Show resolved Hide resolved
- ViewModel: the mirror of template in data ways, auto sync changes with view.
andycall marked this conversation as resolved.
Show resolved Hide resolved
andycall marked this conversation as resolved.
Show resolved Hide resolved

View 层,作为视图模板存在,在 MVVM 里,整个 View 是一个动态模板。除了定义结构、布局外,它展示的是 ViewModel 层的数据和状态。View 层不负责处理状态,View 层做的是 **数据绑定的声明**、 **指令的声明**、 **事件绑定的声明**。
### Model

### ViewModel
Modal layer. The model used to store data. Use Ajax/fetch API to keep client and server data sync. It used to abstract the View's Model of ViewModel in layer relations.
andycall marked this conversation as resolved.
Show resolved Hide resolved
andycall marked this conversation as resolved.
Show resolved Hide resolved

ViewModel 层把 View 需要的层数据暴露,并对 View 层的 **数据绑定声明**、 **指令声明**、 **事件绑定声明** 负责,也就是处理 View 层的具体业务逻辑。ViewModel 底层会做好绑定属性的监听。当 ViewModel 中数据变化,View 层会得到更新;而当 View 中声明了数据的双向绑定(通常是表单元素),框架也会监听 View 层(表单)值的变化。一旦值变化,View 层绑定的 ViewModel 中的数据也会得到自动更新。

### 前端 MVVM 图示
### View

View: the template. In MVVM pattern, The whole View is a dynamic template. It shows the ViewModel's data and state besides of structure and layout. View does not deal with component state, the main character of View is to declare data bindings, commands, and events.
andycall marked this conversation as resolved.
Show resolved Hide resolved

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It reflects the data/state of ViewModel along with layout structures,


### ViewModel

ViewModel exports the data which View needed and control View's data bindings, commands, event declaring.
andycall marked this conversation as resolved.
Show resolved Hide resolved
andycall marked this conversation as resolved.
Show resolved Hide resolved

Developers write custom business logic code to process the data from View. When the data from ViewModel changed, View will get updated automatically; When View declare the two-way bindings syntax, the framework will add the event handler to the DOM, and update the ViewModel's data when DOM get user's input.
andycall marked this conversation as resolved.
Show resolved Hide resolved
andycall marked this conversation as resolved.
Show resolved Hide resolved

### MVVM diagram

<img src="https://raw.githubusercontent.com/X-Jray/blog/master/assets/mvvm.png" width="540" alt="前端MVVM">

如图所示,在前端 MVVM 框架中,往往没有清晰、独立的 Model 层。在实际业务开发中,我们通常按 **Web Component** 规范来组件化的开发应用,Model 层的域模型往往分散在在一个或几个 Component 的 ViewModel 层,而 ViewModel 层也会引入一些 View 层相关的中间状态,目的就是为了更好的为 View 层服务。
In MVVM framework. There is no distinct boundary of which kinds of code belong to Model. In actual production development, we usually use **Web Component** standard to manage our code. The concept of Model sometimes been separated in one or many component's ViewModel, and ViewModel have some temporary state, to better serve the View layer/
andycall marked this conversation as resolved.
Show resolved Hide resolved
andycall marked this conversation as resolved.
Show resolved Hide resolved

开发者在 View 层的视图模板中声明 **数据绑定**、 **事件绑定** 后,在 ViewModel 中进行业务逻辑的 **数据** 处理。事件触发后,ViewModel 中 **数据** 变更, View 层自动更新。因为 MVVM 框架的引入,开发者只需关注业务逻辑、完成数据抽象、聚焦数据,MVVM 的视图引擎会帮你搞定 View。因为数据驱动,一切变得更加简单。
Developer write **declare bindings**, **event bind** in the View template, and write business logic process in ViewModel. After the event fired, the data of ViewModel changed and View updating automatically. With the power of MVVM framework, developers only need to focus on business logic, the abstraction of data and MVVM framework will help you make everything right in the View. Data-driven make everything simpler.
andycall marked this conversation as resolved.
Show resolved Hide resolved

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

business logic process → business logic process

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the data of ViewModel will change and View will update

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simplifies everything?


MVVM框架的工作
What MVVM framework do
-----
MVVM can increase the productivity of application development. It's amazing! But, what MVVM framework do?
andycall marked this conversation as resolved.
Show resolved Hide resolved

不可置否,MVVM 框架极大的提升了应用的开发效率。It's amazing!But,MVVM 框架到底做了什么?

- 视图引擎
- View Engine

视图引擎:我是视图引擎,我为 View 层作为视图模板提供强力支持,开发者,你们不需要操作 DOM ,丢给我来做!
View Engine: fully support for template parsing and rendering. As a developer, you don't need to known what is DOM and how to operate it.
andycall marked this conversation as resolved.
Show resolved Hide resolved

- 数据存取器
- Data Store

数据存取器:我是数据存取器,我可以通过 `Object.defineProperty()` API 轻松定义,或通过自行封装存取函数的方式曲线完成。我的内部往往封装了 **发布/订阅模式**,以此来完成对数据的监听、数据变更时通知更新。我是 **数据绑定** 实现的基础。
Data store: implemented by `Object.defineProperty()` API, or completed by self-encapsulating functions. Integrated with pub/sub patten to watch the data changed and subscribe the view to update when changing the data. This is the basic of **data bindings**.
andycall marked this conversation as resolved.
Show resolved Hide resolved

- 组件机制
- Component Mechanism

组件机制:我是组件机制。有追求的开发者往往希望按照面向未来的组件标准 - **Web Components** 的方式开发,我是为了满足你的追求而生。MVVM 框架提供组件的定义、继承、生命周期、组件间通信机制,为开发者面向未来开发点亮明灯。
Component Mechanism: Developer who have highly pursue hope to use the next generation of the component standard -- **Web Components**. San was born to satisfy your pursuit. The MVVM framework provides component definition, inheritance, lifecycle, and inter-component communication mechanisms to enable developers to develop bright lights for the future.
andycall marked this conversation as resolved.
Show resolved Hide resolved

- more...

结语
The end
-----

>有了前端 MVVM 框架,应用开发如此简单!
> With MVVM framework, application development more simple any more!

前端 MVVM 已是趋势,是大型 Web 应用开发效率提升的利器。由百度 EFE 出品的 MVVM 框架 - [san](https://baidu.github.io/san/),在保持功能强大、特性支持完整的前提下,还兼顾到IE8的市场份额,对老版本浏览器提供了良好的兼容性,更难能可贵的是 GZip 后体积仅 **11k**, 现已为百度内多个产品提供了强劲驱动,可谓百度 EFE 又一精工之作!开源的 [san](https://baidu.github.io/san/) 欢迎广大开发者体验、使用,更欢迎广大开发者加入到 [san 生态](https://github.com/baidu?utf8=%E2%9C%93&q=san&type=&language=) 的建设中来,让 [san](https://baidu.github.io/san/) 变得更好!
MVVM framework had been a trend, a tool for improving the efficiency of large-scale Web application development. San was produced by Baidu EFE - [San](https://baidu.github.io/San/); A JavaScript framework compatible with IE8 with all the powerful and complete features of MVVM. What is more valuable is that the GZipped source code is only **11k** in size. There are large products in Baidu based on the San. It is another masterpiece of Baidu EFE! MVVM is already the trend; it's the most powerful techniques for large web applications. [San](https://baidu.github.io/San/) is an open source project and contributions always welcome. We warmly welcome developers to join the San Ecosystem and make San better and better.