Giter Club home page Giter Club logo

flow-step's Introduction

flow-step介绍

为了让业务逻辑写起来更加简洁清晰,所以设计了这个轻量的框架,它只是提供一个最基本的约束,让大家都可以去遵守它,从而形成套相对美观的代码结构。

简单运用

const flow-step = require('flow-step')

flow-step({
    //设定流程执行步骤
    init: function() {
        this.next('getUserInfo', {name: 'cat'}).then() //获取用户信息(异步)
            .next('updateUserInfo').then() //更新用户信息(异步)
            .next('sendSMS') //发送短信消息(同步)
            .end((err, data) => {
                //todo
            })
    },
    getUserInfo: function(needles, callback) {
        //needles is => {name: 'cat'}
        setTimeout(() => {
            callback && callback(null, null, {name: 'tom'})
        }, 1000)
    },
    updateUserInfo: function(callback) {
        setTimeout(() => {
            //可获取前面所有步骤的指定执行结果
            let name = this.get('getUserInfo').name

            //callback error的时候,当前流程将立即结束
            //callback({msg:'执行异常'})
            callback && callback()
        }, 1000)
    },
    sendSMS: function() {
        console.log('send')
    }
})

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.