Skip to main content

Redux 常见问题解答:各种各样的

¥Redux FAQ: Miscellaneous

目录

¥Table of Contents

各种各样的

¥Miscellaneous

有没有更大的、“真正的”Redux 项目?

¥Are there any larger, “real” Redux projects?

是的,很多!仅举几例:

¥Yes, lots of them! To name just a few:

还有很多很多!Redux Addons Catalog 有 基于 Redux 的应用和示例列表,指向各种大大小小的实际应用。

¥And many, many more! The Redux Addons Catalog has a list of Redux-based applications and examples that points to a variety of actual applications, large and small.

更多信息

¥Further information

文档

¥Documentation

讨论

¥Discussions

如何在 Redux 中实现身份验证?

¥How can I implement authentication in Redux?

身份验证对于任何实际应用都是必不可少的。在进行身份验证时,你必须记住,你组织应用的方式不会发生任何变化,并且你应该以与任何其他功能相同的方式实现身份验证。它相对简单:

¥Authentication is essential to any real application. When going about authentication you must keep in mind that nothing changes with how you should organize your application and you should implement authentication in the same way you would any other feature. It is relatively straightforward:

  1. LOGIN_SUCCESSLOGIN_FAILURE 等创建动作常量。

    ¥Create action constants for LOGIN_SUCCESS, LOGIN_FAILURE, etc.

  2. 创建将凭据、表示身份验证是否成功的标志、令牌或错误消息作为有效负载的操作创建器。

    ¥Create action creators that take in credentials, a flag that signifies whether authentication succeeded, a token, or an error message as the payload.

  3. 使用 Redux Thunk 中间件或任何你认为合适的中间件创建一个异步操作创建器,以向 API 发出网络请求,如果凭证有效,该 API 将返回令牌。然后将令牌保存在本地存储中,或者在失败时向用户显示响应。你可以从上一步中编写的操作创建者中执行这些副作用。

    ¥Create an async action creator with Redux Thunk middleware or any middleware you see fit to fire a network request to an API that returns a token if the credentials are valid. Then save the token in the local storage or show a response to the user if it failed. You can perform these side effects from the action creators you wrote in the previous step.

  4. 创建一个 reducer,为每个可能的身份验证案例(LOGIN_SUCCESSLOGIN_FAILURE 等)返回下一个状态。

    ¥Create a reducer that returns the next state for each possible authentication case (LOGIN_SUCCESS, LOGIN_FAILURE, etc).

更多信息

¥Further information

文章

¥Articles

示例

¥Examples

¥Libraries