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

Modifiers: the good and the Camp

Spencer P
September 16, 2019

Modifiers: the good and the Camp

A presentation on a new feature in Ember: Modifiers. Inspired by lots of campy musicals.

Spencer P

September 16, 2019
Tweet

Other Decks in Technology

Transcript

  1. • Pronouns he/him/his • Engineering Manager at Movable Ink •

    Frequent Broadway-goer • @spencer516 on Twitter & Github • Amateur photographer of one dog Hi! I’m Spencer!
  2. - Susan Sontag: Notes on “Camp” “It is the love

    of the exaggerated, the ‘off,’ of things-being-what-they-are-not.”
  3. - Susan Sontag: Notes on “Camp” “People who share this

    sensibility are not laughing at the thing they label as ‘a camp,’ they're enjoying it. Camp is a tender feeling.”
  4. - Susan Sontag: Notes on “Camp” “What it does is

    to find the success in certain passionate failures.”
  5. - Susan Sontag: Notes on “Camp” “The whole point of

    Camp is to dethrone the serious. Camp is playful, anti-serious.”
  6. • The Modifier Concept • History of Modifiers • Creating

    Modifiers • Good Use Cases • Campy Use Cases Overview
  7. A small reusable tool, like a Helper, that attaches behavior

    to elements using lifecycle events. What is a Modifier?
  8. • autofocus attribute only works on Page Load • element.focus()

    needs to fire once after element is added example: Autofocus
  9. What is a Modifier? • Cannot be expressed by HTML

    alone • Therefore, does not run Server-side in Fastboot
  10. • {{action}} modifier attaches event listeners to elements • Supports

    an on=“EVENT_TYPE” argument • {{bind-attr}} modifier to set element attributes • Deprecated in 1.11 • Removed in 2.0 History of Ember Modifiers
  11. Autofocus in Octane export default class AutoFocusInput extends GlimmerComponent {

    @action focus(element) { element.focus(); } }; <input {{did-insert this.focus}}>
  12. • Use the setModifierManager API • Use the ember-oo-modifiers library

    • Use the ember-functional-modifiers library Making a Modifier
  13. Autofocus: OO Modifiers // app/modifiers/autofocus.js import Modifier from 'ember-oo-modifiers'; export

    default class AutofocusModifier extends Modifier { didInsertElement() { this.element.focus(); } }
  14. Modifier: draggable export default class MoveMe extends Component { @tracked

    x = 0; @tracked y = 0; @action updatePosition([x, y]) { this.x = x; this.y = y; } }
  15. Modifier: draggable export default class MoveMe extends Component { @tracked

    x = 0; @tracked y = 0; @action updatePosition([x, y]) { this.x = x; this.y = y; } get style() { const { x, y } = this; return htmlSafe(`transform: translate(${x}px, ${y}px);`); } }
  16. “I spend my life accounting with figures and such. To

    what is my life amounting, it figures not much.” I Wanna Be a Producer
  17. Modifier: track-on export default class CartAdder extends Component { @service

    metrics; @action addtoCart(...args) { this.metrics.track('Add to cart'); this.args.addToCart(...args); } }
  18. • ember-tooltip by @sir-dunxalot • ember-attacher by @kybishop • ember-pop-over

    by @tim-evans (not updated since Jan 2018) Modifier: flyover
  19. Modifier: flyover <SomeComponent {{on "mouseenter" (set this.showFlyover true)}} {{on "mouseleave"

    (set this.showFlyover false)}} > Hover for more info </SomeComponent> {{#if this.showFlyover}} <SomeTooltip> Here is the info! </SomeTooltip> {{/if}}
  20. Modifier: flyover <SomeComponent {{on "mouseenter" (set this.showFlyover true)}} {{on "mouseleave"

    (set this.showFlyover false)}} {{launch—pad}} > Hover for more info </SomeComponent> {{#if this.showFlyover}} <SomeTooltip {{flyover}}> Here is the info! </SomeTooltip> {{/if}}
  21. “Why do you write like you're running out of time?

    Write day and night like you're running out of time?” Non-Stop
  22. “Jaysus, that’s a jumbo! And now I'm adding this up

    We got thirty-eight planes ...holy shit!” 38 Planes
  23. Modifier: did-resize <div {{did-resize this.didResize}}> Resize Amount: {{this.resizes}} Current Width:

    {{this.width}}px </div> This exists! Thanks @gmurphey ember install ember-did-resize-modifier
  24. “I'll escape now from that world,
 from the world of

    Jean Valjean. Jean Valjean is nothing now — another story must begin!” Valjean’s Soliloquy
  25. Modifier: focus-trap <div {{focus-trap}}> <p> Here is a focus trap

    <a href="#">with some</a> <a href="#">focusable parts.</a> </p> <p> <button>Some button</button> </p> </div> This exists too! Thanks @josemarluedke ember install ember-focus-trap
  26. • Solves the problem of “prop drilling” with ephemeral services

    • Idea borrowed from ember-provider by @alexlafroscia • Relies on parentView (doesn’t exist in Glimmer?) • Conceptually similar to React Context Modifier: scoped
  27. Modifier: scoped {{! templates/application.hbs }} <div {{scoped-provider "DocumentStore"}}> <MyFunkyComponent />

    </div> {{!...somewhere deeply nested in MyFunkyComponent }} <div {{scoped-consumer "DocumentStore" (set this.documentStore _)}}> {{#each this.documentStore.docs as |doc|} } <Doc @doc={{doc}} /> {{/each}} </div>
  28. • Looking on the bride side o’ life: it solves

    a real problem • What if you wormhole? • Maybe just another “global” :-| Modifier: scoped
  29. “I'm gonna have ta gallop, because there is a gal

    up here Who's rustlin' up a herd of your love. So saddle up!” Ride ‘Em
  30. • This exists! ember-split-view-modifier • Thanks @bekzod • Uses split.js

    under-the-hood • Super easy to use Modifier: split-view
  31. • Split.js adds unmanaged elements • Conditional elements? • Would

    a Component-based API be better? Modifier: split-view
  32. • The same as the on modifier • But it

    predicts! • Related Library: guess-js Modifier: predict-on
  33. Modifier: predict-on <LinkTo @route="flowers" {{predict-on "click" (fn this.preload "flowers")}} >

    Flowers </LinkTo> <LinkTo @route="paint" {{predict-on "click" (fn this.preload "paint")}} > Paint </LinkTo>
  34. • Machine Learning, something something, AI • I HAVE NO

    IDEA HOW TO DO THIS. Modifier: predict-on
  35. “Skeptical cats, Dispeptical cats Romantical cats, Pedantical cats Critical cats,

    Parasitical cats (…etc)” Jellicle Songs for Jellicle Cats
  36. “And the way I keep my pinky up Indubitably proves

    That we got elegance.” Elegance
  37. • Small and isolated is good • Bigger Abstractions ≈

    Component? • Experiment and share! Rules about Modifiers
  38. “Hold your Bat Boy, Touch your Bat Boy No more

    need to hide! Know your Bat Boy, Love your Bat Boy. Don’t deny your beast inside! Ah, ah — Aaaaaaa! Aaaaaaahhhh! Hold Me Bat Boy (Reprise)