MVC 与通量?双向还是单向?

MVC vs. Flux ? Bidirectional vs. Unidirectional?

查看下图(解释了 MVC),我看到了单向数据流。

那么为什么我们在证明 Flux 的同时认为 MVC 具有双向数据流呢?

因为在 Javascript 框架中,MVC 并不像您描述的那样工作。 UI 通常与模型进行双向通信,如:

  1. 用户在视图中输入内容
  2. MVC 框架绑定 onchange() 来更新模型。
  3. Ajax 请求引入新的模型数据。
  4. MVC 框架更新视图输入的值以匹配模型。

在 Flux 架构中,UI 只会向调度程序触发具有类型和关联数据的独立操作,然后调度程序会像任何后台 ajax 方法更新模型一样更新模型.

参考: http://www.thesoftwaresimpleton.com/blog/2013/03/23/client-side-mvc/

"Client Side MVC is completely different than Server Side MVC"

"We are setting up a two way communication between two objects..."

"In short we are wiring together the value of the firstName property of the Person object to the value property of the input."

http://guides.emberjs.com/v1.10.0/object-model/bindings/

bindings in Ember.js can be used with any object, not just between views and models.

我是一名嵌入式开发人员,我在我的应用程序中使用 MVC 模式。我的应用程序非常小,我已经将架构设置为几乎是单向 MVC。但是,我读了这篇文章,解释了客户端 MVC,以及一些关于 MVC 和 FLUX 之间差异的想法。

参考: http://www.christianalfoni.com/articles/2015_08_02_Why-we-are-doing-MVC-and-FLUX-wrong

传统 MVC

|------|  request   |------------|  request   |-------|
|      | ---------> |            | ---------> |       |
| VIEW |  response  |            |  response  |       |
|      | <--------- |            | <--------- |       |
|------|            |            |            |       |
                    | CONTROLLER |            | MODEL |
|------|  request   |            |  request   |       |
|      | ---------> |            | ---------> |       |
| VIEW |  response  |            |  response  |       |
|      | <--------- |            | <--------- |       |
|------|            |------------|            |-------|

通量

 COMPONENTS          ACTION CREATORS           STORES

    |----------------------<<<<-------------------|
    |                                             |
|------|            |------------|            |-------|
|      |  request   |            |  request   |       |
| VIEW | ---------> |            | ---------> | MODEL |----
|      |            |            |            |       |   |
|------|            |            |            |-------|   |
                    | CONTROLLER |                        |
|------|            |            |            |-------|   |
|      |  request   |            |  request   |       |   |
| VIEW | ---------> |            | ---------> | MODEL |   |
|      |            |            |            |       |   |
|------|            |------------|            |-------|   |
   | |                                           |        |
   | |--------------------<<<<-------------------|        |
   |----------------------<<<<----------------------------|

真实而纯粹的 MVC 是单向的。从问题中粘贴的维基百科图表可以清楚地看出。

十多年前,当像 Apache Struts 这样的服务器端框架实现了一种称为 Model View Presenter (MVP) 模式的 MVC 变体时,它们让每个请求都通过控制器,每个响应都通过控制器返回.每个人都继续称它为 MVC。由于网络的固有特性,如果视图不发送请求或更新,模型中的任何更改都无法传播到视图。所以 Pure MVC 没有实现。而是实施了 MVP。

几年前,当像 Angular、Ember、Knockout 这样的框架在前端实现 MVC 时,他们实现了 MVC 的另一种变体,称为 Model View ViewModel (MVVM) 模式,很少有人继续称之为它是 MVC。 (很少有人意识到术语并不重要,并将其称为 MVW(W 代表 Whatever)),none 他们中实现了纯 MVC。

React诞生时,他们借机实现了纯MVC(不是MVP或MVVM),并稍加改动就更名为Flux。我觉得 Flux 是 MVC 的另一种变体。虽然 Flux/React 团队说它不是 MVC,但我看到这两种架构(Flux 和 MVC)之间有很多相似之处。

有些人采用术语 MVC 来指代 JavaScript others had pointed out were not pure MVC but were a variation that could be referred to as MVP (Backbone), MVVM (Angular 1) or more broadly MV* (also see ) 的框架。

Facebook introduced Flux, they compared it to the issues with MVVM/MVP/MV* 时,却混淆了术语 MVC。

对于观看此视频的纯 MVC 开发人员来说,Facebook 声明的 MVC 问题没有意义,Facebook 对 Flux 的描述比他们描述的 MVVM 系统更接近 MVC:

The core problem is that they were "doing" MVC wrong. Then they fixed it, but decided to rebrand it and say they'd invented the pattern of decoupling data, view, and event handling

YouTube comment

Looks like your programmers created flux because they didn't know how to properly use MVC and event dispatchers.

YouTube comment