Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Hijacking Hacker News with Ember.js
Search
Godfrey Chan
March 03, 2015
Programming
640
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Hijacking Hacker News with Ember.js
EmberConf 2015
Godfrey Chan
March 03, 2015
More Decks by Godfrey Chan
See All by Godfrey Chan
Virtual EmberConf 2022: Platform State of the Union
chancancode
0
310
Virtual EmberConf 2021: Platform State of the Union
chancancode
0
240
Virtual EmberConf 2020: Platform State of the Union
chancancode
1
390
Thinking in TypeScript
chancancode
0
320
The Lifecycle of a Rails Request
chancancode
3
15k
Dropping Down To The Metal™ (2018)
chancancode
0
170
Using Skylight to Solve Real-World Performance Problems
chancancode
1
450
Prying Open The Black Box (EmberConf 2018)
chancancode
0
430
Bending The Curve: Putting Rust in Ruby with Helix
chancancode
2
2.9k
Other Decks in Programming
See All in Programming
170k Jobs a Day on GKE: Scaling Mercari's CI Platform - and What's Next for AI-Native Development
junyaokabe
0
120
Building a Meta Ray-Ban display app
akkeylab
0
180
What's New in Android 2026
veronikapj
0
270
ソフトウェアエンジニアにとっての生成AI - 特性を知って使い倒す / generative ai for software enginner
kishida
7
2.1k
Flow は今どうなっているか
mizdra
PRO
0
680
運用ダッシュボードの設計を誰も教えてくれないのだけどみなさんどうしてるんですか? - チームに監視するという文化を根付かせるための第一歩を踏みたい -
satoshi256kbyte
1
140
今さら聞けない .NET CLI
htkym
0
210
【QA Test Talk Vol.8】AI-DLC による Whole Team Approach の加速
pkshadeck
PRO
0
220
「寝てても仕事が進む」Claude Codeで組む第二の脳
tomoyafujita2016
0
350
komatsuna「分散システムにおけるバグ分析手法」
komatsunaqa
0
270
まだ間に合う!今年の夏こそSchemeのマクロ展開器を完全理解!
omasanori
0
400
Discordを用いたラボオートメーション関連情報収集の自動化
noguhiro2002
0
380
Featured
See All Featured
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
360
Speed Design
sergeychernyshev
33
2k
AI: The stuff that nobody shows you
jnunemaker
PRO
9
940
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
380
Facilitating Awesome Meetings
lara
57
7.1k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
380
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
250
The #1 spot is gone: here's how to win anyway
tamaranovitovic
3
1.1k
Heart Work Chapter 1 - Part 1
lfama
PRO
8
36k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
800
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
250
Transcript
@chancancode Wednesday, 4 March, 15
Wednesday, 4 March, 15
Wednesday, 4 March, 15
BEFORE AFTER image courtesy of TOM DALE “THE FACE OF
OUR NATION” Wednesday, 4 March, 15
Wednesday, 4 March, 15
Wednesday, 4 March, 15
Wednesday, 4 March, 15
Wednesday, 4 March, 15
52 °F Wednesday, 4 March, 15
52 °F 52 °Freedom Wednesday, 4 March, 15
52 °F 52 °Freedom DEGREES OF FREEDOM Wednesday, 4 March,
15
52 °F 52 °Freedom 11 °cDEGREES OF FREEDOM Wednesday, 4
March, 15
52 °F 52 °Freedom 11 °CANADA 11 °cDEGREES OF FREEDOM
Wednesday, 4 March, 15
52 °F 52 °Freedom 11 °CANADA 11 °cDEGREES OF FREEDOM
“It is currently 11 degrees, in canada.” Wednesday, 4 March, 15
var isEmpty = false; var isLoaded = true; Wednesday, 4
March, 15
var isEmpty = false; var isLoaded = true; var emptyEh
= false; var loadedEh = true; Wednesday, 4 March, 15
>> require 'canada' => true >> [].empty_eh? => true >>
[1,2,3].empty_eh? => false Wednesday, 4 March, 15
gem install canada Wednesday, 4 March, 15
alias npm=gem npm install canada Wednesday, 4 March, 15
Wednesday, 4 March, 15
To Rem 3 Terrible Hacks Wednesday, 4 March, 15
To Rem 3 Terrible Hacks LOL Wednesday, 4 March, 15
You Should A Design Pattern ace Wednesday, 4 March, 15
You Should A Design Pattern YASSS ace Wednesday, 4 March,
15
This Slide? What Colors Are Wednesday, 4 March, 15
This Slide? What Colors Are POLL Wednesday, 4 March, 15
Wednesday, 4 March, 15
DS.Adapter Wednesday, 4 March, 15
ADAPTER PATTERN Wednesday, 4 March, 15
Wednesday, 4 March, 15
Wednesday, 4 March, 15
Wednesday, 4 March, 15
Wednesday, 4 March, 15
var CanadianSensor = { getTemperature: function() { // Measures temperature
in °C } }; Wednesday, 4 March, 15
function FreedomMonitor(sensor) { setInterval(function() { // Expects °F if (sensor.readTemperature()
> 100) { ... } }, 1000); }; var CanadianSensor = { getTemperature: function() { // Measures temperature in °C } }; Wednesday, 4 March, 15
function CanadianAdapter(sensor) { this.sensor = sensor; }; CanadianAdapter.prototype = {
readTemperature: function() { return this.sensor.getTemperature() * 1.8 + 32; } }; // Use it! new FreedomMonitor( new CanadianAdapter(CanadianSensor) ); Wednesday, 4 March, 15
DEMO TIME! Wednesday, 4 March, 15
chancancode / hn-reader Wednesday, 4 March, 15
GETTING THE DATA Wednesday, 4 March, 15
Wednesday, 4 March, 15
$.get("/news").then( function(html) { var stories = []; $(html).find("tr .title a").each(
function (_, $link) { stories.push({ title: $link.text(), url: $link.attr('href') }); }); ... return stories; }); Wednesday, 4 March, 15
Ember Data ( DATA STORE ) JSON API ( DATA
SOURCE ) Wednesday, 4 March, 15
Ember Data ( DATA STORE ) HACKER NEWS HTML SCRAPPER
( DATA SOURCE ) Wednesday, 4 March, 15
Ember Data ( DATA STORE ) HACKER NEWS HTML SCRAPPER
( DATA SOURCE ) Wednesday, 4 March, 15
DS.Adapter DS.Serializer Wednesday, 4 March, 15
App.StoryAdapter = DS.Adapter.extend({ findAll(store, type, id) { return $.get("/news"); }
}); App.StorySerializer = DS.Serializer.extend({ extractArray(store, type, payload) { var stories = []; $(payload).find("tr .title a").each( ... ); return stories; } }); Wednesday, 4 March, 15
FIXING THE URLS Wednesday, 4 March, 15
Wednesday, 4 March, 15
/ Wednesday, 4 March, 15
/ /stories/ Wednesday, 4 March, 15
/ /stories/ /stories/9132815/ Wednesday, 4 March, 15
/ /stories/ /stories/9132815/ /stories/9132815/COMMENTS/ Wednesday, 4 March, 15
“IDEAL” URLS /stories /stories?filter=latest /stories/9132815/comments /stories/9132815/comments?highlight=9133317 Hacker News URLS /news
/newest /item?id=9132815 /item?id=9133317 Wednesday, 4 March, 15
Ember ROUTER HACKER NEWS URLS Wednesday, 4 March, 15
Ember ROUTER ( ACTUAL APP STATES ) HACKER NEWS URLS
( SERIALIZED APP STATES ) Wednesday, 4 March, 15
Ember ROUTER ( ACTUAL APP STATES ) HACKER NEWS URLS
( SERIALIZED APP STATES ) Wednesday, 4 March, 15
History LOCATION /stories /stories?filter=latest /stories/9132815/comments /stories/9132815/comments?highlight=9133317 HASH LOCATION #/stories #/stories?filter=latest
#/stories/9132815/comments #/stories/9132815/comments?highlight=9133317 Wednesday, 4 March, 15
Ember.HistoryLocation Ember.HashLocation Wednesday, 4 March, 15
App.HackerNewsLocation = Ember.HistoryLocation.extend({ getURL: function() { if (this._super() === "/news")
{ return "/stories"; } else if (...) { ... } }, formatURL: function( logicalPath ) { if (logicalPath === "/stories") { return "/news"; } else if (...) { ... } } }); App.Router.reopen({ location: 'hacker-news' }); Wednesday, 4 March, 15
PREFERENCES Wednesday, 4 March, 15
Ember ROUTER <p>{{ localStorage.zomg }}</p> LOCAL STORAGE localStorage.getItem(“zomg”) Wednesday, 4
March, 15
LOCAL STORAGE localStorage.getItem(“key”); localStorage.setItem(“key”, value); $(window).on(“storage”, ...); EMBER.OBSERVABLE obj.get(“key”); obj.set(“key”,
value); obj.addObserver( ... ); Wednesday, 4 March, 15
App.LocalStorage = Ember.Object.extend({ init: function() { $(window).on("storage", Ember.run.bind(this, "_onStorageEvent") );
}, unknownProperty: function(key) { return localStorage.getItem(key); }, setUnknownProperty: function(key, value) { localStorage.setItem(key, value); return true; }, _onStorageEvent: function(e) { this.notifyPropertyChange(e.key); }, willDestroy: function() { $(window).off("storage"); } }); Wednesday, 4 March, 15
THE POSSIBILITIES Wednesday, 4 March, 15
HTML <div> <span> <img> Cocoa UIView UITextView UIImageView Wednesday, 4
March, 15
Wednesday, 4 March, 15
COCOA BARS! Wednesday, 4 March, 15
$ cd cocoabars $ git status # On branch master
# # Initial commit # nothing to commit (create/copy files and use "git add" to track) Wednesday, 4 March, 15
@chancancode Wednesday, 4 March, 15
Wednesday, 4 March, 15
Here is the URL you are looking for: https://github.com/chancancode/hn-reader Wednesday,
4 March, 15
A few awesome things didn’t make it to the slides.
I’ll be tweeting, stay tuned. Wednesday, 4 March, 15
I’d like to dedicate this talk to my favourite teacher
and life-mentor, Miss Shirley Ngai. Wednesday, 4 March, 15
Thank you EmberConf team for putting this together! Wednesday, 4
March, 15
And of course, thank you Ember contributors for making this
amazing framework. Wednesday, 4 March, 15
Huge thanks to those who beta tested my app and
tolerated the “dry” runs of my talk. Wednesday, 4 March, 15
And finally, thank YOU for sitting through my first-ever conference
talk and being awesome! Wednesday, 4 March, 15
One more thing. Wednesday, 4 March, 15
<canvas> bars Wednesday, 4 March, 15
Wednesday, 4 March, 15
(Yes, that’s it.) Wednesday, 4 March, 15
Wednesday, 4 March, 15