我无法使用此功能发送UPDATE_REGION
或GET_CURRENT_POSITION_FULFILLED
...import { Observable } from 'rxjs'
import 'redux-observable'
import { ajax } from 'rxjs/observable/dom/ajax'
import {...
GET_CURRENT_POSITION,..
} from './action'
import {
getCurrentPositionFulfilled,
getCurrentLocationRejected
} from './action'
import type { LocationAction } from './action'
import 'rxjs/add/operator/catch'
import { getCurrentPositionObservable } from '../../../../../callbackToObservable'
...
export const getCurrentPositionEpic: Epic<*, *, *> = (
action$: ActionsObservable<*>
): Observable<LocationAction> =>
action$.ofType(GET_CURRENT_POSITION).mergeMap(() =>
getCurrentPosition$
.mergeMap((position: Position): ActionsObservable<*> => {
return Observable.of(
updateRegion({
region: {
latitude: position.coords.latitude,
longitude: position.coords.longitude,
latitudeDelta: 0,
longitudeDelta: 0
}
}),
getCurrentPositionFulfilled(position)
)
})
.catch(error => Observable.of(getCurrentLocationRejected(error)))
)
export const UPDATE_REGION: 'UPDATE_REGION' = 'UPDATE_REGION'
const getCurrentPosition$ = getCurrentPositionObservable()
type UpdateRegionAction = {
type: typeof UPDATE_REGION,
payload: RegionPayload
}
export type MapAction = UpdateRegionAction
export const updateRegion: ActionCreator = (
payload: RegionPayload
): UpdateRegionAction => ({
type: UPDATE_REGION,
payload
})
callbackToObservable.js
import { Observable } from 'rxjs'
export const getCurrentPositionObservable = Observable.bindCallback(
(options: any, cb?: any) => {
if (typeof options === 'function') {
cb = options
options = null
}
navigator.geolocation.watchPosition(cb, null)
})
我发送的唯一动作:
index.js
const rootReducer = combineReducers({
product: product
})
export const rootEpic = combineEpics(
fetchCategoriesEpic,
getAddPageLocationAutocompleteResultsEpic,
getAddPageLocationPlaceDetailsEpic,
getCurrentPositionEpic,
getCurrentLocationEpic,
getCurrentLocationFulfilledEpic
)
export const store = createStore(
rootReducer,
vepo,
composeWithDevTools(applyMiddleware(createEpicMiddleware(rootEpic)))
)
callbackToObservable.js
import { Observable } from 'rxjs'
export const getCurrentPositionObservable = Observable.bindCallback(
(options: any, cb?: any) => {
if (typeof options === 'function') {
cb = options
options = null
}
navigator.geolocation.watchPosition(cb, null)
})
为什么不发送UPDATE_REGION
或GET_CURRENT_POSITION_FULFILLED
?
答案 0 :(得分:0)
您正在同时调度多个动作,因此 Observable.concat(Observable.of(),Observable.of())是这里的方法。没有concat,你没有正确返回ActionsObservable。
public static void Seed(AppDbContext context)