MVC 与 Flux ?双向与单向? [英] MVC vs. Flux ? Bidirectional vs. Unidirectional?

查看:16
本文介绍了MVC 与 Flux ?双向与单向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Looking at the following diagram (which explains MVC), I see unidirectional data flow.

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

So why do we consider MVC to have bidirectional data flow while justifying Flux ?

推荐答案

因为在 Javascript 框架中,MVC 无法按照您描述的方式工作.UI 通常与模型双向通信,如下所示:

Because in Javascript frameworks the MVC does not work the way you depicted. The UI generally communicates bi-directionally with the model, as in:

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

在 Flux 架构中,UI 只会将具有类型和关联数据的独立操作触发到调度程序,然后调度程序会以与任何后台 ajax 方法更新模型相同的方式更新模型.

In Flux architecture, the UI would only fire an independent action with type and associated data to a dispatcher which would then update the model the same way any background ajax method would update the model.

参考:http://www.thesoftwaresimpleton.com/blog/2013/03/23/客户端-mvc/

客户端 MVC 与服务器端 MVC 完全不同"

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

我们正在两个对象之间建立双向通信......"

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

简而言之,我们将 firstName 属性的值连接在一起Person 对象到输入的 value 属性."

"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-模型/绑定/

Ember.js 中的绑定可以用于任何对象,不仅仅是在视图和模型.

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

这篇关于MVC 与 Flux ?双向与单向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆