feat(asyncComponent): add onError option for defineAsyncComponent

BREAKING CHANGE: `retryWhen` and `maxRetries` options for
`defineAsyncComponent` has been replaced by the more flexible `onError`
option, per https://github.com/vuejs/rfcs/pull/148
This commit is contained in:
Evan You
2020-04-07 14:34:42 -04:00
parent f87d6b501e
commit e804463492
2 changed files with 38 additions and 14 deletions

View File

@@ -488,7 +488,13 @@ describe('api: defineAsyncComponent', () => {
reject = _reject
})
},
retryWhen: error => error.message.match(/foo/)
onError(error, retry, fail) {
if (error.message.match(/foo/)) {
retry()
} else {
fail()
}
}
})
const root = nodeOps.createElement('div')
@@ -526,7 +532,13 @@ describe('api: defineAsyncComponent', () => {
reject = _reject
})
},
retryWhen: error => error.message.match(/bar/)
onError(error, retry, fail) {
if (error.message.match(/bar/)) {
retry()
} else {
fail()
}
}
})
const root = nodeOps.createElement('div')
@@ -549,7 +561,7 @@ describe('api: defineAsyncComponent', () => {
expect(serializeInner(root)).toBe('<!---->')
})
test('retry (fail w/ maxRetries)', async () => {
test('retry (fail w/ max retry attempts)', async () => {
let loaderCallCount = 0
let reject: (e: Error) => void
@@ -560,8 +572,13 @@ describe('api: defineAsyncComponent', () => {
reject = _reject
})
},
retryWhen: error => error.message.match(/foo/),
maxRetries: 1
onError(error, retry, fail, attempts) {
if (error.message.match(/foo/) && attempts <= 1) {
retry()
} else {
fail()
}
}
})
const root = nodeOps.createElement('div')