Weitere ähnliche Inhalte Ähnlich wie Web-First Design Patterns Ähnlich wie Web-First Design Patterns (20) Kürzlich hochgeladen (20) Web-First Design Patterns4. Evolution of Design Patterns
The Mother of All Design Principles
The Mother of All Design Patterns
Web-First Patterns
Pattern-Fu
19. #highCohesion
#lowCoupling
#modularity #isolation
#separationOfConcerns
26. Test
Driver
Good: We can test!
31. shop
cart
item item
added changed
eventA eventB eventC
item removed
36. eventA eventB eventC
The Problem: Event Registration
37. Timer = {
init: function() {
listen(“pageLoad”, this.onPageLoad);
listen(“trialStart”, this.onTrialStart);
listen(“trialEnd”, this.onTrialEnd);
}
}
The Problem: Event Registration
39. Timer = {
pageLoad: function() { … }
trialStart: function() { … }
trialEnd: function() { … }
}
Solution: Automagic Registration
40. AppMediator = {
init: function() {
var components=[Trial, Counter, …]
var handlers = {
init: [],
trialStart: [],
trialEnd: []
}
for (eventType in handlers) {
components.forEach(function(component) {
if (component[eventType])
handlers[eventType].push(component);
}
}
}
fire: function(eventType) { … }
}
Solution: Automagic Registration
41. Timer = {
pageLoad: function() { … }
onTrialStart: function() { … }
onTrialEnd: function() { … }
}
42. Timer = {
pageLoad: function() { … }
onTrialStart: function() { … }
onTrialEnd: function() { … }
}
An example of
Convention Over Configuration
44. h1 {
background: blue;
font-family: arial;
}
#account h1 {
background: red;
}
#account h1:hover {
border-color: black;
}
The Problem:
CSS Jungle
45. .account {
background: #f9a;
}
.heading {
color: #882;
}
Solution:
Use classes, not IDs or Tags
46. .account {
background: #f9a;
}
.heading {
color: #882;
}
Solution:
Avoid hierarchies
48. Logged in?
Show name
Allowed to rate? Managing your page?
Show thumbs Show edit controls
Leaving a comment?
Show textarea
The Problem:
Complex Display Logic
49. function startEditing() {
$(‘.titleInput’).show();
$(‘.mixPanel’).slideDown();
$(‘.comments’).fadeOut();
}
function stopEditing() {
$(‘.titleInput’).hide();
$(‘.mixPanel’).slideUp();
$(‘.comments’).fadeIn();
}
The Problem:
Complex Display Logic
54. <! accounts.forEach(account) { >
<li><!= account.balance ></li>
<! } >
<ul>
<li>28.50</li>
<li>48.50</li>
<li>78.12</li>
</ul>
The Problem:
Even client-side templates are static
55. <tr>
<td>28.50</td>
<td>48.50</td>
<td>78.12</td>
</tr>
The Problem:
Can’t transform representation