Skip to content

Commit

Permalink
Make fp tools faster by pulling directly from state
Browse files Browse the repository at this point in the history
  • Loading branch information
goatslacker committed Jul 24, 2015
1 parent 5f50840 commit 2b5adb3
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/utils/fp.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@ const { push } = Array.prototype
/*eslint-disable no-shadow*/
export function map(fn, stores) {
return stores
? stores.map(store => fn(store.getState()))
? stores.map(store => fn(store.state))
: stores => map(fn, stores)
}

export function filter(fn, stores) {
return stores
? stores.filter(store => fn(store.getState()))
? stores.filter(store => fn(store.state))
: stores => filter(fn, stores)
}

export function reduce(fn, stores, acc = {}) {
return stores
? stores.reduce((acc, store) => fn(acc, store.getState()), acc)
? stores.reduce((acc, store) => fn(acc, store.state), acc)
: stores => reduce(fn, stores)
}

export function flatMap(fn, stores) {
if (!stores) return (stores) => flatMap(fn, stores)

return stores.reduce((result, store) => {
let value = fn(store.getState())
let value = fn(store.state)
if (Array.isArray(value)) {
push.apply(result, value)
} else {
Expand All @@ -42,7 +42,7 @@ export function zipWith(fn, a, b) {
const length = Math.min(a.length, b.length)
const result = Array(length)
for (let i = 0; i < length; i += 1) {
result[i] = fn(a[i].getState(), b[i].getState())
result[i] = fn(a[i].state, b[i].state)
}
return result
}

0 comments on commit 2b5adb3

Please sign in to comment.