GriddleGriddle / Griddle

Simple Grid Component written in React
http://griddlegriddle.github.io/Griddle/
MIT License
2.5k stars 378 forks source link

Component Re-render improvements #755

Closed joellanciaux closed 7 years ago

joellanciaux commented 7 years ago

Griddle major version

v1

Changes proposed in this pull request

In an effort to resolve #750, I've made some updates to improve some of the diffing / shouldComponentUpdate logic in a handful of locations.

Why these changes are made

Are there tests?

Covered by previous tests.

dahlbyk commented 7 years ago

This is some great stuff!

Updated GriddleConnect to not redefine connected component every render.

My first thought when I saw this render() method is that this could probably be a functional component using withContext. Am I missing something?

Scoped selectors for cell properties.

I'm having a bit of trouble wrapping my head around this - can you talk me through it?

This is a slight API change ⚠️

SemVer-wise, might consider reverting this change but including a story to demonstrate how to build a better Cell?

joellanciaux commented 7 years ago

My first thought when I saw this render() method is that this could probably be a functional component using withContext. Am I missing something?

I totally might be missing something, but the thought is to preserve the existing function signature of the react-redux connect function without overwriting the store context value for any custom components that might be using the vanilla connect to grab values from their application store.

If we're using withContext to change the store context value, we'll break regular connect for anything nested inside of Griddle.

can you talk me through it?

This is explained pretty well in the reselect documentation.

More or less, reselect is only memoizing the results of the cellProperties selector for a particular set of state and props. Because we're using this selector for all of the Cell elements we're building, it's constantly destroying the memoized value as it's receiving new properties for each different Cell.

Scoping the selector's use keeps reselect's memoization meaningful.

SemVer-wise, might consider reverting this change but including a story to demonstrate how to build a better Cell?

On further review, I think we can skip this change. Phew 😅

rdavidwu commented 7 years ago

This is great stuff @joellanciaux @dahlbyk Do you know when this is expected to be released?

ryanlanciaux commented 7 years ago

This one is in npm right now but not as latest. I'm going to give it another run through and push as latest sometime this weekend :+1: