Skip to content

Commit

Permalink
buid v0.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
switer committed Dec 2, 2014
1 parent 8f611a8 commit c37fc09
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 22 deletions.
47 changes: 36 additions & 11 deletions dist/chain.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,28 +102,37 @@ function pushNode( /*handler1, handler2, ..., handlerN*/ ) {
return node
}

function noop () {}
function setAlltoNoop (obj, methods) {
utils.each(methods, function (method) {
obj[method] = noop
})
}

utils.merge(Chain.prototype, {
/**
* Define a chain node
**/
then: function() {
if (this._destroy) return
pushNode.apply(this, arguments)
return this
},
some: function() {
if (this._destroy) return
var node = pushNode.apply(this, arguments)
if (node.items.length) node.type = 'some'
return this
},
/**
* @RuntimeMethod can be call in runtime
* @RuntimeMethod only be called in runtime
* Check current node states and execulate nextNode
**/
next: function() {
if (this._end || this._destroy) return
var that = this
var args = utils.slice(arguments)
var node
if (this._end) return

if (this.__id) {
node = this._nodes.get(this.__id)
Expand Down Expand Up @@ -160,18 +169,29 @@ utils.merge(Chain.prototype, {
utils.merge(chainDummy, that)
chainDummy.__id = node.id
chainDummy.__index = index
chainDummy.__callee = item
chainDummy.__arguments = xArgs
chainDummy.__proto__ = that.__proto__

xArgs.unshift(chainDummy)
item.apply(that._context, xArgs)
})
return this
},

/**
* @RuntimeMethod can be call in runtime
* comment
* @RuntimeMethod only be called in runtime
* Run current step once again
**/
retry: function () {
if (this._end || this._destroy) return
this.__callee.apply(this._context, this.__arguments)
},
/**
* @RuntimeMethod only be called in runtime
**/
wait: function(time) {
if (this._destroy) return
var that = this
var args = utils.slice(arguments)
args.shift()
Expand All @@ -180,11 +200,11 @@ utils.merge(Chain.prototype, {
}, time)
},
/**
* @RuntimeMethod can be call in runtime
*
* Save/Update/Get data in current chain instance
* @RuntimeMethod only be called in runtime
* Save, Update, Get data in current chain instance
*/
data: function(key, data) {
if (this._destroy) return
// set data
if (key && data) {
this._data[key] = data
Expand All @@ -196,32 +216,37 @@ utils.merge(Chain.prototype, {
else return util.merge({}, this._data)
},
start: function() {
if (this._end) return
if (this._end || this._destroy) return

this._running = true
this.next()
this.next.apply(this, arguments)
return this
},
end: function() {
if (this._end) return
if (this._end || this._destroy) return
this._end = true
utils.batch(this._context, this._finals, this)
utils.batch.apply(utils, [this._context, this._finals, this].concat(utils.slice(arguments)) )
return this
},
final: function (handler) {
if (this._destroy) return
this._finals.push(handler)
return this
},
/**
* @RuntimeMethod can be call in runtime
**/
destroy: function() {
this._destroy = true
this._context = null
this._data = null
this._nodes = null
this._finals = null
setAlltoNoop(this, ['then', 'some', 'next', 'wait', 'data', 'start', 'end', 'final', 'destroy'])
return this
},
context: function(ctx) {
if (this._destroy) return
this._context = ctx
return this
}
Expand Down
47 changes: 36 additions & 11 deletions dist/chain.cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,28 +102,37 @@ function pushNode( /*handler1, handler2, ..., handlerN*/ ) {
return node
}

function noop () {}
function setAlltoNoop (obj, methods) {
utils.each(methods, function (method) {
obj[method] = noop
})
}

utils.merge(Chain.prototype, {
/**
* Define a chain node
**/
then: function() {
if (this._destroy) return
pushNode.apply(this, arguments)
return this
},
some: function() {
if (this._destroy) return
var node = pushNode.apply(this, arguments)
if (node.items.length) node.type = 'some'
return this
},
/**
* @RuntimeMethod can be call in runtime
* @RuntimeMethod only be called in runtime
* Check current node states and execulate nextNode
**/
next: function() {
if (this._end || this._destroy) return
var that = this
var args = utils.slice(arguments)
var node
if (this._end) return

if (this.__id) {
node = this._nodes.get(this.__id)
Expand Down Expand Up @@ -160,18 +169,29 @@ utils.merge(Chain.prototype, {
utils.merge(chainDummy, that)
chainDummy.__id = node.id
chainDummy.__index = index
chainDummy.__callee = item
chainDummy.__arguments = xArgs
chainDummy.__proto__ = that.__proto__

xArgs.unshift(chainDummy)
item.apply(that._context, xArgs)
})
return this
},

/**
* @RuntimeMethod can be call in runtime
* comment
* @RuntimeMethod only be called in runtime
* Run current step once again
**/
retry: function () {
if (this._end || this._destroy) return
this.__callee.apply(this._context, this.__arguments)
},
/**
* @RuntimeMethod only be called in runtime
**/
wait: function(time) {
if (this._destroy) return
var that = this
var args = utils.slice(arguments)
args.shift()
Expand All @@ -180,11 +200,11 @@ utils.merge(Chain.prototype, {
}, time)
},
/**
* @RuntimeMethod can be call in runtime
*
* Save/Update/Get data in current chain instance
* @RuntimeMethod only be called in runtime
* Save, Update, Get data in current chain instance
*/
data: function(key, data) {
if (this._destroy) return
// set data
if (key && data) {
this._data[key] = data
Expand All @@ -196,32 +216,37 @@ utils.merge(Chain.prototype, {
else return util.merge({}, this._data)
},
start: function() {
if (this._end) return
if (this._end || this._destroy) return

this._running = true
this.next()
this.next.apply(this, arguments)
return this
},
end: function() {
if (this._end) return
if (this._end || this._destroy) return
this._end = true
utils.batch(this._context, this._finals, this)
utils.batch.apply(utils, [this._context, this._finals, this].concat(utils.slice(arguments)) )
return this
},
final: function (handler) {
if (this._destroy) return
this._finals.push(handler)
return this
},
/**
* @RuntimeMethod can be call in runtime
**/
destroy: function() {
this._destroy = true
this._context = null
this._data = null
this._nodes = null
this._finals = null
setAlltoNoop(this, ['then', 'some', 'next', 'wait', 'data', 'start', 'end', 'final', 'destroy'])
return this
},
context: function(ctx) {
if (this._destroy) return
this._context = ctx
return this
}
Expand Down

0 comments on commit c37fc09

Please sign in to comment.