简而言之,尝试将一个非常大的数组块分成10块,等待5秒,然后发出下一个10块。
这是我目前拥有的
Rx.Observable
.from(hugeArray)
.bufferCount(10)
.delay(5000) //want to wait 5 secs
.flatMap(e => e) // this needs to go after to flatten the array, buffer spits out arrays of entries
.flatMap( (data, index) => Rx.Observable.create(observer => {
// going to render stuff here
observer.onNext(data)
observer.onCompleted();
}))
.subscribe(val => console.log('Buffered Values:', val));
只是尝试在5秒内完成10个块,只能做一个初始延迟,然后它会发出其余的。
答案 0 :(得分:5)
您的链条只是立即发出一切,然后安排每个块从同一时间开始等待5秒,以便在同一时刻所有块的延迟过去。
解决方案可以是使用逐个订阅每个Observable的 import {RECEIVE_BABY} from '../constants'
import axios from 'axios'
export const receiveBaby = (baby,weight,height,sleep,diaper,feeding) =>({
type: RECEIVE_BABY,
baby: baby,
weight: weight,
feeding: feeding,
height: height,
sleep: sleep,
diapers: diaper
})
export const getBabyById = babyId => {
console.log("GET BABY BY ID")
return dispatch => {
Promise
.all([
axios.get(`/api/baby/${babyId}`),
axios.get(`/api/baby/${babyId}/weight`),
axios.get(`/api/baby/${babyId}/height`),
axios.get(`/api/baby/${babyId}/sleep`),
axios.get(`/api/baby/${babyId}/diaper`),
axios.get(`/api/baby/${babyId}/feed`)
])
.then(results => results.map(r => r.data))
.then(results => {
console.log("THIS IS RESULTS in Action assadkjasdfkjl;", results)
dispatch(receiveBaby(...results));
})
.catch(function(err){
console.log(err)
})
};
};
。
concatMap()