Ich benutze react-observable, um eine reaktionsnative Anwendung zu entwickeln.Verwenden Sie eine Ausgabe von Epic als eine andere Eingabe von Epic in reagieren beobachtbar
Ich habe zwei Epen, eine wird verwendet, um die Breite und Länge zu holen, und eine andere wird verwendet, um die Adresse durch die Breite und Länge zu bekommen.
Meine Frage ist, wie ich eine Sache in einem Epos machen möchte, wie könnte ich die Ausgabe des ersten Epos als die Eingabe des zweiten Epos verwenden?
const getLocationEpic = action$ =>
action$.ofType('GET_LOCATION')
.mergeMap(() =>
currentPosition$()
.map(data => ({
type: 'GET_LOCATION_SUCCESS',
data: {"latitude": data.coords.latitude, "longitude": data.coords.longitude}
}))
.catch(error => {
console.log("GET POSITION ERR", error);
return Observable.of({type: 'GET_POSITION_ERROR', error: error});
})
);
const getAddressEpic = action$ =>
action$.ofType('GET_ADDRESS')
.switchMap(action =>
ajax(`https://maps.googleapis.com/maps/api/geocode/json?latlng=${latitude},${longitude}`)
.map(data => (data))
.do({
next: data => {
console.log("address data");
console.log(data);
}
})
.map(data => ({
type: 'GET_POSITION_SUCCESS', data: data.response.results[0].formatted_address
}))
.mergeMap(() =>
currentPosition$()
.map(data => ({
type: 'GET_ADDRESS_SUCCESS',
data: {"latitude": data.coords.latitude, "longitude": data.coords.longitude}
}))
.catch(error => {
console.log("GET_ADDRESS_ERROR", error);
return Observable.of({type: 'GET_ADDRESS_ERROR', error: error});
})
));
Hey dort. Hat das deine Frage beantwortet? – jayphelps