Coder Social home page Coder Social logo

redux-by-hand's Introduction

Redux-By-Hand

文件结构说明

  • sampleMiddlewares(文件夹):用于测试而写的参考中间件

  • sampleReducers(文件夹):用于测试而写的参考reducer

  • src(文件夹):实现redux的源文件

  • test.js(文件):包含多reducer(拆分state)多中间件的测试文件

  • test2.js(文件):简易测试,使用单独reducer,单独state,无中间件


实现功能

  1. createStore()

    • 参数: reducer,初始state,createStore增强器

    • 返回3个函数

      • subscribe():添加订阅

      • changeState():从外部发送action,在store内部对state进行修改

      • getState():从外部获取state(不可以在外部对state直接进行修改)

  2. combineReducers()

    • 用途:拆分出多个reducer和state

    • 参数:通过key+value对应不同reducer函数

    • 返回一个新的reducer函数

      • 接收action时,会循环key对应的函数,并更新state中key对应的数值
  3. applyMiddleware()

    • 用途:对store中的changeState功能进行增强和修改

    • 参数:多个middleware函数(有格式要求)

    • 返回一个之前提到的createStore增强器

      • 增强器:会返回一个增强的createStore函数

        • 增强的createStore函数:会返回一个增强的store,其中changeState函数会通过所有的middleware进行改写

redux-by-hand's People

Contributors

mary-biu-biu-biu avatar rmit-s3714621-yunying-ma avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.