【发布时间】:2018-02-06 02:18:24
【问题描述】:
我正在尝试在状态更新之前在我的操作创建器中解决此异步调用。我试图实现 redux thunk,但我对它和 angular4+ 整体来说还很陌生。
这是我的动作创建者的样子:
@Injectable()
export class IndexActions {
constructor(
private _cloudReadService: CloudReadService
) {}
static UPDATE_INDEX = 'UPDATE_INDEX';
updateIndex(): ActionWithPayload {
return {
type: IndexActions.UPDATE_INDEX,
payload: this._cloudReadService.getRecordsByOwner()
.then(response => {return response})
.catch(err => console.log)
}
}
}
thunk 的主要问题是我的服务方法没有在实际的 thunk 中定义。
这是服务的基本外观:
@Injectable()
export class CloudReadService {
constructor() {
}
getRecordsByOwner(): any {
return firebase.database()
.ref('lists/records/owners')
.orderByChild('ownerName')
.once('value')
.then(snapshot => {
/* process response */
return processedResponse;
}
})
}
}
我想我的问题真的是如何在 redux 中间件中使用服务方法,或者有其他方法吗?
非常感谢任何帮助。
【问题讨论】:
标签: angular asynchronous redux thunk