Skip to content

Commit

Permalink
Simplify composer
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeCortopassi committed Dec 10, 2016
1 parent 7677804 commit 44dfc39
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions src/compose.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,5 @@ export default function compose(...funcs) {
return funcs[0]
}

const last = funcs[funcs.length - 1]
const rest = funcs.slice(0, -1)
return (...args) => rest.reduceRight((composed, f) => f(composed), last(...args))
return funcs.reduce((a, b) => (...args) => a(b(...args)))
}

4 comments on commit 44dfc39

@liqiang372
Copy link
Contributor

@liqiang372 liqiang372 commented on 44dfc39 Jan 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is indeed a good improvement for LOC, but I don't think it has better performance than reduceRight in terms of speed and memory allocation. js bin unless the it is trivial since we generally don't create that thousands of reducers in real-apps

@JoeCortopassi
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we actually perf tested it as part of the initial PR, and this way was always faster (between 1-3x)

@markerikson
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, the point is that most apps are probably only calling this one time during app initialization, rather than thousands of times over the life of the app.

@JoeCortopassi
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@markerikson I was just responding to this comment

but I don't think it has better performance than reduceRight in terms of speed and memory allocation

Please sign in to comment.