Code Monkey home page Code Monkey logo

react-cnode-two's Introduction

react版本的cnode应用(第二版)

这是第二个版本的react版本的cnode应用,相比较第一版来说,这一个版本的改动主要是:

  • 1、store结构上

目前的结构为:

1.png

  • 2、容器组件负责处理数据,展示组件负责渲染,逻辑变得更加清晰。

  • 3、增加测试代码

  • 4、编写中间件函数,用于处理异步action

export const asyncFetch = ({dispatch , getState}) => next => action => {
    let {
        types,
        shouldCallApi = () => true,
        callApi,
        payload = {}
    } = action;
    // 如果没有types,那么就跳过这个中间件
    if (!types) {
        return next(action);
    };
    if (!Array.isArray(types) || types.length !== 3 || !types.every(type => typeof type === 'string')) {
        throw new Error('Expected an array of three string types.');
    };
    if (typeof callApi !== 'function') {
        throw new Error('callApi must be function');
    };
    if (!shouldCallApi(getState())) {
        return;
    }
    let [startType , receiveType , failType] = types;
    dispatch(Object.assign({} , payload , {
        type : startType
    }));
    return callApi().then(res => {
        if (res.ok) {
            return res.json();
        } else {
            return Promise.reject({
                status : res.status,
                statusText : res.statusText
            });
        }
    }).then(json => {
        return dispatch(Object.assign({} , payload , {
            type : receiveType,
            data : json.data ? json.data : json
        }));
    }).catch(err => {
        return dispatch(Object.assign({} , payload , {
            type : failType,
            error : err
        }));
    });
};

用法

git clone https://github.com/andyChenAn/react-cnode-two.git
cd react-cnode-two
npm install
npm start

测试

npm test

项目展示

首页

2.png

页面加载中效果

3.png

详细页

4.png

登录页

5.png

代码测试(包括action,reducer,component)

6.png

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.