meteor node upnorth-bobdavies
TRANSCRIPT
MeteorRock your world
Bob DaviesIndieSpring / Imba Software
What is Meteor?
Principles
What it actually does
How it works (101)
http://docs.meteor.com/
Key Principles
Data on the Wire. Don't send HTML over the network. Send data and let the client decide how to render it.
Full Stack Reactivity. Make realtime the default. All layers event-driven.
Simple and Open
http://docs.meteor.com/#sevenprinciples
Single Page
Focus is on intuitive UXClean, single page
Simple interactions
Highly interconnectedSocially networked
Mashup paradise
Simple collaboration platform
Reactive
• Templated views• Application reacts to
– User actions– Data actions– Remote actions
• ‘Synchronisation’ is automatic– No transport code needed
David Glasser in Chicago - Meteor: Past, Present, & Future: http://youtu.be/r996yhHNs5k?t=11m27s
Realtime
• Fetches from MongoDB after every operation– Pushes relevant updates to any subscribed
client• Uses fairly sophisticated algorithm to determine
what to fetch and for whom.
– Also polls every 10 seconds
• Mongo oplog when >= Meteor 0.7.0
Session
• Session is per-tab – sticky session
• Session is retained on hot-code reload, but not on manual refresh (can cause testing issues)
• Session stays open for ~15 minutes (memory on server) after socket closes
Comparison
Several Thousand lines of code (php + jQuery)Hard to build AND to use
TENs of lines of codeVery EASY to build AND use
Application Structure
• Simple structure• Client/server separate files
– but share most functional code
• Publish on server and Subscribe on client• Templated views• MongoDB backend
– Can access others via packages– Flexible nosql data source
• Backend is very efficient with Fibers
Quickstart
// install$ curl https://install.meteor.com/ | sh// create project$ meteor create TestApp
// run$ cd TestApp $ meteor => Meteor server running on: localhost:3000
//deploy$ meteor deploy TestApp.meteor.com
Highly Recommended
// create project$ meteor create TestApp $ cd TestApp
// secure the projectmeteor remove insecuremeteor remove autopublish
// run$ meteor => Meteor server running………
Suggested
$ mkdir server //Only loads on server$ mkdir client //Only loads on client$ mkdir public //Static assets$ mkdir shared //Loads on both (as will anything else not in server or client folder)
• Move (or remove) the premade files– They sort of suck– maybe want templates/views folder too
Publish/SubscribeNO v
ar
Templating
Binding Events
http://stackoverflow.com/a/20794175/1358220
Chris Mather: Understanding the Event Loop, Async and Fibers: http://www.youtube.com/watch?v=AWJ8LIzQMHY
Allow / Deny
What to build?
• Slick UI/UX• Socially Integrated
• Collaborative
http://madewith.meteor.com/
https://www.meteor.com/blog/2014/01/03/6-must-see-meteor-talks-from-2013
Meteor meets Phonegap with Verso: http://youtu.be/eeY1mZhvDy4?t=6m30s
Useful built in packages
Package Management
• Meteorite– Smart packages manager– Several router choices– Installs from atmosphere.meteor.com
• Can use NPM packages– But may require some custom wrappers
• Much better towards 1.0
Challenges
• Good habits in old models, sometimes fail you under Meteor– Centralised data model– Flow is different
• Some developers prefer the old model– Break out!– Don’t force MVC or ‘tack on’ an extra DAL, let
the engine to do the work for you
Into Production
• Setup an appropriate file structure• Check your Allow/Deny rules• Check what code is shared/private• Expect change• Optimise Performance
– Essentially Node under the hood, though some caveats apply (sticky sessions)
Ritik Malhotra: Building a Production-Ready Meteor App:http://www.youtube.com/watch?v=gfFGjmiKfnA
Performance
• Not great with static assets, use a CDN and/or static cache if scaling big
• Wrap source/subscriptions for logged-in and anonymous users differently– Each subscription requires resources
• Use {{#constant}}...{{/constant}} in templates around static content
• {“_id”: “abc123”} is very fast when query/update Collection
http://meteorhacks.com/does-meteor-scale.html
http://projectricochet.com/blog/
Coming Up
• 1.0 expected soon (any day)• Newer, faster render engine• Many more packages appearing
• Students/kids are learning with Meteor• Lots of startups use it for simple products
So, what is Meteor?
• Highly interactive and interconnected• Realtime, reactive• Templated simple user
interface/experience• Accessible and manageable code
– no callback soup
• Scalable and performant
• Getting more awesome every day :)
Thank You :)
How can you benefit
from Meteor?
Bob Davies
IndieSpring / Imba Software
Twitter/Skype @bobbigmac
Facebook /bobdavies
Blog: http://bobbigmac.com