console.logaction不显示在React Native中

问题描述

我有多个减速器,这个减速器在任何console.log()都不会出现,但是在default的情况下,它总是到达另一个xxx_fetch_success负载

这是我的 actions / index.js

export * from './ItemActions';

这是我的 actions / types.js

export const ITEM_UPDATE = 'item_update';
export const ITEM_CREATE = 'item_create';
export const ITEMS_FETCH_SUCCESS = 'items_fetch_success';

这是我的 actions / ItemActions.js

import firebase from 'firebase';
import { ITEM_UPDATE,ITEM_CREATE,ITEMS_FETCH_SUCCESS } from './types';

export const itemUpdate =  ({ prop,value }) => {
    return {
        type: ITEM_UPDATE,payload: { prop,value }
    };
};

export const itemsFetch = () => {
    return (dispatch) => {
        firebase.database().ref(`items/`)
            .on('value',snapshot => {
                dispatch({ type: ITEMS_FETCH_SUCCESS,payload: snapshot.val() });
            });
    };
};

这是我的 reducers / index.js

import { combineReducers } from 'redux';
import ItemFormReducer from './ItemFormReducer';
import ItemReducer from './ItemReducer';

export default combineReducers({
    itemForm: ItemFormReducer,items: ItemReducer,});

这是我的 reducers / ItemReducer.js

import { ITEMS_FETCH_SUCCESS } from '../actions/types';

const INITIAL_STATE = {}

export default (state = INITIAL_STATE,action) => {
    switch (action.type){
        case ITEMS_FETCH_SUCCESS:
            console.log("ITEM_FETCH_SUCCESS: ",action);
            return state;
        default:
            console.log("FROM DEFAULT: ",action);
            return state;
    }
};

这是我的 reducers / ItemFormReducer.js

import {
    ITEM_UPDATE,} from '../actions/types';

const INITIAL_STATE = {
    photo: '',item: '',category: '',price: '',description: '',};

export default (state = INITIAL_STATE,action) => {
    switch (action.type){
        case ITEM_UPDATE: 
            return { ...state,[ action.payload.prop ]: action.payload.value };
        case ITEM_CREATE:
            return INITIAL_STATE;
        default:
            return state;
    }
}

这是我的 screens / Menu.js

import _ from 'lodash';
import React,{ Component } from 'react';
import { Text,View,StyleSheet,TouchableOpacity } from 'react-native';
import { connect } from 'react-redux';
import { itemsFetch } from '../../actions';
class Menu extends Component {
    componentDidMount() {
        this.props.itemsFetch();
    }
    render() {
        return (
            <View>
                <Text>Menu</Text>
                <Text>Menu</Text>
                <Text>Menu</Text>
                <Text>Menu</Text>
                <Text>Menu</Text>
                <Text>Menu</Text>
            </View>
        );
    }
}

export default connect(null,{ itemsFetch })(Menu);

这是我的 Firebase规则:

{

  /* Visit https://firebase.google.com/docs/database/security to learn more about security rules. */

  "rules": {

     "items" : {

      "$itemId":{

        ".read": true,        ".write":"auth.uid === data.child('ownerId').val() || data.child('ownerId').val() === null"

      }

    },    "users":{

      "$uid":{

        ".read": true,        ".write":"$uid === auth.uid"

      }

    },  }

}

这是我的 Firebase实时数据库结构:

ProjectName

      - items

      - users

问题是 reducers / ItemReducer.js 中的console.log(action)从未出现,但是在console.log(action)情况下的default与另一个对象数据有效负载一起出现 您能帮我一下吗,谢谢。

解决方法

在Redux中,React Native或Action没问题。由于Firebase安全性的规定,我阻止了所有写入操作。