Skip to content

Instantly share code, notes, and snippets.

@abhiaiyer91
Last active December 12, 2015 21:57
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/b71234d0b6d88a9eaa7f to your computer and use it in GitHub Desktop.
Save abhiaiyer91/b71234d0b6d88a9eaa7f to your computer and use it in GitHub Desktop.
// register this group of functions with the ActionMixins
ZenMixins.registerMixin('CommentActions', {
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);
}
}
});
// WHEN YOU INSTANTIATE THE ACTION SEE BELOW
// The ZenActions takes a string array of mixin names.
// this will bind these methods to the objects prototype and you're good to go.
// Template 1 CommentSubmitComponent
Template.CommentSubmitComponent.onCreated(function () {
var template = this;
// now this template has access to all the comment actions,
// and is bound to the template.
template.actionCreator = new ZenAction(['CommentActions']);
});
// Template 2 CommentComponent
Template.CommentComponent.onCreated(function () {
var template = this;
// now this template has access to all the comment actions,
// and is bound to the template.
template.actionCreator = new ZenAction(['CommentActions']);
});
// SHARED ACTIONS BETWEEN TEMPLATES
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment