Skip to content

Instantly share code, notes, and snippets.

@alexmcpherson
Last active August 29, 2015 14:04
Show Gist options
  • Save alexmcpherson/4ebc65db31cd2a2ce0e2 to your computer and use it in GitHub Desktop.
Save alexmcpherson/4ebc65db31cd2a2ce0e2 to your computer and use it in GitHub Desktop.
polymer-presentation
//spoiler: I just copy this from view to view. Bad ergonomics.
attachIncrementors: function() {
var incrementor = new IncrementorView({
attrName : 'difference',
model: this.model.dishwashing_model,
options: Helpers.range(0, 100),
template: JST['components/load_incrementor']
});
incrementor.render();
this.$('#dishLoadsIncrementor').html(incrementor.el);
},
<body>
<!-- WHAT THIS IS CRAZY USEFUL -->
<carousel autoplay controls='false'>
<img src='1.png' />
<img src='2.gif' />
<img src='3.jpg' />
</carousel>
</body>
<body>
<!-- How does that... I don't even... -->
<twitter-follow user='@alexmcpherson'>Follow me!</twitter-follow>
</body>
<html>
<head>
<!-- 1. Load platform.js for polyfill support. -->
<script src="bower_components/platform/platform.js"></script>
<!-- 2. Use an HTML Import to bring in the element. -->
<link rel="import"
href="bower_components/core-ajax.html">
</head>
<body>
<!-- 3. Declare the element. Configure using its attributes. -->
<core-ajax url="http://example.com/json"
handleAs="json"></core-ajax>
<script>
window.addEventListener('polymer-ready', function(e) {
var ajax = document.querySelector('core-ajax');
ajax.addEventListener('core-response', function(e) {
console.log(this.response);
});
ajax.go(); // Call its API methods.
});
</script>
</body>
</html>
//lifecycle filters
Polymer('sweet-tag', {
created: function() { ... },
ready: function() { ... },
attached: function () { ... },
domReady: function() { ... },
detached: function() { ... },
nameChanged: function() { //magic! },
});
//expressions in templates
<div class="{{ {active: user.selected, big: user.type == 'super'} | tokenList }}">

What the what is a web component

  • a little box drawn around some functionality in a reusable way
  • Polymer.js, React.js, Ember.Component, Mozilla Brick, etc
  • DX issues: a Backbone component...?

But what about:

  • Testing? ezpz
  • HTML Load times and file sizes? Vulcanize
  • Sharing or using sweet internet stuff? Bower
  • Mobile? A primary goal Topeka

Other features

  • two way data binding
  • element inheritance
  • plays fine with CSS pre-processers
  • nuzzles in nicely to the grunt/gulp/bower/yeoman toolchain
  • not all you can eat: take what you need
  • this thing

Why is Polymer different?

  • Secret browser advances for custom elements

    • Shadow DOM API
    • HTML Imports
    • Object.observe
    • ES6 WeakMap (objects as keys! What!)
  • Google sugar for stitching it together

    • Mutation Observers
    • Animation Helpers
    • URL helpers

How do I use this?

  1. platform.js (polyfills everything)
  2. <link rel="import" href="custom-element.html">
  3. There is no 3. Throw those tags around like you mean it
  • IE10+, evergreen browsers
  • IE9 sorta works
  • Chrome 36 doesn't need platform.js. It's all there (!!!)

Pros/Cons

A++

  • native languages for everything
  • true sandboxing
  • dev ergonomics through the roof

F--

  • sandboxing with shadow DOM is the new this problem
  • big network time. async requests throughout
  • seems unwieldy for 'apps', better for true components

Approaches that seem to work (IMO)

  • No-business-logic widgets
  • Only replace the view layer
  • Styleguide build out

Not so hot

  • Big injection trains
  • Less sure about the 'void' components

But Alex, how do I trust you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment