zoukankan      html  css  js  c++  java
  • React-Redux

    1,store

    保存数据的地方,管理全局的状态

    import { createStore } from 'redux';
    const store = createStore(reducter);
    store.getState();
    store.dispatch(action);
    store.subscribe(liatener);

    2,state

    const state = store.getState();

    一个state对应一个view

    所有的state都以一个对象树的形式存在一个单一的store中

    3,action

    唯一改变state的方法就是dispatch一个action

    state + action = new state(可预测性)

    const action = {
      type: 'ADD_TODO',
      payload: 'Learn Redux'
    };

    action本质上是一个JavaScript对象,包含一个type字段

    4,action creator

    定义一个函数生成action

    const ADD_TODO = '添加 TODO';
    
    function addTodo(text) {
      return {
        type: ADD_TODO,
        text
      }
    }
    
    const action = addTodo('Learn Redux');

    5,store.dispatch

    view发出action的唯一方法

    store.dispatch(addTodo('Learn Redux'));

    6,reducter

    store收到action之后,必须给出新的state,这样view才能发生变化,这种state的计算过程就叫做reducter

    reducter是一个函数,接收action和当前state作为参数,返回新的state

    combineReducers

    bindActionCreators

  • 相关阅读:
    常用注解
    代码自动生成插件:
    jsoup爬虫技术+druid连接池

    图书管理系统-项目介绍
    shiro
    (C#) What is the difference between "const" and "static readonly" ?
    What is a Windows USB device path and how is it formatted?
    (C/C++ interview) Static 详解
    Cpk
  • 原文地址:https://www.cnblogs.com/caimengting/p/15252957.html
Copyright © 2011-2022 走看看