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

What if there isn’t?

Surma
November 06, 2015

What if there isn’t?

DevFest Hamburg 2015

Surma

November 06, 2015
Tweet

More Decks by Surma

Other Decks in Technology

Transcript

  1. <template is="dom-bind"> <reddit-api posts="{{posts}}" sorting="{{sorting}}" subreddit="{{subreddit}}"></reddit-api> <paper-input value="{{subreddit::change}}"></paper-input> <paper-radio-group selected="{{sorting}}">

    <!-- ... --> </paper-radio-group> <template is="dom-repeat" items="[[posts]]"> <a class=“post” href="[[item.link]]">[[item.title]]</a> </template>
  2. <template is="dom-bind"> <reddit-api posts="{{posts}}" sorting="{{sorting}}" subreddit="{{subreddit}}"></reddit-api> <paper-input value="{{subreddit::change}}"></paper-input> <paper-radio-group selected="{{sorting}}">

    <!-- ... --> </paper-radio-group> <template is="dom-repeat" items="[[posts]]"> <a class=“post” href="[[item.link]]">[[item.title]]</a> </template>
  3. <script> Polymer({ is: 'reddit-api', properties: { subreddit: { type: String,

    reflectToAttribute: true, notify: true }, // ... }); </script>
  4. <script> Polymer({ is: 'reddit-api', properties: { sorting: { type: String,

    reflectToAttribute: true, notify: true }, // ... }); </script>
  5. <script> Polymer({ is: 'reddit-api', properties: { posts: { type: Array,

    readOnly: true, value: function() { return []; }, notify: true }, // ...
  6. <script> Polymer({ is: 'reddit-api', properties: { baseUrl: { type: String,

    value: 'https://api.reddit.com', notify: true }, // ... }); </script>
  7. <script> Polymer({ is: 'reddit-api', properties: { _requestUrl: { type: String,

    computed: '_computeUrl(baseUrl, subreddit, sorting)', notify: true }, // ... }); </script>
  8. <script> Polymer({ is: 'reddit-api', _computeUrl: function(baseUrl, subreddit, sorting) { return

    baseUrl + subreddit + '/' + sorting + '?jsonp=%%callback%%'; }, </script>
  9. <template is="dom-bind"> <reddit-api posts="{{posts}}" sorting="{{sorting}}" subreddit="{{subreddit}}"></reddit-api> <paper-input value="{{subreddit::change}}"></paper-input> <paper-radio-group selected="{{sorting}}">

    <!-- ... --> </paper-radio-group> <template is="dom-repeat" items="[[posts]]"> <a class=“post” href="[[item.link]]">[[item.title]]</a> </template>
  10. <template is="dom-bind"> <reddit-api posts="{{posts}}" sorting="{{sorting}}" subreddit="{{subreddit}}"></reddit-api> <paper-input value="{{subreddit::change}}"></paper-input> <paper-radio-group selected="{{sorting}}">

    <!-- ... --> </paper-radio-group> <template is="dom-repeat" items="[[posts]]"> <a class=“post” href="[[item.link]]">[[item.title]]</a> </template>
  11. <template is="dom-bind"> <reddit-api posts="{{posts}}" sorting="{{sorting}}" subreddit="{{subreddit}}"></reddit-api> <paper-input value="{{subreddit::change}}"></paper-input> <paper-radio-group selected="{{sorting}}">

    <!-- ... --> </paper-radio-group> <template is="dom-repeat" items="[[posts]]"> <a class=“post” href="[[item.link]]">[[item.title]]</a> </template>
  12. <template is="dom-bind"> <reddit-api posts="{{posts}}" sorting="{{sorting}}" subreddit="{{subreddit}}"></reddit-api> <paper-input value="{{subreddit::change}}"></paper-input> <paper-radio-group selected="{{sorting}}">

    <!-- ... --> </paper-radio-group> <template is="dom-repeat" items="[[posts]]"> <a class=“post” href="[[item.link]]">[[item.title]]</a> </template>
  13. _constructServiceWorkerUrl: function() { var paramsPromises = []; var cs =

    Polymer.dom(this).children; for (var i = 0; i < cs; i++) { if (typeof cs[i]._getParameters === 'function') { var params = cs[i]._getParameters(); paramsPromises.push(params); } } }
  14. var serviceWorkerUrl = new URL(this.href, window.location); serviceWorkerUrl.search = Object.keys(params).sort() .map(function(key)

    { return encodeURIComponent(key) + "=" + encodeURIComponent(params[key]); }).join('&'); navigator.serviceWorker .register(serviceWorkerUrl, { scope: this.scope