updating callback names to new dot notation

This commit is contained in:
Sacha Greif 2016-02-24 18:23:21 +09:00
parent 0a98c14288
commit 6b810de8fa
10 changed files with 53 additions and 46 deletions

View file

@ -142,6 +142,15 @@ Settings can be public (meaning they will be published to the client) or private
Note that packages may also rely on their own settings.
### Callbacks
Methods support four distinct callbacks
- `client` callbacks are only called on the client, before the actual method is called.
- `method` callbacks are called within the body of the method, and they run both on the client and server.
- `sync` callbacks are called in the mutator, and can run either on both client and server, *or* on the server only if the mutator is called directly.
- `async` callbacks are called in the mutator, and only run on the server in an async non-blocking way.
### Other Notes
- The `comments` package is now optional.

View file

@ -70,7 +70,7 @@ function cachePostThumbnailOnSubmit (post) {
}});
}
}
Telescope.callbacks.add("postSubmitAsync", cachePostThumbnailOnSubmit);
Telescope.callbacks.add("posts.new.async", cachePostThumbnailOnSubmit);
// post edit callback
function cachePostThumbnailOnEdit (newPost, oldPost) {
@ -84,4 +84,4 @@ function cachePostThumbnailOnEdit (newPost, oldPost) {
}});
}
}
Telescope.callbacks.add("postEditAsync", cachePostThumbnailOnEdit);
Telescope.callbacks.add("posts.edit.async", cachePostThumbnailOnEdit);

View file

@ -75,7 +75,7 @@ function addMediaAfterSubmit (post) {
}
}
}
Telescope.callbacks.add("postSubmitAsync", addMediaAfterSubmit);
Telescope.callbacks.add("posts.new.async", addMediaAfterSubmit);
function updateMediaOnEdit (modifier, post) {
var newUrl = modifier.$set.url;
@ -95,7 +95,7 @@ function updateMediaOnEdit (modifier, post) {
}
return modifier;
}
Telescope.callbacks.add("postEdit", updateMediaOnEdit);
Telescope.callbacks.add("posts.edit.sync", updateMediaOnEdit);
var regenerateThumbnail = function (post) {
delete post.thumbnailUrl;

View file

@ -85,7 +85,7 @@ Telescope.operateOnItem = function (collection, itemId, user, operation) {
item = _.extend(item, {baseScore: (item.baseScore + votePower)});
// --------------------- Server-Side Async Callbacks --------------------- //
Telescope.callbacks.runAsync(operation+"Async", item, user, collection, operation);
Telescope.callbacks.runAsync(operation+".async", item, user, collection, operation);
return true;

View file

@ -28,8 +28,11 @@ const PostNew = React.createClass({
submitForm(data) {
// remove any empty properties
data = _.compactObject(data);
Meteor.call('posts.new', data, (error, post) => {
post = _.compactObject(data);
post = Telescope.callbacks.run("posts.new.client", post);
Meteor.call('posts.new', post, (error, post) => {
if (error) {
console.log(error)
Messages.flash(error.message, "error")

View file

@ -37,17 +37,17 @@ var checkCategories = function (post) {
}
};
function postSubmitCheckCategories (post) {
function postsNewCheckCategories (post) {
checkCategories(post);
return post;
}
Telescope.callbacks.add("postSubmit", postSubmitCheckCategories);
Telescope.callbacks.add("posts.new.sync", postsNewCheckCategories);
function postEditCheckCategories (post) {
checkCategories(post);
return post;
}
Telescope.callbacks.add("postEdit", postEditCheckCategories);
Telescope.callbacks.add("posts.edit.sync", postEditCheckCategories);
// TODO: debug this
@ -64,7 +64,7 @@ Telescope.callbacks.add("postEdit", postEditCheckCategories);
// post.categories = _.unique(newCategories);
// return post;
// }
// Telescope.callbacks.add("postSubmit", addParentCategoriesOnSubmit);
// Telescope.callbacks.add("posts.new.sync", addParentCategoriesOnSubmit);
// function addParentCategoriesOnEdit (modifier, post) {
// if (modifier.$unset && modifier.$unset.categories !== undefined) {
@ -83,4 +83,4 @@ Telescope.callbacks.add("postEdit", postEditCheckCategories);
// modifier.$set.categories = _.unique(newCategories);
// return modifier;
// }
// Telescope.callbacks.add("postEdit", addParentCategoriesOnEdit);
// Telescope.callbacks.add("posts.edit.sync", addParentCategoriesOnEdit);

View file

@ -46,7 +46,7 @@ function afterCommentOperations (comment) {
return comment;
}
Telescope.callbacks.add("commentSubmitAsync", afterCommentOperations);
Telescope.callbacks.add("comments.new.sync", afterCommentOperations);
// ------------------------------------- Votes -------------------------------- //
@ -61,7 +61,7 @@ if (typeof Telescope.operateOnItem !== "undefined") {
return comment;
}
Telescope.callbacks.add("commentSubmitAsync", upvoteOwnComment);
Telescope.callbacks.add("comments.new.sync", upvoteOwnComment);
}
// ------------------------------------- Notifications -------------------------------- //

View file

@ -12,10 +12,10 @@ var modifyKarma = function (userId, karma) {
function updateScore (item, user, collection, operation) {
Telescope.updateScore({collection: collection, item: item, forceUpdate: true});
}
Telescope.callbacks.add("upvoteAsync", updateScore);
Telescope.callbacks.add("downvoteAsync", updateScore);
Telescope.callbacks.add("cancelUpvoteAsync", updateScore);
Telescope.callbacks.add("cancelDownvoteAsync", updateScore);
Telescope.callbacks.add("upvote.async", updateScore);
Telescope.callbacks.add("downvote.async", updateScore);
Telescope.callbacks.add("cancelUpvote.async", updateScore);
Telescope.callbacks.add("cancelDownvote.async", updateScore);
/**
* Update the profile of the user doing the operation
@ -52,10 +52,10 @@ function updateUser (item, user, collection, operation) {
Meteor.users.update({_id: user._id}, update);
}
Telescope.callbacks.add("upvoteAsync", updateUser);
Telescope.callbacks.add("downvoteAsync", updateUser);
Telescope.callbacks.add("cancelUpvoteAsync", updateUser);
Telescope.callbacks.add("cancelDownvoteAsync", updateUser);
Telescope.callbacks.add("upvote.async", updateUser);
Telescope.callbacks.add("downvote.async", updateUser);
Telescope.callbacks.add("cancelUpvote.async", updateUser);
Telescope.callbacks.add("cancelDownvote.async", updateUser);
/**
* Update the karma of the item's owner
@ -75,7 +75,7 @@ function updateKarma (item, user, collection, operation) {
}
}
Telescope.callbacks.add("upvoteAsync", updateKarma);
Telescope.callbacks.add("downvoteAsync", updateKarma);
Telescope.callbacks.add("cancelUpvoteAsync", updateKarma);
Telescope.callbacks.add("cancelDownvoteAsync", updateKarma);
Telescope.callbacks.add("upvote.async", updateKarma);
Telescope.callbacks.add("downvote.async", updateKarma);
Telescope.callbacks.add("cancelUpvote.async", updateKarma);
Telescope.callbacks.add("cancelDownvote.async", updateKarma);

View file

@ -8,26 +8,21 @@ FlowRouter.extendPathWithQueryParams = (path, params, newQueryParams) => {
FlowRouter.triggers.exit([() => Messages.clearSeen()]);
// FlowRouter.addToQueryArray = function (key, value) {
// var keyArray = FlowRouter.getQueryParam(key) || [];
// keyArray.push(value);
// var params = {};
// params[key] = keyArray;
// FlowRouter.setQueryParams(params);
// }
FlowRouter.addToQueryArray = function (key, value) {
var keyArray = FlowRouter.getQueryParam(key) || [];
keyArray.push(value);
var params = {};
params[key] = keyArray;
FlowRouter.setQueryParams(params);
}
// FlowRouter.removeFromQueryArray = function (key, value) {
// var keyArray = FlowRouter.getQueryParam(key);
// keyArray = _.without(keyArray, value);
// var params = {};
// params[key] = keyArray;
// FlowRouter.setQueryParams(params);
// }
// Telescope.adminRoutes = FlowRouter.group({
// prefix: '/admin',
// name: 'admin'
// });
FlowRouter.removeFromQueryArray = function (key, value) {
var keyArray = FlowRouter.getQueryParam(key);
keyArray = _.without(keyArray, value);
var params = {};
params[key] = keyArray;
FlowRouter.setQueryParams(params);
}
// FlowRouter.notFound = {
// action: function() {

View file

@ -29,7 +29,7 @@ AutoForm.hooks({
// ------------------------------ Callbacks ------------------------------ //
// run all post submit client callbacks on properties object successively
post = Telescope.callbacks.run("postSubmitClient", post);
post = Telescope.callbacks.run("posts.new.client", post);
return post;
}