Promise-based architecture by Yuri
- think of promises as wrappers around uncertain results
- promises separate defining a request and response handler (callback) at the same time.
- writing functions that accept promises as arguments and return promises, you can make something that almost looks like synchronous code
Check the table in the presentation for useful definitions of promise behaviour (“when the callback…”)
Avoid $q.defer, Denodify instead
- $q.when(x) returns an ok promise
- $q.reject(e) returns a rejected promise
- functions should never ‘sometimes’ return a promise. Always return a promise, or never return a promise. See $q.when and $q.reject
- return a promise if you aren’t sure whether code will eventually be async or not async
Avoid Optimistic Code
- optimistic code is code where you assume that data will eventually be loaded
- ask for a promise instead, even if you think the data loaded already
Neat things with promises
Hexo + AngularJS by Matias
Slides and Code
Static sites are good because:
- Host on AWS S3 (cheap and fast) and CloudFlare (even faster!)
- You get a local copy of your site that’s always up to date by default. Your writing happens locally, and is saved in version control
Hexo is good because:
- Hexo rebuilds pages and sites quickly,
hexo server command watches for content changes and live-reloads them in your browser while you are writing posts
- posts are written in markdown with a small YAML header
- your content can live as files in a Git repo, and custom theme in another Git repo (possibly a private repo)
- templates use common js templating formats – ejs, jade
- uses excellent tools like Warehouse.js
- supports custom pages too (not just posts)
How do I handle dynamic behaviour without a backend?
3rd party services and more JS!
How about capturing all internal link clicks using an Angular directive, and replacing the default behaviour with pushstate, an AJAX call to load the requested page, and an animation to load the content into the current page? That gives you even faster page loads and room to animate content coming and going. Yearofmoo.com is doing this now.
Check out this Meetup →