Skip to content
This repository has been archived by the owner on Dec 25, 2017. It is now read-only.

Commit

Permalink
⚡ improvement(async): update async validator for function I/F
Browse files Browse the repository at this point in the history
  • Loading branch information
kazupon committed May 11, 2016
1 parent 87b5b42 commit 974cf61
Showing 1 changed file with 5 additions and 18 deletions.
23 changes: 5 additions & 18 deletions src/validations/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,24 +421,11 @@ export default class BaseValidation {
_invokeValidator (vm, validator, val, arg, cb) {
let future = validator.call(this, val, arg)
if (typeof future === 'function') { // function
if (future.resolved) {
// cached
cb(future.resolved)
} else if (future.requested) {
// pool callbacks
future.pendingCallbacks.push(cb)
} else {
future.requested = true
let cbs = future.pendingCallbacks = [cb]
future(() => { // resolve
future.resolved = true
for (let i = 0, l = cbs.length; i < l; i++) {
cbs[i](true)
}
}, (msg) => { // reject
cb(false, msg)
})
}
future(() => { // resolve
cb(true)
}, (msg) => { // reject
cb(false, msg)
})
} else if (isPromise(future)) { // promise
future.then(() => { // resolve
cb(true)
Expand Down

0 comments on commit 974cf61

Please sign in to comment.