错误:从Firestore集合中删除项目后添加了冗余字段

时间:2019-08-12 19:27:35

标签: javascript reactjs firebase redux google-cloud-firestore

您要请求功能还是报告 bug
错误

当前行为是什么? 加载页面后,我得到的保护数据如下所示:

Screenshot (43)_LI

但是,删除项目后,将嵌入冗余todayFeed。对于每个删除的项目,将再次添加todayFeed字段(此字段不是在Firestore中创建的,仅在刷新页面之前存在于redux存储中)。商店更新后,实际商品数组的长度是相同的,并且看起来好像商品没有被删除(即使商品已从firestore集合中删除,并且刷新后的页面数据也类似于第一个屏幕截图)但与预期相比,数组中的项减少了一个)

Screenshot (44)_LI

用户调度操作(redux)以删除Firestore集合中的项目

this.props.deleteItem(item);

在那之后,我在中间件中使用redux-thunk并使用额外的参数(getFirebasegetFirestore)来访问动作创建者中的firebase和firestore。

let store = createStore(reducer,
  compose(
    applyMiddleware(thunk.withExtraArgument({ getFirebase, getFirestore })),
    reduxFirestore(firebaseConfig),
    reactReduxFirebase(firebaseConfig, { useFirestoreForProfile: true, userProfile: 'users', attachAuthIsReady: true })
  )
);

动作创作者:

import { getFirestore } from "redux-firestore";

export const deleteItem = itemToDelete => {
  return (dispatch, getState, { getFirebase, getFirestore }) => {
    const firestore = getFirestore();
    const authorId = getState().firebase.auth.uid;
    const userRef = firestore.collection("users").doc(authorId);

    userRef
      .collection("todayFeed")
      .doc(itemToDelete.uid)
      .delete()
      .then(res => {
        dispatch({ type: "CHANGE_ITEM_STATE_SUCCESS", res });
      })
      .catch(err => {
        dispatch({ type: "CHANGE_ITEM_STATE_ERROR", err });
      });
  };
};

我使用react-redux-firebase来获取视图文件中的数据。

let mapStateToProps = state => {  
  return {
    auth: state.firebase.auth,
    items:
      state.firestore.ordered.users &&
      state.firestore.ordered.users.length &&
      state.firestore.ordered.users[0].todayFeed
  };
};

export default compose(
  connect(mapStateToProps),
  firestoreConnect(props => {
    return [
      {
        collection: "users",
        doc: props.auth.uid,
        subcollections: [
          { collection: "todayFeed", orderBy: ["pubDate", "desc"] }
        ]
      }
    ];
  })
)(Dashboard);

预期的行为是什么? 删除项目后,以预期的格式(不嵌入多余的todayFeed字段)获取数据。

哪个版本的依赖项以及哪个浏览器和操作系统受此问题影响?这在以前的版本或设置中有效吗?

操作系统:Windows 10

依赖项:

"dependencies": {
    "cors": "^2.8.5",
    "firebase": "^5.5.5",
    "googleapis": "^42.0.0",
    "moment": "^2.24.0",
    "react": "^16.9.0",
    "react-dom": "^16.9.0",
    "react-firebaseui": "^3.1.2",
    "react-redux": "^5.0.7",
    "react-redux-firebase": "^2.3.0",
    "react-router-dom": "^4.3.1",
    "react-scripts": "2.0.5",
    "react-spring": "^5.1.3",
    "react-with-gesture": "^1.0.10",
    "redux": "^4.0.1",
    "redux-firestore": "^0.5.8",
    "redux-thunk": "^2.3.0",
    "scriptjs": "^2.5.9",
    "styled-components": "^3.2.6"
  },

0 个答案:

没有答案