Redux 上下文中的有效负载是什么 [英] What is a Payload in Redux context

查看:50
本文介绍了Redux 上下文中的有效负载是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以解释一下 PayloadRedux 上下文中究竟是什么吗?请通俗地说,技术术语没有用.因此仍然是混乱.

Can someone please explain what exactly a Payload is in Redux context? In layman terms please, the technical term wasn't useful. Hence still the confusion.

据我所知,Payload 是通过网络传输的实际数据.这是否意味着,Redux 上下文中 actionPayload 意味着在发出动作以更改Redux state?

What I understand is that Payload is the actual data that is transmitted over the network. Does this mean, Payload of an action in Redux context means that the data that is passed as a parameter while an action is emitted to change the Redux state?

推荐答案

tl;dr

Payload 是非官方的、社区接受的(事实上的) 在 Redux 操作对象中保存实际数据的属性的命名约定.

tl;dr

Payload is a non-official, community accepted (de facto) naming convention for the property that holds the actual data in a Redux action object.

官方文档 仅说明Redux 操作必须是普通对象,并且需要字符串操作类型:

The official documentation only states that a Redux action has to be a plain object and needs a string action type:

一个普通对象,描述对您的应用程序有意义的更改.... 操作必须有一个类型字段,指示正在执行的操作类型.类型可以定义为常量并从另一个模块导入.使用字符串作为类型比使用符号更好,因为字符串是可序列化的.除了类型之外,动作对象的结构完全取决于您.如果您有兴趣,请查看 Flux 标准操作 以获取有关如何构建操作的建议.

A plain object describing the change that makes sense for your application. ... Actions must have a type field that indicates the type of action being performed. Types can be defined as constants and imported from another module. It's better to use strings for type than Symbols because strings are serializable. Other than type, the structure of an action object is really up to you. If you're interested, check out Flux Standard Action for recommendations on how actions could be constructed.

社区最佳做法

Redux 中的很多事情都没有标准化,因此您可以最大程度地灵活地以自己的方式做事,但是由于我们大多数人不想为每个日常小细节提出自定义解决方案,因此社区倾向于制定最佳做法.

Community Best Practices

Lots of things are not standardized in Redux so you have maximal flexibility to do the things in your own way, but since most of us don't want to come up with a custom solution to every little everyday detail, the community tends to establish best practices.

为了将这种类型与常规数据分开,使用了 payload 属性.现在,关于什么应该进入 payload 以及什么应该与它处于同一级别是有争议的,但是一个流行的标准(官方文档也推荐)是 Flux Standard Action 声明在官方要求中你可以添加一个payloaderrormeta 属性.这里的有效载荷定义为:

To separate this type from regular data the payload property is used. Now, on what should go into payload and what should be on the same level with it is debatable, but a popular standard (recommended by the official docs too) is the Flux Standard Action which states that among the official requirements you may add a payload, error, and meta property. Here the payload is defined as:

可选的 payload 属性可以是任何类型的值.它代表动作的有效载荷.任何不属于 type 或动作状态的动作信息都应该是 payload 字段的一部分.按照惯例,如果 errortrue,则负载应该是错误对象.

The optional payload property MAY be any type of value. It represents the payload of the action. Any information about the action that is not the type or status of the action should be part of the payload field. By convention, if error is true, the payload SHOULD be an error object.

这篇关于Redux 上下文中的有效负载是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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