meteor Flashcards
meteor: To run your app on localhost, type
cd into it and type meteor
meteor: To create a new app, type
meteor create my_app
meteor: To render code into your html, type
{{myVar}}
meteor: To create a for loop in a template, type
{{#each items}}
{{> item}}
{{/each}}
meteor: To run code only on client, type it into
if (Meteor.isClient) {
}
meteor: meteor parses your template to find
head, body and template
meteor: templates can be rendered in HTML by typing
{{> templateName}}
meteor: To create an if statement in a template, type
{{#if}}
meteor: To pass data into templates from your JavaScript code, type
if (Meteor.isClient) { Template.body.helpers({ myCollection: [ { field: "String" }, { field: "String" }, ] }); }
meteor: To create a template, type
-template name=”templateName”>
…
-/template>
meteor: To create a database collection, type
MyCollection = new Mongo.Collection(“my-collection”);
note: remember new
meteor: To pass data into a template from a database query as a helper, type
Template.body.helpers({ getCollection: function () { return MyCollection.find({}); } })
meteor: Items inside collections are called
documents
meteor: To access the mongo console from the terminal, type
meteor mongo
meteor: To insert a document into a collection inside the mongo console, type
db.collectionName.insert({ field1: “string”, createdAt: new Date });
meteor: To listen to and handle an event in a template, type
Template.templateName.events({
“click .css-class”: function(event, template_instance)} {
event.preventDefault();
})
meteor: To access the value of an input field from a form submit event, type
event.target.fieldName.value
meteor: To clear the value of an input field from a form submit event, type
event.target.fieldName.value = “”;
meteor: To sort the data going into a template, type
MyCollection.find({}, {sort: {field1: -1}});
meteor: In a collection, every inserted document has a unique
_id
meteor: To access the _id of the event currently being handled, type
this._id
meteor: The update function on a collection takes
two arguments
meteor: To update a field of a document, type
MyCollection.update({field1: “value”}, {
$set: {field: “value”}
});
meteor: To delete a document, type
“click .css-class”: function () {
MyCollection.remove(this._id);
}
meteor: To build and run your app for ios, type
meteor add-platform ios
meteor: To run your app in ios simulator, type
meteor run ios
meteor: To run and run your app in ios simulator, type
meteor run android
meteor: To build and run your app for ios, type
meteor add-platform android
meteor: To run your app on an ios device, type
meteor run ios-device
meteor: To run your app on an ios device while connected to a previously deployed server, type
meteor run ios-device –mobile-server my_app.meteor.com
meteor: to store temporary reactive state on the client use a
Session
meteor: Some listenable events are
change, click, submit, keypress, input
meteor: To pass is a var that in a count of all of the documents in a collection, type
documentCount: function () {
return MyCollection.find({}).count();
}
meteor: To enable user accounts and login ui, type
meteor add accounts-ui accounts-password
meteor: To access the id of a logged in user in app.js, type
Meteor.userId()
meteor: To access the username of a logged in user, type
Meteor.user().username
meteor: To display something in the view only if a user is logged in, type
{{#if currentUser}}
…
{{/if}}
meteor: To revoke client side permission to edit mongo, type
meteor remove insecure
meteor: To create a method for securely editting mongo, type
Meteor.methods({ insertMethod: function (text) { if (! Meteor.userId()) { throw new Meteor.Error("not-authorized"); } MyCollection.insert({ field: text, createdAt: new Date(), owner: Meteor.userId(), username: Meteor.user().username }); }, deleteMethod: function (Id) { MyCollection.remove(Id); }, setMethod: function (Id, set) { MyCollection.update(Id, { $set: { field1: set} }); } });
meteor: adding properties and methods to Template.body.helpers({}) seems to
pass the body that data across all templates.
meteor: To set the value of a variable that is currently available in just the client and not the server, type
Session.set(‘varName’, ‘value’)
meteor: To return the value of a session variable, type
Session.get(‘varName’)
meteor: To set a default value for a session variable, type
Session.setDefault(‘varName’, ‘value’);
meteor: To add url routing, type into terminal
meteor add iron:router
meteor: the “items” in {{#each items}} is
the name of a function that returns an array
meteor: To render something from an {{#each items}} block if the function returns empty, type
{{#each items}}
{{else}}
{{/each}}
meteor: You can place functions that are callable from a template, and that return query data in
Template.templateName.helpers({})
meteor: CollectionName.find({}) returns a
cursor
meteor: Making the data available to the template using a cursor makes the ui
reactive
meteor: To create a mongo collection that is only on the browser you must
instantiate the mongo collection inside if (Meteor.isClient) {}
meteor: To search for atmosphere packages in the terminal type
meteor search package_name
meteor: To add a package, type
meteor add author:package_name
meteor: To see the installed packages, type
meteor list
meteor: To pass a {{var}} in a template as a param to a helper function, type
{{functionName item}}
meteor: A data context is
the data being passed into a part of the view
meteor: The data context can be accessed from javascript using
this.field_name
meteor: Packages that you install
do not need to be imported anywhere, they become available everywhere
websockets uses
DDP
DDP stands for
Distributed Data Protocol
meteor: To subscribe to a collection, type
Meteor.subscribe(“subscriptionName”)
note: Must match the name defined in publish function
meteor: To query the database after autopublish is removed, you must
Publish that data using a cursor in if (Meter.isServer) {} and subscribe to that data in if (Meter.isClient) {}
meteor: To create a cursor that publishes data from the server without autopublish, type
Meteor.publish(“subscriptionName”, function() {
return CollectionName.find({});
})
note: The subscriptionName can be anything, but the subscription function has to use the same name
meteor: To unsubscribe from a collection connection, type
subscriptionName.stop()
mongo: To list all your collections from the mongo shell, type
show collections
mongo: To return all the documents of a collection in a pretty way, type
db.collectionName.find().pretty()
mongo: To insert a new document into a collection from within the mongo shell, type
db.collectionName.insert({field1: “value”, field2: “value”})
meteor: To clear a form, type
var form = template_instance.find("form") form.reset();
meteor: The messages the server sends to the client are
added
removed
changed
meteor: To manually send an added message to the client, add
this.added(“collectionName”, “id”, {“field1”:”value”})
to the publish function
meteor: To manually send a ready message to the client, add
this.ready()
to the publish function