Skip to content

Instantly share code, notes, and snippets.

@abhiaiyer91
Last active December 12, 2015 21:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abhiaiyer91/8b6a0d285d73940e9041 to your computer and use it in GitHub Desktop.
Save abhiaiyer91/8b6a0d285d73940e9041 to your computer and use it in GitHub Desktop.
// Lets say we have some view called CommentSubmitComponent
// This view will make many things happen. Its job is to send off
// actions from the view and process something.
// Lets make an Action Creator
let CommentSubmitActions = new ZenAction();
// So yeah yeah this is just a plain object at this point. But even so, you have a
// logical place to attach functionality
_.extend(CommentSubmitActions, {
fetchData(collection, query, options) {
// Do something here
},
submitComment(options, cb) {
return Meteor.call('submitComment', options, cb);
},
manipulateDOM(template) {
// manipulate some dom
$(template.find('.some-selector')).animate({right: -20px});
}
changeTemplateState(reactiveVar, update) {
var currentVal = reactiveVar.get();
if (!_.isEmpty(currentVal)) {
reactiveVar.set(update);
}
}
});
// So now I have a bunch of functions that take some params and do some actions.
Template.CommentSubmitComponent.events({
'click .button-red': function (event, template) {
// change some state
CommentSubmitActions.changeTemplateState(template.followers, template.data.newFollowers);
CommentSubmitActions.manipulateDOM(template);
CommentSubmitActions.submitComment(template.data.commentData, commentCallback);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment