我有一個〜5000個元素的列表,我想通過用戶給出的searchPhrase
進行過濾。 通常用戶鍵入過濾短語的第一個字母,然後是第二個,然後是第三個。 例如,用戶類型'a'
,然後'ab'
,然後'abc'
。使用大型列表過濾性能
我正在嘗試使用reactjs/reselect庫來提高過濾性能。 我已經使用這個LIB如實施例上自述: Example 我已經改變這個方法:
export const getVisibleTodos = createSelector(
[ getVisibilityFilter, getTodos ],
(visibilityFilter, todos) => {
switch (visibilityFilter) {
case 'SHOW_ALL':
return todos
case 'SHOW_COMPLETED':
return todos.filter(t => t.completed)
case 'SHOW_ACTIVE':
return todos.filter(t => !t.completed)
}
}
)
該實現:
export const getVisibleTodos = createSelector(
[getSearchPhrase, getTodos],
(searchPhrase, todos) => {
return todos.filter((x) => {
return x.firstName.indexOf(searchPhrase) >= 0;
});
}
)
我,每次注意到當用戶鍵入下字母todos.length
屬性是一樣的。 searchPhrase
更長時,不應該todos.length
更短嗎? 我認爲沒有reactjs/reselect的性能是相同的。
是否有可能過濾較短的todos
列表當前searchPhrase
是實際的子串searchPhrase
?
感謝您的解釋。所以我誤解了這個庫的功能。你有沒有遇到過類似的情況下可以幫助你的圖書館? – Andrzej