Permalink
Browse files

Memoized Selectors: filtert, aber Liste wird nicht neu gerendert

  • Loading branch information...
ronnyhartenstein committed Sep 26, 2016
1 parent 639a36c commit e27025297d2cb02f37da74e57df85c5d0f8336f9
Showing with 19 additions and 12 deletions.
  1. +2 −1 package.json
  2. +17 −11 src/components/ReduxListe.js
View
@@ -13,6 +13,7 @@
"react-native-vector-icons": "^2.1.0",
"react-redux": "^4.4.5",
"redux": "^3.6.0",
"redux-logger": "^2.6.1"
"redux-logger": "^2.6.1",
"reselect": "^2.5.4"
}
}
@@ -1,25 +1,31 @@
import React, { Component } from 'react'
import Liste from './Liste'
import { connect } from 'react-redux'
// import FuzzySearch from 'fuzzy-search'
import { createSelector } from 'reselect'
import _ from 'lodash'
// Memoized Selectors -> http://redux.js.org/docs/recipes/ComputingDerivedData.html
const getVisibleItems = (items, search) => {
if (_.isEmpty(search) || search.length < 3) {
return { filteredItems: items }
} else {
const r = new RegExp(search, 'i')
const filtered = _.filter(items, itm => ( r.test(itm.name) || r.test(itm.lat) ))
console.log("Filtered: ", filtered)
return filtered
const getSearch = (state) => state.search
const getItems = (state) => state.items
const getVisibleItems = createSelector(
[ getSearch, getItems ],
(search, items) => {
// if (_.isEmpty(search) || search.length < 3) {
// return items
// } else {
const r = new RegExp(search, 'i')
const filtered = _.filter(items, itm => ( r.test(itm.name) || r.test(itm.lat) ))
console.log("Filtered: ", filtered)
return filtered
// }
}
}
)
const mapStateToProps = (state) => {
return {
filteredItems: getVisibleItems(state.items, state.search)
filteredItems: getVisibleItems(state)
}
}

0 comments on commit e270252

Please sign in to comment.