Created
July 17, 2014 06:57
-
-
Save alanshaw/9651a97e027e70a98180 to your computer and use it in GitHub Desktop.
Meteor London server to server DDP talk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var conn = DDP.connect("http://localhost:3000") | |
Pictures = new Meteor.Collection("pictures", conn) | |
function allow () {return true} | |
Pictures.allow({insert: allow, update: allow, remove: allow}) | |
if (Meteor.isClient) { | |
conn.subscribe("pics") | |
Template.pics.items = function () { | |
return Pictures.find({}, {sort: [["createdAt", "desc"]]}) | |
} | |
} | |
if (Meteor.isServer) { | |
Meteor.startup(function () { | |
}) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Pictures = new Meteor.Collection("pictures") | |
function allow () {return true} | |
Pictures.allow({insert: allow, update: allow, remove: allow}) | |
if (Meteor.isClient) { | |
Meteor.subscribe("pics") | |
Template.pics.items = function () { | |
return Pictures.find({}, {sort: [["createdAt", "desc"]]}) | |
} | |
} | |
if (Meteor.isServer) { | |
Meteor.startup(function () { | |
Meteor.publish("pics", function () { | |
return Pictures.find() | |
}) | |
var conn = DDP.connect("http://localhost:3000") | |
var RemotePictures = new Meteor.Collection("pictures", conn) | |
conn.subscribe("pics") | |
RemotePictures.find().observe({ | |
added: function (doc) { | |
if (!Pictures.findOne(doc._id)) { | |
Pictures.insert(doc) | |
} | |
}, | |
changed: function (doc) { | |
Pictures.update(doc._id, {$set: doc}) | |
}, | |
removed: function (doc) { | |
Pictures.remove(doc._id) | |
} | |
}) | |
}) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<head> | |
<title>index</title> | |
</head> | |
<body> | |
<h1>index</h1> | |
{{> pics}} | |
</body> | |
<template name="pics"> | |
{{#each items}} | |
<img src="{{src}}"> | |
{{/each}} | |
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Pictures = new Meteor.Collection("pictures") | |
function allow () {return true} | |
Pictures.allow({insert: allow, update: allow, remove: allow}) | |
if (Meteor.isClient) { | |
Meteor.subscribe("pics") | |
Template.pics.items = function () { | |
return Pictures.find({}, {sort: [["createdAt", "desc"]]}) | |
} | |
} | |
if (Meteor.isServer) { | |
Meteor.startup(function () { | |
Meteor.publish("pics", function () { | |
return Pictures.find() | |
}) | |
}) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
img { | |
max-width: 100px; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment