Created
February 16, 2014 15:11
-
-
Save yeputons/9035816 to your computer and use it in GitHub Desktop.
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>publish-test</title> | |
</head> | |
<body> | |
{{> hello}} | |
</body> | |
<template name="hello"> | |
<p>Elements of A: (<a href="#" class="subscr">Subscribe</a>, <a href="#" class="unsubscr">Unsubscribe</a>)</p> | |
<ul> | |
{{#each a}} | |
<li>{{_id}}. XXX={{xxx}}. B = {{bId}}. <input class="newb" value="{{bId}}" id="bId-{{_id}}"/> <a href="#" class="updb">Update</a></li> | |
{{/each}} | |
</ul> | |
<p>Elements of B:</p> | |
<ul> | |
{{#each b}} | |
<li>{{_id}}</li> | |
{{/each}} | |
</ul> | |
</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
A = new Meteor.Collection('a'); | |
B = new Meteor.Collection('B'); | |
if (Meteor.isClient) { | |
Meteor.subscribe('Bs'); | |
Template.hello.helpers({ | |
a: function() { return A.find(); }, | |
b: function() { return B.find(); } | |
}); | |
var aSubscr; | |
Template.hello.events({ | |
'click .updb': function(e, instance) { | |
A.update(this._id, {$set: {bId: instance.find("#bId-" + this._id).value}}); | |
}, | |
'click .subscr': function() { | |
if (aSubscr) return; | |
aSubscr = Meteor.subscribe('As'); | |
}, | |
'click .unsubscr': function() { | |
if (aSubscr) { | |
aSubscr.stop(); | |
aSubscr = undefined; | |
} | |
} | |
}); | |
} | |
if (Meteor.isServer) { | |
Meteor.publish('Bs', function() { | |
return Meteor.publishWithRelations({ | |
handle: this, | |
collection: B, | |
filter: {}, | |
mappings: [ | |
{ | |
reverse: true, | |
key: 'bId', | |
collection: A, | |
} | |
] | |
}); | |
}); | |
Meteor.publish('As', function() { | |
return A.find(); | |
}); | |
if (!A.find().count() && !B.find().count()) { | |
var id = B.insert({}); | |
A.insert({bId: id}); | |
A.insert({bId: id}); | |
A.insert({bId: 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
{ | |
"packages": { | |
"publish-with-relations": {} | |
} | |
} |
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
{ | |
"meteor": {}, | |
"dependencies": { | |
"basePackages": { | |
"publish-with-relations": {} | |
}, | |
"packages": { | |
"publish-with-relations": { | |
"git": "https://github.com/erundook/meteor-publish-with-relations.git", | |
"tag": "v0.1.5", | |
"commit": "98213e9f056b139597c99fb9ec2884ae6be76d91" | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment