State management

https://en.wikipedia.org/wiki/State_management

UI控件的状态管理, 例如按钮的灰化、只读、显示隐藏等。 特殊地一个控件的状态依赖其它控件的状态。

补充:对于控件的依赖不仅仅来自于其它的控件, 也可能来自于后台数据的状态, 例如故事数据变化导致浏览器中 股票的日开线的变化。

State management refers to the management of the state of one or more user interface controls such as text fields, OK buttons, radio buttons, etc. in a graphical user interface. In this user interface programming technique, the state of one UI control depends on the state of other UI controls. For example, a state managed UI control such as a button will be in the enabled state when input fields have valid input values and the button will be in the disabled state when the input fields are empty or have invalid values.

HTTP协议的状态管理

http://hc.apache.org/httpcomponents-client-ga/tutorial/html/statemgmt.html

Originally HTTP was designed as a stateless, request / response oriented protocol that made no special provisions for stateful sessions spanning across several logically related request / response exchanges. As HTTP protocol grew in popularity and adoption more and more systems began to use it for applications it was never intended for, for instance as a transport for e-commerce applications. Thus, the support for state management became a necessity.

3.1. HTTP cookies

An HTTP cookie is a token or short packet of state information that the HTTP agent and the target server can exchange to maintain a session. Netscape engineers used to refer to it as a "magic cookie" and the name stuck.

https://datatracker.ietf.org/doc/rfc6265/?include_text=1

  COOKIE规范

3.  Overview

   This section outlines a way for an origin server to send state
information to a user agent and for the user agent to return the
state information to the origin server. To store state, the origin server includes a Set-Cookie header in an
HTTP response. In subsequent requests, the user agent returns a
Cookie request header to the origin server. The Cookie header
contains cookies the user agent received in previous Set-Cookie
headers. The origin server is free to ignore the Cookie header or
use its contents for an application-defined purpose. Origin servers MAY send a Set-Cookie response header with any
response. User agents MAY ignore Set-Cookie headers contained in
responses with 100-level status codes but MUST process Set-Cookie
headers contained in other responses (including responses with 400-
and 500-level status codes). An origin server can include multiple
Set-Cookie header fields in a single response. The presence of a
Cookie or a Set-Cookie header field does not preclude HTTP caches
from storing and reusing a response. Origin servers SHOULD NOT fold multiple Set-Cookie header fields into
a single header field. The usual mechanism for folding HTTP headers
fields (i.e., as defined in [RFC2616]) might change the semantics of
the Set-Cookie header field because the %x2C (",") character is used
by Set-Cookie in a way that conflicts with such folding.

UI状态管理

https://www.imooc.com/article/19233

一个较大的项目中,会涉及到很多数据,有的是纯前端的,也有来自后台的,随着 View 层交互行为的驱动,整个项目中的数据需要涉及到大量的数据变更,这种变更会十分复杂,以至于我们无法追踪状态的源头,这个时候,就需要采用一些方案,来管理这些数据状态,所谓的状态管理,管理的是从视图层事件源到数据变迁的映射过程。Facebook 公司提出了最早的 Flux 状态管理技术,现在前端框架流行的状态管理,都遵照 Flux 的“单向数据流”理念,所谓单向数据流,基本上是这样运作的: <strong>Action</strong>  <strong>Dispatch</strong>   <strong>Store</strong>  <strong>View</strong>,也就是说,在一个项目中,我们会建立一个状态树,叫做 Store,把所有的 State(状态)全部放在这个 Store 树中,如果你要改变 View,就必须通过一些动作来操作 Store 中的 state. Vue 的状态管理方法 Vuex 就是依照 Flux 的“单向数据流”理念,在 Vuex 的官方文档中,还有一个更为简洁的单向数据流示意图,如下:

vuex

https://segmentfault.com/a/1190000012015742

先引用vuex官网的话:

Vuex 是一个专为 Vue.js 应用程序开发的状态管理模式。它采用集中式存储管理应用的所有组件的状态,并以相应的规则保证状态以一种可预测的方式发生变化。

状态管理模式集中式存储管理 一听就很高大上,蛮吓人的。在我看来 vuex 就是把需要共享的变量全部存储在一个对象里面,然后将这个对象放在顶层组件中供其他组件使用。这么说吧,将vue想作是一个js文件、组件是函数,那么vuex就是一个全局变量,只是这个“全局变量”包含了一些特定的规则而已。

在vue的组件化开发中,经常会遇到需要将当前组件的状态传递给其他组件。父子组件通信时,我们通常会采用 props + emit 这种方式。但当通信双方不是父子组件甚至压根不存在相关联系,或者一个状态需要共享给多个组件时,就会非常麻烦,数据也会相当难维护,这对我们开发来讲就很不友好。vuex 这个时候就很实用,不过在使用vuex之后也带来了更多的概念和框架,需慎重!

State management(状态管理)的更多相关文章

  1. 设计模式之State(状态)(转)

    State的定义: 不同的状态,不同的行为;或者说,每个状态有着相应的行为. 何时使用? State模式在实际使用中比较多,适合"状态的切换".因为我们经常会使用If elseif ...

  2. angular2 学习笔记 ( 状态管理 state management )

    更新 : 2017-12-29  ng5 移除 zone.js https://zhuanlan.zhihu.com/p/29577461 zone 的用途就是拦截游览器事件, 比如 click, a ...

  3. Web前端的状态管理(State Management)

    背景 我相信很多朋友跟我一样,初次听到什么Flux, Redux, Vuex,状态管理的时候是一脸懵逼的.因为在外面之前前端大部分开发的时候,根本没有那么多的概念.自从ReactJS火爆后,什么Flu ...

  4. Spark Streaming揭秘 Day14 State状态管理

    Spark Streaming揭秘 Day14 State状态管理 今天让我们进入下SparkStreaming的一个非常好用的功能,也就State相关的操作.State是SparkStreaming ...

  5. vuex状态管理,state,getters,mutations,actons的简单使用(一)

    之前的文章中讲过,组件之间的通讯我们可以用$children.$parent.$refs.props.data... 但问题来了,假如项目特别大,组件之间的通讯可能会变得十分复杂... 这个时候了我们 ...

  6. 组件之间的通讯:vuex状态管理,state,getters,mutations,actons的简单使用(一)

    之前的文章中讲过,组件之间的通讯我们可以用$children.$parent.$refs.props.data... 但问题来了,假如项目特别大,组件之间的通讯可能会变得十分复杂... 这个时候了我们 ...

  7. saltstack(五) saltstack的state状态管理

    一,YAML语法 首先先了解一下YAML,默认的SLS文件的renderer是YAML renderer.YAML是一个有很多强大特性的标记性语言.Salt使用了一个YAML的小型子集,映射非常常用的 ...

  8. [译]面向初学者的Asp.Net状态管理技术

    介绍 本文主要讲解Asp.Net应用程序中的状态管理技术(Asp.Net中有多种状态管理技术),并批判性地分析所有状态管理技术的优缺点. 背景 HTTP是无状态的协议.客户端发起一个请求,服务器响应完 ...

  9. asp.net 的状态管理

    状态管理 (state management) 在Web应用程序中,一向是很重要的课题,良好的状态管理可以帮助开发人员发展出具有状态持续能力的应用程序(像是工作流程型应用程序或是电子商务应用程序),但 ...

随机推荐

  1. hexo博客添加功能

    设置Hexo主题模式 Hexo主题中,有三种不同的模式,通过切换模式,让NexT主题显示不一样的样式.在NexT根目录下有一个同样名称为_config.yml,为了区分hexo根目录下的_config ...

  2. 【原创】hdu1698 Just a Hook(线段树→区间更新,区间查询)

    学习线段树第二天,这道题属于第二简单的线段树,第一简单是单点更新,这个属于区间更新. 区间更新就是lazy思想,我来按照自己浅薄的理解谈谈lazy思想: 就是在数据结构中,树形结构可以线性存储(线性表 ...

  3. CF1131F Asya And Kittens(Kruskal重构树,启发式合并)

    这题难度1700,我感觉又小了…… 这题虽然没几个人是用kruskal重构树的思想做的,但是我是,所以我就放了个kruskal重构树的标签. 题目链接:CF原网 题目大意:有一个长为 $n$ 的排列, ...

  4. Typescript学习笔记(一)基础类型

    为了面向ng2和前端未来,开始搞向ts,ts是微软出的一枚语言,作为es6的超集,他出的一些特性还是蛮好用的(略坑).对于我等纯前端(从开始就接触javascript)的人来说,真想说,这特么什么鬼. ...

  5. 编写高质量代码:改善Java程序的151个建议 --[26~36]

    提防包装类型的null值 public static int testMethod(List<Integer> list) { int count = 0; for (Integer i ...

  6. poj2083 Fractal

    我一开始的想法是间断性的输出空格和solve(k-1) 但是发现问题很大. 雨菲:可以用一个数组保存啊 我:那不爆了? 雨菲:不会爆. 我一算:729 × 729,还真没爆. 然后就直接WA了.... ...

  7. 洛谷P4248 差异

    题意:求所有后缀两两之间的最长公共前缀的长度之和. 解:这道题让我发现了一个奇妙的性质:所有后缀两两最长公共前缀长度之和 和 所有前缀两两最长公共后缀之和的值是相等的,但是每一组公共前/后缀是不同的. ...

  8. 浏览器直接显示html代码,不解析代码

    在某些时候,我们可能因为某些特殊的原因,不想让浏览器解析html代码. 1,把代码放到js中,如下 <script type='text/html' style='display:block'& ...

  9. 斯坦福大学公开课机器学习: advice for applying machine learning | deciding what to try next(revisited)(针对高偏差、高方差问题的解决方法以及隐藏层数的选择)

    针对高偏差.高方差问题的解决方法: 1.解决高方差问题的方案:增大训练样本量.缩小特征量.增大lambda值 2.解决高偏差问题的方案:增大特征量.增加多项式特征(比如x1*x2,x1的平方等等).减 ...

  10. 整合shiro出现【Correct the classpath of your application so that it contains a single, compatible version of org.quartz.Scheduler】

    跑的时候出现错误: Description: An attempt was made to call the method org.quartz.Scheduler.getListenerManage ...