谁能告诉我我无法获得此代码?

时间:2018-12-28 06:11:59

标签: reactjs redux

    const getVisibleExpenses = (expenses, { text, sortBy, startDate, endDate }) => {
    return expenses.filter((expense) => {
        const startDateMatch = typeof startDate !== "number" || expense.createAt >= startDate;
        const endDateMatch = typeof endDate !== "number" || expense.createAt <= endDate;
        const textMatch = expense.desciption.toLowerCase().includes(text.toLowerCase())
        return startDateMatch && endDateMatch && textMatch;
    });

}
const store = createStore(combineReducers({
    expenses: expensesReducer,
    filters: filterReducer
}))

store.subscribe(() => {
    const state = store.getState();
    const visibleExpense = getVisibleExpenses(state.expenses, state.filters);
    console.log(visibleExpense);
})

谁能帮助我描述这段代码 特别是在本节中,我从redux商店获得了费用和对象,它们都是化简器,但我无法理解以下代码的逻辑

const startDateMatch = typeof startDate !== "number" || expense.createAt >= startDate;

1 个答案:

答案 0 :(得分:0)

const startDateMatch = typeof startDate !== "number" || expense.createAt >= startDate;

这意味着,如果startDate的类型不是数字,或者大于或等于Expense.createAt日期,则返回一个布尔值true。

如果其中一个为假,则startDateMatch为假。两者都必须为true才能返回true。

将其与其他2个条件结合起来,如果所有条件都为true(它们匹配),则返回true,否则,如果其中任何一个为false,则返回false。