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

  • 相关阅读:
    验证码缓存问题完美解决方案
    最近项目是跟框架有关的两个问题
    未与信任 SQL Server 连接相关联
    Get请求
    Post请求
    jQuery操作元素
    Dom对象和jQuery包装集
    XMLHttpRequest对象
    jQuery事件与事件对象
    处理数据集
  • 原文地址:https://www.cnblogs.com/caimengting/p/15252957.html
Copyright © 2011-2022 走看看