1.0.5 • Published 5 years ago

purechain v1.0.5

Weekly downloads
-
License
ISC
Repository
-
Last release
5 years ago

PureChain

Usage

const chain = require('PureChain');

// new Chain(.....) 和 Chain(...) 是等效的

let c1 = Chain(function (next) {
	console.log(this.name)
	next({context: 123})
}, {name: 123})

c1
	.next(Chain(function (next) {
		setTimeout(() => {
			console.log('this is second Chain')
			console.log(this.context)
			next()
		}, 1200)
	}, {context: window}))
	.next(Chain(function () {
		setTimeout(() => {
			console.log('the third Chain')
		}, 90)
	}, {Chain: 'third'}))

c1.start()

拆解

let c1 = new Chain(function (next) {
	console.log(this.name)
	next()
}, {name: 123})
let c2 = new Chain(function (next) {
	setTimeout(() => {
		next()
		console.log(this)
	}, 1200)
}, {current: 'admin'})
let c3 = Chain(function () {
	setTimeout(() => {
		console.log('c3')
	}, 90)
}, {admin: '123'})
c1.next(c2).next(c3)
c1.start()

next 里的参数是用来修改下一个Chain里的上下文

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago