meteor node upnorth-bobdavies

26
Meteor Rock your world Bob Davies IndieSpring / Imba Software

Upload: mark-skeet

Post on 10-May-2015

2.969 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Meteor node upnorth-bobdavies

MeteorRock your world

Bob DaviesIndieSpring / Imba Software

Page 2: Meteor node upnorth-bobdavies

What is Meteor?

Principles

What it actually does

How it works (101)

http://docs.meteor.com/

Page 3: Meteor node upnorth-bobdavies

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

Page 4: Meteor node upnorth-bobdavies

Single Page

Focus is on intuitive UXClean, single page

Simple interactions

Highly interconnectedSocially networked

Mashup paradise

Simple collaboration platform

Page 5: Meteor node upnorth-bobdavies

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

Page 6: Meteor node upnorth-bobdavies

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

Page 7: Meteor node upnorth-bobdavies

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

Page 8: Meteor node upnorth-bobdavies

Comparison

Several Thousand lines of code (php + jQuery)Hard to build AND to use

Page 9: Meteor node upnorth-bobdavies

TENs of lines of codeVery EASY to build AND use

Page 10: Meteor node upnorth-bobdavies

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

Page 11: Meteor node upnorth-bobdavies

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

Page 12: Meteor node upnorth-bobdavies

Highly Recommended

// create project$ meteor create TestApp $ cd TestApp

// secure the projectmeteor remove insecuremeteor remove autopublish

// run$ meteor => Meteor server running………

Page 13: Meteor node upnorth-bobdavies

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

Page 14: Meteor node upnorth-bobdavies

Publish/SubscribeNO v

ar

Page 15: Meteor node upnorth-bobdavies

Templating

Page 16: Meteor node upnorth-bobdavies

Binding Events

http://stackoverflow.com/a/20794175/1358220

Chris Mather: Understanding the Event Loop, Async and Fibers: http://www.youtube.com/watch?v=AWJ8LIzQMHY

Page 17: Meteor node upnorth-bobdavies

Allow / Deny

Page 18: Meteor node upnorth-bobdavies

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

Page 19: Meteor node upnorth-bobdavies

Useful built in packages

Page 20: Meteor node upnorth-bobdavies

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

Page 21: Meteor node upnorth-bobdavies

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

Page 22: Meteor node upnorth-bobdavies

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

Page 23: Meteor node upnorth-bobdavies

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/

Page 24: Meteor node upnorth-bobdavies

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

Page 25: Meteor node upnorth-bobdavies

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 :)

Page 26: Meteor node upnorth-bobdavies

Thank You :)

How can you benefit

from Meteor?

Bob Davies

IndieSpring / Imba Software

Twitter/Skype @bobbigmac

Facebook /bobdavies

Blog: http://bobbigmac.com