javascript - Callable signature not found in promise (Flow, React Native, JS) -
my app shows list of question displayed on first screen upon loading.
i'm trying implement listens appstate , upon becoming 'active' again, refresh list of questions again make sure list date.
i'm using mobx keep track of state.
everything appears working fine, flow generating following errors...
library type error: /private/tmp/flow/flowlib_1950abc4/core.js:666 666: onfulfill?: (value: r) => promise<u> | u, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function type. callable signature not found in 17: .then(this.refreshquestions()) // eslint-disable-line promise/prefer-await-to-then ^^^^^^^^^^^^^^^^^^^^^^^ promise. see: packages/mobile/src/questionlist/questionrepository.js:17 packages/mobile/src/questionlist/questionrepository.js:16 v---------------------------- 16: this.loadquestionsfromcache() 17: .then(this.refreshquestions()) // eslint-disable-line promise/prefer-await-to-then -----------------------------^ call of method `then` 666: onfulfill?: (value: r) => promise<u> | u, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function type. callable signature not found in. see lib: /private/tmp/flow/flowlib_1950abc4/core.js:666 17: .then(this.refreshquestions()) // eslint-disable-line promise/prefer-await-to-then ^^^^^^^^^^^^^^^^^^^^^^^ promise
this constructor , relevant methods being called...
constructor() { this.loadquestionsfromcache() .then(this.refreshquestions()) // eslint-disable-line promise/prefer-await-to-then .then(this.startlisteningforstatechanges()) // eslint-disable-line promise/prefer-await-to-then .catch(() => { alert.alert( 'ooops!', 'something went wrong when tried load everyones questions :( please try refreshing me', [{text: 'ok'}], {cancelable: false} ) }) } @action('list refreshing (true/false) updated') updateislistrefreshing(isrefreshing: boolean) { this.islistrefreshing = isrefreshing } @action('set question list') setquestions(questions: question) { this.questions = questions } handleappstatechange = (nextappstate: string) => { if (nextappstate === 'active') { this.refreshquestions() } } startlisteningforstatechanges() { appstate.addeventlistener('change', this.handleappstatechange) } // eslint-disable-next-line complexity, max-statements async refreshquestions() { if (this.islistrefreshing) { return } try { this.updateislistrefreshing(true) const response = await fetch(serverurl) if (response.status === 200) { const questionstext = await response.text() this.setquestions(json.parse(questionstext).map(question.of)) await asyncstorage.setitem('questions', questionstext) } this.updateislistrefreshing(false) } catch (error) { this.updateislistrefreshing(false) } } async loadquestionsfromcache() { const questionstext = await asyncstorage.getitem('questions') if (questionstext) { this.setquestions(json.parse(questionstext).map(question.of)) } }
constructor() { this.loadquestionsfromcache() .then(this.refreshquestions) // eslint-disable-line promise/prefer-await-to-then .then(this.startlisteningforstatechanges) // eslint-disable-line promise/prefer-await-to-then .catch(() => { alert.alert( 'ooops!', 'something went wrong when tried load everyones questions :( please try refreshing me', [{text: 'ok'}], {cancelable: false} ) }) } @action.bound updateislistrefreshing(isrefreshing: boolean) { this.islistrefreshing = isrefreshing } @action('set question list') setquestions(questions: question) { this.questions = questions } handleappstatechange = (nextappstate: string) => { if (nextappstate === 'active') { this.refreshquestions() } } @action.bound startlisteningforstatechanges() { appstate.addeventlistener('change', this.handleappstatechange) } @action.bound async refreshquestions() { if (this.islistrefreshing) { return } try { this.updateislistrefreshing(true) const response = await fetch(serverurl) if (response.status === 200) { const questionstext = await response.text() this.setquestions(json.parse(questionstext).map(question.of)) await asyncstorage.setitem('questions', questionstext) } this.updateislistrefreshing(false) } catch (error) { this.updateislistrefreshing(false) } }
Comments
Post a Comment