All you need is Meteor
if (Meteor.isClient) {
console.log("Logging on Client");
}
if (Meteor.isServer) {
console.log("Logging on Server");
}
if (Meteor.isCordova) {
console.log("Logging on Phonegap");
}
Todos = new Mongo.Collection('todos'); // runs on both client and server
if (Meteor.isServer) {
//runs only on server
Meteor.startup(function() {
Todos.insert({body: 'Very important thing to do', done: false});
});
}
if (Meteor.isClient) {
//runs only on client
var todos = Todos.find({done: false}).forEach(function(todo) {
Todos.update({_id: todo._id}, {$set: {done: true} });
});
Package.describe({
summary: "My awesome package or a sub app, or whatever",
version: "0.0.1",
name: "username:package",
git: 'https://github.com/username/package'
});
Simple Notice Board App
client - Loaded on client only
client/compatibility - Isn't wrapped in IEFs
server - Loaded on server only
lib - Loaded first in directory
public - For static assets on client
private - For static assets on server
tests - For tests, not loaded anywhere
<template name="noticeList">
<ul>
{{#each notices}}
<li>
<span class="notice">{{body}}</span>
<span class="delete"><i class="glyphicon glyphicon-trash"></i></span>
<span class="like ">
<i class="glyphicon glyphicon-heart"></i>
<span class="like-count">{{likeCount}}</span>
</span>
</li>
{{/each}}
</ul>
</template>
Helpers - Template data providers, arbitrary methods etc
Events - Well, event handlers
Template.noticeList.helpers({
notices: function() {
return Notices.find({}, {sort: {like_count: -1}});
}
});
Template.noticeList.events({
"click .like": function(e) {
Notices.update(this._id, {$inc: {like_count: 1}});
},
"click .delete": function(e) {
Notices.remove(this._id);
}
});
Create Collection
Use it
Notices = new Mongo.Collection('notices');
Notices.find({}, {sort: {like_count: -1}});
Notices.insert({
body: e.currentTarget.value,
like_count: 0
});
Notices.update("some_id", {$inc: {like_count: 1}});
Notices.remove("some_id");
Allow / Deny callbacks for Collections
Notices.allow({
insert: function(userId, doc) {
return true;
},
update: function(userId, doc) {
return true;
},
remove: function(userId, doc) {
return true;
}
});
Control what and how much goes to Clients
Publishers / Subscribers
Meteor.publish('all_notices', function() {
return Notices.find();
});
Template.noticeList.created = function() {
Meteor.subscribe('all_notices');
};
//SIGN UP
Accounts.createUser({
email: email,
password: password
}, function(err) {
if (err) {
console.log("Creating user", err);
}
});
//LOG IN
Meteor.loginWithPassword(
email,
password,
function(err) {
if (err) {
console.log("Login:", err);
}
})
$ meteor add-platform ios
$ meteor build ios
Say Thank You DDP!
Android
iOS
Xamarin
Javascript
Others
Man behind reactivity
Synchronous (like) Development for Nodejs
Load order
Or lack of control over it
No fixed Structure for Code
Namespacing
Globals revived
Happy Hacking with Meteor :)
@bitspook