Last active
December 12, 2015 21:58
-
-
Save abhiaiyer91/8b6a0d285d73940e9041 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
// 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