Last active
September 30, 2016 12:18
-
-
Save Pent/5744793 to your computer and use it in GitHub Desktop.
Reactive publication/subscription using Meteor
This file contains hidden or 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
| Deps.autorun(function() { | |
| Meteor.subscribe('messages', Session.get('query')); | |
| }) |
This file contains hidden or 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.publish('messages', function(query) { | |
| return Messages.find({messagecontent: query}); | |
| }); |
This file contains hidden or 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
| <template name="yourTemplateName"> | |
| <input type="text"> | |
| <ul> | |
| {{#each messages}} | |
| <li>{{messagecontent}}</li> | |
| {{/each}} | |
| </ul> | |
| </template> |
This file contains hidden or 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
| Template.yourTemplateName.events({ | |
| //listen on input | |
| 'keyup input': function(event) { | |
| //if enter was hit | |
| if(event.type === 'keyup' && event.which === 13) { | |
| //set query as input box text | |
| Session.set('query', $(event.target).text()); | |
| } | |
| } | |
| }); | |
| Template.yourTemplateName.helpers({ | |
| messages: function() { | |
| return Messages.find({}); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment