Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Normalizing Redux

Normalizing Redux

Avatar for João Paulo Siqueira Lins

João Paulo Siqueira Lins

August 29, 2019
Tweet

More Decks by João Paulo Siqueira Lins

Other Decks in Programming

Transcript

  1. • Bachelor of Computer Engineering @ UFPE • 3 years

    working with Web Development • Front end enthusiast João Paulo Lins Fullstack Developer @ Vinta /joaopslins [email protected]
  2. We're a team of experts from Brazil. We help our

    clients evolve their products the right way with top notch development and UX techniques. Get to know us: vintasoftware.com
  3. • Duplicated data is harder to update. • Nested data

    implies in nested reducer logic. Nested data
  4. • Duplicated data is harder to update. • Nested data

    implies in nested reducer logic. • Updates to nested data can generate unnecessary re-renders. Nested data
  5. “The more your frontend state looks like a database, the

    easier it is to work with it.” - Dan Abramov
  6. • Normalized data - No repetitions. • Data is structured

    in Tables. • Relationships are indicated by Foreign Keys. Database characteristics
  7. • Normalizr is a small, but powerful utility for taking

    JSON with a schema definition and returning nested entities with their IDs, gathered in dictionaries. • https://github.com/paularmstrong/normalizr Normalizr
  8. Normalizr API • Normalizr API consists of: ◦ schema -

    definition of Entities ◦ normalize() / denormalize() - transformations
  9. Tip - Selectors • The selector pattern is an abstraction

    that standardizes an application’s store querying logic. • For any part of the store that an application needs access to, define a function that when given the full store, returns the desired part (or derivation) of the store. https://hackernoon.com/selector-pattern-painless-redux-store-destructuring- bfc26b72b9ae
  10. Normalizr + Redux - Good Practices • Normalize data before

    storing into Redux • If denormalizing, be careful with the amount of data
  11. Normalizr + Redux - Good Practices • Normalize data before

    storing into Redux • If denormalizing, be careful with the amount of data • Store the least amount of data possible, and calculate your needs on the fly
  12. Normalizr + Redux - Good Practices • Normalized state structure

    => more components are connected. • “As it turns out, having connected parent components simply pass item IDs to connected children is a good pattern for optimizing UI performance in a React Redux application, so keeping state normalized plays a key role in improving performance.” -- Redux Docs
  13. Normalizr + Redux - Good Practices • Dan Abramov -

    From his article written in 2015:
  14. João Paulo Lins Fullstack Developer /joaopslins [email protected] Thank you! Got

    any questions? Access this talk on github.com/vintasoftware/normalizr-redux-talk
  15. Extra - Reselect • getActiveUsers always returns a new reference

    • filter operation will run on every check
  16. “Performance optimizations are not free. They always come with a

    cost but do not always come with a benefit to offset that cost. Therefore, optimize responsibly.” - Kent C. Dodds