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

Type safe CSS with Reason

Ciro Nunes
February 13, 2020

Type safe CSS with Reason

Ciro Nunes

February 13, 2020
Tweet

More Decks by Ciro Nunes

Other Decks in Programming

Transcript

  1. @cironunesdev import { css } from '@emotion/core' const titleStyle =

    css({ boxSizing: 'border-box', width: 300, height: 200 })
  2. @cironunesdev CONFIDENCE Add, change and delete CSS without any unexpected

    consequences DYNAMIC STYLES Style your components with a global theme or based on different states
  3. @cironunesdev CONFIDENCE Add, change and delete CSS without any unexpected

    consequences DYNAMIC STYLES Style your components with a global theme or based on different states MAINTAINIBILITY Never go on a hunt for CSS affecting your components ever again
  4. @cironunesdev CONFIDENCE Add, change and delete CSS without any unexpected

    consequences DYNAMIC STYLES Style your components with a global theme or based on different states MAINTAINIBILITY Never go on a hunt for CSS affecting your components ever again PERFORMANCE Send only the critical CSS to the user for a rapid first paint
  5. @cironunesdev import { css } from '@emotion/core' const titleStyle =

    css({ boxSizing: 'bordre-box', width: 300, height: 200 })
  6. @cironunesdev import { css } from '@emotion/core'; const titleStyle =

    css({ ^ Argument of type 'boxSizing: 'bordre-box';' is not assignable [...] boxSizing: 'bordre-box', // Oops, there's a typo! width: 300, height: 200, });
  7. @cironunesdev 100% SAFETY The compiler finds errors reliably so you

    don’t have to CLARITY There is far less ambiguity. e.g.: “1” == 1 && 1.0 == 1
  8. @cironunesdev 100% SAFETY The compiler finds errors reliably so you

    don’t have to CLARITY There is far less ambiguity. e.g.: “1” == 1 && 1.0 == 1 LESS ERRORS Type problems are a whole class of errors you just don’t have to deal with
  9. @cironunesdev 100% SAFETY The compiler finds errors reliably so you

    don’t have to CLARITY There is far less ambiguity. e.g.: “1” == 1 && 1.0 == 1 LESS ERRORS Type problems are a whole class of errors you just don’t have to deal with PERFORMANCE The more information the compiler has, the more it can optimise
  10. @cironunesdev OBJECTIVES ☐ Create a Todo app using ReasonReact ☐

    Style it using bs-css ☐ Animate the items being added/removed
  11. TAKEAWAYS ✓ Confidence: to add, change and delete code ✓

    Performance: improved by delivering only the critical path CSS CSS-IN-JS 1 2 3 %
  12. TAKEAWAYS ✓ Confidence: to add, change and delete code ✓

    Performance: improved by delivering only the critical path CSS ✓ Dynamic styles is a no brainer CSS-IN-JS 1 2 3 %
  13. TAKEAWAYS ✓ Confidence: to add, change and delete code ✓

    Performance: improved by delivering only the critical path CSS ✓ Dynamic styles is a no brainer CSS-IN-JS STATIC TYPING 1 2 3 %
  14. TAKEAWAYS ✓ Confidence: to add, change and delete code ✓

    Performance: improved by delivering only the critical path CSS ✓ Dynamic styles is a no brainer CSS-IN-JS STATIC TYPING ✓ Confidence: that our code is correct at compile-time 1 2 3 %
  15. TAKEAWAYS ✓ Confidence: to add, change and delete code ✓

    Performance: improved by delivering only the critical path CSS ✓ Dynamic styles is a no brainer CSS-IN-JS STATIC TYPING ✓ Confidence: that our code is correct at compile-time ✓ Performance: by giving the compiler type information 1 2 3 %
  16. TAKEAWAYS ✓ Confidence: to add, change and delete code ✓

    Performance: improved by delivering only the critical path CSS ✓ Dynamic styles is a no brainer CSS-IN-JS STATIC TYPING REASON ✓ Confidence: that our code is correct at compile-time ✓ Performance: by giving the compiler type information 1 2 3 %
  17. TAKEAWAYS ✓ Confidence: to add, change and delete code ✓

    Performance: improved by delivering only the critical path CSS ✓ Dynamic styles is a no brainer CSS-IN-JS STATIC TYPING REASON ✓ Confidence: that our code is correct at compile-time ✓ Performance: by giving the compiler type information ✓ Confidence: that our code is 100% type safe and sound 1 2 3 %
  18. TAKEAWAYS ✓ Confidence: to add, change and delete code ✓

    Performance: improved by delivering only the critical path CSS ✓ Dynamic styles is a no brainer CSS-IN-JS STATIC TYPING REASON ✓ Confidence: that our code is correct at compile-time ✓ Performance: by giving the compiler type information ✓ Confidence: that our code is 100% type safe and sound ✓ Familiar: Syntax & ecosystem used by JS developers 1 2 3 %