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

Crafting the Perfect Computed Property

Serena Fritsch
July 12, 2016
38

Crafting the Perfect Computed Property

This talk was held as part of Embercamp 2016.

Serena Fritsch

July 12, 2016
Tweet

Transcript

  1. How I Learned To Stop Worrying Use A Babel Transform

    In An Ember Addon With A Computed Property Macro And
  2. How I Learned To Stop Worrying Use A Babel Transform

    In An Ember Addon With A Computed Property Macro Based On Template Strings And
  3. Ember.String.fmt String formatting function available up until Ember 2+ Replaces

    all occurrences of %@ inside a string with the passed arguments
  4. What does it look like? Similar syntax to ES 2015

    Template Strings First proposal on the ember-cpm repository
  5. Proposal Robert Jackson wondered whether we could use real-template strings

    A precedent for this had already been set by the ember-cli-htmlbars- precompiler https://github.com/ember-cli/ember-cli-htmlbars-inline-precompile
  6. Template String Parser Implemented as a node module Follows similar

    concept to James Kyle’s super-tiny compiler https://github.com/thejameskyle/the-super-tiny-compiler Easy to unit-test
  7. Template String Parser hi ${name}, you are ${age} years old

    Sections: Mode: Literal hi name , you are age year s old
  8. Ember Addon Uses Babel source code transformations to overwrite AST

    nodes Imports the String Template Parser as a dependency
  9. How does it work? 1. Detect import statements 2. Detect

    function calls 3. Pass template to parser
  10. How does it work? 1. Detect import statements 2. Detect

    function calls 3. Pass template to parser 4. Substitute function call