Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
AOP with YouAreDaBomb
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Jan Filipowski
June 11, 2012
70
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
AOP with YouAreDaBomb
Jan Filipowski
June 11, 2012
Featured
See All Featured
Become a Pro
speakerdeck
PRO
31
6.3k
Rails Girls Zürich Keynote
gr2m
96
14k
Heart Work Chapter 1 - Part 1
lfama
PRO
10
37k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
540
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
35
2.9k
Navigating Weather and Climate Data
rabernat
0
560
Exploring anti-patterns in Rails
aemeredith
4
540
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
3
3.9k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
710
The Cult of Friendly URLs
andyhume
79
7k
Site-Speed That Sticks
csswizardry
13
1.6k
New Earth Scene 8
popppiees
4
2.7k
Transcript
AOP with YouAreDaBomb Jan Filipowski, Arkency, Gameboxed
Me Twitter: @janfilipowski Blog: http://agiler.net
Hate mode: on Let's start!
AOP for dummies • separation of cross-cutting concerns • concerns:
logging, authorization, security, storage etc. • aspect • advice • join point
Example - logging author = // (...) writePost: (title, content)
-> @posts.push(new Post(title, content)) Before(author, 'writePost', (title, content) -> console.log("Author#writePost(#{title}, #{content})") ) author.writePost("title", "long content") # console: Author#writePost(title,content) author.posts.length # 1
Example - storage After(author, 'writePost', (title, content) -> serverSide.storePost(title, content)
) author.getAllPosts = (callback) -> callback(@posts) Around(author, 'getAllPosts', (proceed, args...) -> serverSide.getAllPosts((response) -> author.posts = buildPosts(response) proceed(args...) ) )
AOP in JavaScript / CoffeeScript • YouAreDaChef (http://github.com/raganwald/YouAreDaChef) ◦ based
on prototypes ◦ supports npm • YouAreDaBomb (http://github.com/gameboxed/YouAreDaBomb) ◦ inspired by YouAreDaChef ◦ based on objects ◦ supports callback advices (beforeAnyCallback, afterAnyCallback) ◦ doesn't support npm yet
YouAreDaBomb API YouAreDaBomb(object, methodName) .before((args...) -> (...)) .after((args...) -> (...))
.around((proceed, args...) -> (...)) .beforeAnyCallback((callbackArgs...) -> (...)) .afterAnyCallback((callbackArgs...) -> (...)) # chainable
YouAreDaBomb shortcuts API • Before • After • Around
Our approach • use cases as flow • domain models
• GUI components • server-side and Facebook adapters • aspects as glue
Real world simple example • simple social app • write
something - it will be posted as a picture on facebook • you can write it only once
Real world simple example use case class MainUseCase constructor: (@game)
-> enterGame: => if
[email protected]
() @useEditor() useEditor: => writeStatement: (statement) => @game.playerWriteStatement(statement)
Real world simple example GUI aspect class MainGuiConfiguration constructor: (@useCase,
@gui) -> execute: => After @useCase, 'useEditor', => @gui.showEditor() @gui.hideSubmittedStatement() Around(@useCase, 'writeStatement', @onWriteStatement) After(@gui.editor, 'submitStatement', (statement) => @useCase.writeStatement(statement)) onWriteStatement: (proceed, args...) => statement = proceed(args...) @gui.addStatementToList(statement) @gui.hideEditor() @gui.showSubmittedStatement()
Real world simple example Game storage aspect class GameAspect constructor:
(@game, @services) -> execute: => After(@game, 'playerWriteStatement', (statement) => @services.serverSide.playerWriteStatement(statement))
Real world simple example Viral aspect class RequireLikeFanpageToEnterAspect constructor: (@usecase,
@game, @services) -> execute: () => Around @usecase, 'enterGame', (proceed) => @services.facebookAdapter.isFan @game.player.facebookUid, @game.fanpageId, (likes) => if likes proceed() else component = new LikeFanpageToProceedPopupComponent(@services, @game) component.showPopup(proceed)
Real world example - quiz game Usecase (object): 1. enter
quiz 2. get next question 3. answer question 4. correct answer made 5. wrong answer made 6. end quiz
Example: Enter quiz GUI aspect: • Display popup and wait
for "OK" click • Render question and answers board Sound aspect: • Play intro sound
Example: Get next question GUI aspect: • show question •
show answers Storage: • get question (advice on Quiz#getNextQuestion) Sound: • play 'new question' sound
Example: Answer question GUI: • highlight answer Storage: • Store
answer
Example: Correct answer made GUI: • show "yay!" Storage: •
save players points Sound: • play "yay!"
Example: Wrong answer made GUI: • show "buuu" Storage: •
store info about wrong answer Sound: • play 'buuu'
Example: End quiz GUI: • hide question and answers board
• show popup with results Storage: • store game session info Social feature: • post to wall about results
Thank you hate mode: off