()=>async()=>{} 是什么意思?
What does ()=>async()=>{} mean?
我对 redux thunk 操作感到困惑:
import axios from 'axios';
export const GET_CHANNELS = 'GET_CHANNELS'
export const getChannels = () => async (dispatch, getState) => {
const res = await axios.get('https://v-forum-api.bahdcasts.com/api/channels')
dispatch({
type: GET_CHANNELS,
payload: res.data
})
}
下面的结构是什么意思?
const getChannels=()=>async()=>{}
能否提供有关该表达式的文章 link?
谢谢
它是 returns 另一个(异步)函数的函数。
忽略箭头函数和正则函数之间 this
的语义差异,使用正则函数编写相同内容的更清晰的方法可能是:
const getChannels = function () {
return async function (dispatch, getState) {
// ...
}
}
调用者会调用 getChannels()
并返回一个函数,然后也可以调用该函数。
const innerFunction = getChannels()
await innerFunction(dispatch, getState)
const getChannels = () => async() => {}
在某种程度上等于:
function getChannels() {
return async function() {
}
}
使用箭头函数(这改变了 this
的用法)& getChannels 是常量块级变量。
我对 redux thunk 操作感到困惑:
import axios from 'axios';
export const GET_CHANNELS = 'GET_CHANNELS'
export const getChannels = () => async (dispatch, getState) => {
const res = await axios.get('https://v-forum-api.bahdcasts.com/api/channels')
dispatch({
type: GET_CHANNELS,
payload: res.data
})
}
下面的结构是什么意思?
const getChannels=()=>async()=>{}
能否提供有关该表达式的文章 link? 谢谢
它是 returns 另一个(异步)函数的函数。
忽略箭头函数和正则函数之间 this
的语义差异,使用正则函数编写相同内容的更清晰的方法可能是:
const getChannels = function () {
return async function (dispatch, getState) {
// ...
}
}
调用者会调用 getChannels()
并返回一个函数,然后也可以调用该函数。
const innerFunction = getChannels()
await innerFunction(dispatch, getState)
const getChannels = () => async() => {}
在某种程度上等于:
function getChannels() {
return async function() {
}
}
使用箭头函数(这改变了 this
的用法)& getChannels 是常量块级变量。