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
S3 を使うアプリケーションをローカル完結で動かすことに全力を注いでみた / Running S3 Apps Offline
contour_gara
0
490
型も通る、synthも通る、それでも危ない 〜AIのCDKの権限とコストを機械で検証する〜 / It Passes Type Checks, It Passes Synth Checks, but It’s Still Risky — Automatically Verifying Permissions and Costs in AI’s CDK —
seike460
PRO
1
560
人間の目はかわらない、だからJPEGは30年もつ
yuzneri
12
18k
FDEが実現するAI駆動経営の現在地
gonta
2
280
2年かけて Deno に DOMMatrix を実装した話 / How I implemented DOMMatrix in Deno over two years
petamoriken
0
210
JAWS-UG横浜 #102 AWSサ終供養LT会 成仏できない AWS サービスたち 〜本日、三体供養します〜
maroon1st
0
360
Building a Meta Ray-Ban display app
akkeylab
0
150
わからない話を追いかけたら、プログラミング言語を作る側にいた
ydah
3
510
進化を続けるGo toolsの現在地 / The Current State of Ever-Evolving Go Tools
hond0413
0
220
5分で問診!Composer セキュリティ健康診断
codmoninc
0
1k
OpenSpecのproposalにbrainstormingを持たせてみた
tigertora7571
1
230
テーブルをDELETEした
yuzneri
0
140
Featured
See All Featured
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.2k
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
4.2k
Everyday Curiosity
cassininazir
0
280
The untapped power of vector embeddings
frankvandijk
2
1.8k
Claude Code のすすめ
schroneko
67
230k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
1.2k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
650
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.3k
Reality Check: Gamification 10 Years Later
codingconduct
0
2.3k
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
540
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
460
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