Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// 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