Skip to content

Instantly share code, notes, and snippets.

@alanshaw
Created July 17, 2014 06:57
Show Gist options
  • Save alanshaw/9651a97e027e70a98180 to your computer and use it in GitHub Desktop.
Save alanshaw/9651a97e027e70a98180 to your computer and use it in GitHub Desktop.
Meteor London server to server DDP talk
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 () {
})
}
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)
}
})
})
}
<head>
<title>index</title>
</head>
<body>
<h1>index</h1>
{{> pics}}
</body>
<template name="pics">
{{#each items}}
<img src="{{src}}">
{{/each}}
</template>
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()
})
})
}
img {
max-width: 100px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment