Last active
December 12, 2015 21:57
-
-
Save abhiaiyer91/b71234d0b6d88a9eaa7f 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
// 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