From f9d9bb72cb8c1982cbe3acecfff3389c1121aadf Mon Sep 17 00:00:00 2001
From: Dhivya Dandapani
Date: Fri, 3 Apr 2020 14:14:10 +0530
Subject: [PATCH 1/5] Handle async functions passed as source prop
---
src/components/Autocomplete.vue | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/src/components/Autocomplete.vue b/src/components/Autocomplete.vue
index f307552..2de9b31 100644
--- a/src/components/Autocomplete.vue
+++ b/src/components/Autocomplete.vue
@@ -241,6 +241,13 @@ export default {
}
return this.resourceSearch(this.source + this.display)
+ case this.source.constructor.name === 'AsyncFunction':
+ // No resource search with no input
+ if (!this.display || this.display.length < 1) {
+ return
+ }
+ // When the function is async and returns a promise
+ return this.handlePromise(this.source(this.display));
case typeof this.source === 'function':
// No resource search with no input
if (!this.display || this.display.length < 1) {
@@ -279,6 +286,10 @@ export default {
headers: this.getHeaders()
})
+ return this.handlePromise(promise)
+ },
+
+ handlePromise: function (promise) {
return promise
.then(response => {
if (response.ok) {
@@ -297,7 +308,6 @@ export default {
this.loading = false
})
},
-
/**
* Set some default headers and apply user supplied headers
*/
From 8c947dd3a66fe6f6e3e9ee35160fddefc99685c4 Mon Sep 17 00:00:00 2001
From: Dhivya Dandapani
Date: Fri, 3 Apr 2020 14:18:45 +0530
Subject: [PATCH 2/5] Fix eslint semicolon error
---
src/components/Autocomplete.vue | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/components/Autocomplete.vue b/src/components/Autocomplete.vue
index 2de9b31..1396398 100644
--- a/src/components/Autocomplete.vue
+++ b/src/components/Autocomplete.vue
@@ -247,7 +247,7 @@ export default {
return
}
// When the function is async and returns a promise
- return this.handlePromise(this.source(this.display));
+ return this.handlePromise(this.source(this.display))
case typeof this.source === 'function':
// No resource search with no input
if (!this.display || this.display.length < 1) {
From c2db1318a5341bf06b22adfe7f79cbc3d2e410ad Mon Sep 17 00:00:00 2001
From: Dhivya Dandapani
Date: Sat, 4 Apr 2020 12:49:39 +0530
Subject: [PATCH 3/5] Handle fetch response differntly from promise response
---
src/components/Autocomplete.vue | 37 ++++++++++++++++++++++++++-------
1 file changed, 29 insertions(+), 8 deletions(-)
diff --git a/src/components/Autocomplete.vue b/src/components/Autocomplete.vue
index 1396398..72627b6 100644
--- a/src/components/Autocomplete.vue
+++ b/src/components/Autocomplete.vue
@@ -63,6 +63,7 @@