美文网首页
redux一些笔记

redux一些笔记

作者: 一点金光 | 来源:发表于2019-08-21 08:17 被阅读0次

它是什么

a predictable(可预料的) state container for JavaScript apps.

为什么要

01.It helps you write applications that behave consistently(行为固定) , run in different environments (client, server, and native)(多端运行) , and are easy to test(测试简单) .
02.On top of that, it provides a great developer experience(开发体验), such as live code editing combined with a time traveling debugger.
03.can use Redux together with React, or with any other view library(集成软件).
04.It is tiny (2kB, including dependencies)(轻量微小).

如何使用

了解概念
If you're brand new to Redux and want to understand the basic concepts, see:
01.The Motivation behind building Redux(了解意图), the Core Concepts(核心概念), and the Three Principles(三个原则).
02.The basic tutorial in the Redux docs(基础教程).
03.If you learn best by looking at code and playing with it, check out our list of Redux example applications(示例应用), available as separate projects in the Redux repo, and also as interactive online examples on CodeSandbox.
......

安装软件

npm install --save redux

基本架构

//导入类库
import { createStore } from 'redux'

/**
 * This is a reducer, a pure function with (state, action) => state signature.
 * It describes how an action transforms the state into the next state.
 *
 * The shape of the state is up to you: it can be a primitive, an array, an object,
 * or even an Immutable.js data structure. The only important part is that you should
 * not mutate the state object, but return a new object if the state changes.
 *
 * In this example, we use a `switch` statement and strings, but you can use a helper that
 * follows a different convention (such as function maps) if it makes sense for your
 * project.
 */
function counter(state = 0, action) {
  switch (action.type) {
    case 'INCREMENT':
      return state + 1
    case 'DECREMENT':
      return state - 1
    default:
      return state
  }
}
 
//
let store = createStore(counter)

//添加订阅
store.subscribe(() => console.log(store.getState()))

//发布消息
store.dispatch({ type: 'INCREMENT' })// 1
store.dispatch({ type: 'INCREMENT' })// 2
store.dispatch({ type: 'DECREMENT' })// 1

官方文档

01.Introduction(介绍篇)
02.Basics(基础篇)
03.Advanced(进阶篇)
04.Recipes(秘诀篇)
05.FAQ(问答篇)
06.Troubleshooting(问题篇)
07.Glossary(术语篇)
08.API Reference(接口篇)

一些示例

01.Counter Vanilla: Source
02.Counter: Source | Sandbox
03.Todos: Source | Sandbox
04.Todos with Undo: Source | Sandbox
05.Todos w/ Flow: Source
06.TodoMVC: Source | Sandbox
07.Shopping Cart: Source | Sandbox
08.Tree View: Source | Sandbox
09.Async: Source | Sandbox
10.Universal: Source
11.Real World: Source | Sandbox

特别鸣谢

01.The Elm Architecture for a great intro to modeling state updates with reducers;
02.Turning the database inside-out for blowing my mind;
03.Developing ClojureScript with Figwheel for convincing me that re-evaluation should “just work”;
04.Webpack for Hot Module Replacement;
05.Flummox for teaching me to approach Flux without boilerplate or singletons;
06.disto for a proof of concept of hot reloadable Stores;
07.NuclearJS for proving this architecture can be performant;
08.Om for popularizing the idea of a single state atom;
09.Cycle for showing how often a function is the best tool;
10.React for the pragmatic innovation.

官方图标

You can find the official logo on GitHub.

更新记录

01.This project adheres to Semantic Versioning.
02.Every release, along with the migration instructions, is documented on the GitHub Releases page.

其赞助者

01.The work on Redux was funded by the community.
02.Meet some of the outstanding(杰出的) companies that made it possible:
Webflow
Ximedes
03.See the full list of Redux patrons, as well as the always-growing list of people and companies that use Redux.

参考文献

redux.offical-readme[p].npmjs
redux.source-code.github

相关文章

  • Redux 笔记一:简单串讲

    Redux 笔记一:简单串讲 React 笔记一:简单串讲 Redux 笔记一:简单串讲 介绍 Redux并不是R...

  • redux一些笔记

    它是什么 a predictable(可预料的) state container for JavaScript a...

  • Redux初步理解

    Redux笔记 参考理解 Redux 中文文档Redux 阮一峰 严格的单向数据流是Rduex设计核心。 Redu...

  • Redux-saga

    Redux-saga学习笔记说到中间件Redux-saga之前不得不提一下Redux-thunk(详细请访问:ht...

  • 了解Redux源码

    前言 了解redux,最好可以结合一些其他的东西来里了解redux相关原理。如: flux的一些思想 redux的...

  • React 初探(五)- Redux、React-Redux

    概述 之前写了一些 Redux 的一些示例,这次主要是跟着 Redux 官方网站 中的示例继续探索 Redux C...

  • redux and react-redux

    感谢react小书作者,看了三遍,对redux有了点了解,写下随手笔记。 redux: 一、createStore...

  • GraphQL笔记一:简单串讲

    GraphQL笔记一:简单串讲 React 笔记一:简单串讲 Redux 笔记一:简单串讲 当然GraphQL和R...

  • 详解react、redux、react-redux之间的关系

    本文介绍了react、redux、react-redux之间的关系,分享给大家,也给自己留个笔记,具体如下: Re...

  • 详解react、redux、react-redux之间的关系

    本文介绍了react、redux、react-redux之间的关系,分享给大家,也给自己留个笔记,具体如下: Re...

网友评论

      本文标题:redux一些笔记

      本文链接:https://www.haomeiwen.com/subject/rgpvsctx.html