Redux Observable史诗中的动作没有被派遣

时间:2018-04-17 18:44:35

标签: react-native redux redux-observable

我无法使用此功能发送UPDATE_REGIONGET_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)
  })

我发送的唯一动作:

enter image description here

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_REGIONGET_CURRENT_POSITION_FULFILLED

1 个答案:

答案 0 :(得分:0)

您正在同时调度多个动作,因此 Observable.concat(Observable.of(),Observable.of())是这里的方法。没有concat,你没有正确返回ActionsObservable。

public static void Seed(AppDbContext context)