我的应用会显示加载后第一个屏幕上显示的问题列表。
我目前正在尝试实施它,以便它可以监听AppState并使其变为“活跃”状态。再次,它将再次刷新问题列表,以确保列表是最新的。
我目前正在使用MobX来跟踪我的状态。
一切似乎都运行良好,但流程产生以下错误......
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
这是我的构造函数和被调用的相关方法......
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 I tried to load everyones questions :( please try refreshing me',
[{text: 'OK'}],
{cancelable: false}
)
})
}
@action('List is 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))
}
}
答案 0 :(得分:0)
@IBAction func filter1(_ sender: Any) {
myImage.image = simpleBlurFilterExample(myImage: myImage.image)
}
func simpleBlurFilterExample(myImage: UIImage) -> UIImage {
// convert UIImage to CIImage
let inputCIImage = CIImage(image: myImage)!
// Create Blur CIFilter, and set the input image
let blurFilter = CIFilter(name: "CIGaussianBlur")!
blurFilter.setValue(inputCIImage, forKey: kCIInputImageKey)
blurFilter.setValue(8, forKey: kCIInputRadiusKey)
// Get the filtered output image and return it
let myImage = blurFilter.outputImage!
return UIImage(ciImage: myImage)
}