redux 函数式组件_如何从函数式编程的角度学习Redux

redux 函数式组件

Discover Functional JavaScript was named one of the best new Functional Programming books by BookAuthority!

“发现功能JavaScript”BookAuthority评为最佳新功能编程书籍之一

Redux is a state container that promotes the use of functional programming for managing state.

Redux是一个状态容器,可促进使用功能编程来管理状态。

I would say that the Redux ecosystem has evolved in an architectural pattern that gives best practices on how to organize an application.

我要说的是,Redux生态系统已经以一种体系结构模式发展,该体系结构为如何组织应用程序提供了最佳实践。

纯函数 (Pure Functions)

Pure functions produce the same output value, given the same input. Pure functions have no side-effects.

给定相同的输入,纯函数会产生相同的输出值。 纯函数没有副作用。

Pure functions don’t mutate data, so the question is how can we change state and at the same time use pure functions. Redux proposes a solution: we write pure functions and let the library apply them and do the state change.

纯函数不会改变数据,因此问题是我们如何更改状态并同时使用纯函数。 Redux提出了一个解决方案:我们编写纯函数,然后让库应用它们并进行状态更改。

The application does state change, but the mutation is encapsulated behind the Redux store.

该应用程序确实会进行状态更改,但是该突变被封装在Redux存储后面。

不变性 (Immutability)

An immutable value is a value that, once created, cannot be changed.

不变值是一旦创建就无法更改的值。

The state value is immutable, so each time we want to change the state we need to create a new immutable value.

状态值是不可变的,因此每次我们要更改状态时,都需要创建一个新的不可变值。

The value of state is immutable but state can change. There is no point to use a library to manage state that doesn’t change. We can use a plain object to store that kind of data.

状态的值是不变的,但状态可以更改。 没有必要使用库来管理不变的状态。 我们可以使用一个普通的对象来存储这种数据。

建筑 (Architecture)

Redux suggests that we split a practical application into the following parts:

Redux建议我们将实际应用分为以下几部分:

  • Presentation Components

    演示组件
  • Action Creators (aka Synchronous Action Creators)

    动作创建者(又名同步动作创建者)
  • Reducers

    减速器
  • Asynchronous Action Creators

    异步动作创建者
  • API Utils/Gateways

    API实用程序/网关
  • Selectors

    选择器
  • Container Components

    容器组件

Discover Functional JavaScript was named one of the best new Functional Programming books by BookAuthority!

发现功能JavaScript被称为 BookAuthority最好的新功能编程书籍

For more on applying functional programming techniques in React take a look at Functional React.

有关在React中应用函数式编程技术的更多信息,请查看 Functional React

Learn functional React, in a project-based way, with Functional Architecture with React and Redux.

通过带有React和Redux的功能架构 ,以基于项目的方式学习功能性React

Follow on Twitter

在Twitter上关注

翻译自: https://www.freecodecamp.org/news/how-to-learn-redux-from-a-functional-programming-perspective-720892f704c6/

redux 函数式组件

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值