by
Kyle Mitofsky
|
@KyleMitBTV
Presentation
|
Demo
Software Development Tech Lead
at the Vermont Department of Health
Reactive, Full-Stack, Development Framework
Yesterday | Today |
---|---|
Browser | Mobile |
Refresh Button | Live Update |
Individual Sessions | Multi-User Collaboration |
Links and Forms | Native Style GUI |
![]() |
![]() |
Follow Along!
curl https://install.meteor.com/ | sh
meteor create new-project-name
cd new-project
meteor
if (Meteor.isClient) {
// runs on the client
}
if (Meteor.isServer) {
// runs on the server
}
// runs on client and server
beter option ...
/client
- Runs only on the client/server
- Runs only on the server/public
- for static assets (images...)/lib
- loaded before anything elsemain.*
- loaded after everything elseCreate a collection and seed some data
Questions = new Mongo.Collection('quest');
Questions.insert(
{ text: "Seed Question?" }
);
Questions = new Mongo.Collection('quest');
What's This?
(function() {
/* ... */
})()
Immediately-Invoked Function Expression (IIFE)
MongoDB adds a "PLEASE" keyword for inserts, boosting chance that data is stored to above 75%.
— Hacker News Onion (@HackerNewsOnion)
September 24, 2013
I'll be available after the presentation to write slogans
SQL | Mongo |
---|---|
Normalized | Denormalized |
Schema-Bound | SchemaLess |
PK - any unique column(s) | PK - always set to _id |
SQL | Mongo |
---|---|
Table | Collection |
Row | Document |
Column | Field |
CREATE TABLE table_name
new Mongo.Collection('col_name');
INSERT INTO users(user_id, age, status)
VALUES ("bcd001", 45, "A")
db.users.insert({
user_id: "bcd001",
age: 45,
status: "A"
})
SELECT _id, name, address -- Projection
FROM users -- Table
WHERE age > 18 -- Criteria
LIMIT 5 -- Cursor Modifier
db.users.find( // Collection
{ age: { $gt: 18 } }, // Criteria
{ name: 1, address: 1 } // Projection
).limit(5) // Cursor Modifier
UPDATE users -- Table
SET name = 'Ed', -- Modify
rel_status = 'Single'
WHERE id = 1 -- Criteria
db.users.update( // Collection
{ id: 1 }, // Criteria
{ $set: { // Modify
name: 'Ed',
rel_status: 'Single'
}}
)
DELETE FROM users -- Table
WHERE rel_status = 'single' -- Criteria
db.users.remove( // Collection
{ rel_status: 'single' } // Criteria
)
Include Template
{{> template_name}}
Define Template
<template name="template_name">
I'm a Template!
</template>
General
Template.<name>.helpers({})
Example
Template.question_list.helpers({
questions: function() {
return Questions.find();
}
})
{{property}}
{{> template}}
{{#if}} ... {{/if}}
{{#each}} ... {{/each}}
{{#with}} ... {{/with}}
Sometimes when I'm writing Javascript I want to throw up my hands and say "this is bullshit!" but I can never remember what "this" refers to
— Ben Halpern (@bhalp1)
March 20, 2015
jQuery Example
$(template).on('event', 'selector', (e) => {
//Do Stuff
});
Spacebar Event Handling:
Template.template-name.events({
'event selector': (event, template) => {
// Do Stuff
}
})
meteor deploy app-name.meteor.com
npm install -g mup
mkdir ~/app-deploy
cd ~/app-deploy
mup init
open mup.json
mup setup
mup deploy
Install:
meteor add accounts-ui accounts-password
Usage:
{{> loginButtons}}
Spacebars Helper
{{currentUser}}
Everywhere else
var user = Meteor.user();
user._id
user.username
Write once; run everywhere
# iOS
meteor install-sdk ios
meteor add-platform ios
meteor run ios
# android
meteor install-sdk android
meteor add-platform android
meteor run android
"Meteor isn't secure"
meteor remove autopublish
Two Steps:
Publish
// on server
Meteor.publish("questions", function () {
return Questions.find();
});
Subscribe
// on client
Meteor.subscribe("questions");
Will someone open their console and run this:
Questions.remove({})
What Happened?
"Not permitted. Untrusted code may only remove documents by ID."
How about this instead?
Questions.find().forEach(function(doc) {
Questions.remove(doc._id)
});
meteor remove insecure
Two Solutions:
Allow
Posts.allow({
insert: function (userId, doc) {
// user must be logged in and modify their own doc
return (userId && doc.owner === userId);
}
});
Deny
Posts.deny({
update: function (userId, docs, fields, modifier) {
// can't change owners
return _.contains(fields, 'owner');
}
});
Add Method
Meteor.methods({
'method-name': function([params]) {
// Do Something
}
})
Call Method
Meteor.call('method-name' [, params])
Community: