Federico Pereiro
(yes, I wrote my own framework)
Scope: frontend of web applications (SPAs)
Takeaway: patterns
Experience: moderate
No code!
HTML & CSS
link
Server
render
HTML & CSS
action
Server
bootstrap
ajax
update
- Sending or receiving info requires a page refresh.
- The page is rendered once.
- Background communication with server.
- The page must be updated.
compare with batch program & web server route
At a minimum:
- Perform bidirectional ajax
- Update parts of the view
- Navigation (SPA)
Optionally:
- Generate HTML/CSS (CSR)
- Hold client state
1) HTML/CSS generation
2) Holding client state
<p>Hello!</p>
[‘p’, ‘Hello!’]
<p class=”nice”></p>
[‘p’, {class: ‘nice’}]
<div>
<p class=”nice”>Hello</p>
</div>
['div', [
[‘p’, {class: ‘nice’}, 'Hello']
]]
Conditional #1: cond ? [‘p’, ‘Hello!’] : []
Conditional #2: [‘p’, {class: cond ? ‘h2’ : ‘’}, ‘Hello!’]
Iteration:
[‘table’, ITEMS.map (function (item) {
return [‘tr’, [‘td’, item]];
})]
function (...) {
// return object literals that represent HTML/CSS
}
{}
function (State) {
// return object literals that represent HTML/CSS
}
Dynamic patterns
1) Data events
2) Complex events
verb
path
arguments
add
set
rem
+
path
set ['users'] [{id: 1}, {id: 2}] add ['users'] {id: 3} rem ['users'] 1
- Modify store
- Fire an event
submit ['user'] {id: 4}
retrieve ['users'] {filter: ...}
- Read store
- Perform computation or AJAX
- Update store
- Trigger other events
View (path, complex_events, function (state) {
// object literals with stringified event triggers
});
nuke (innerHTML)
flatten (Myers diff)
- Make tree into array of strings
- Diff 'em
- Give up after n millis (O (nd))
- Descending priority for nested
-change verb
- Listeners path wildcard
add
set
rem
change
set ['users'] [{name: 'pepe'}]
set ['users', 0, 'name'] 'pepe'
change ['users']
change ['users', 0]
change ['users', 0, 'name']
change ['users', 0, 'email']
event
listener