From 48264ccafdcdfe6ff88b59ea8fc5631210d79818 Mon Sep 17 00:00:00 2001 From: David Greenspan Date: Thu, 25 Sep 2014 14:56:15 -0700 Subject: [PATCH] Use preferred helper style in docs,apps,packages --- docs/client/api.html | 24 +- docs/client/concepts.html | 28 +- docs/client/docs.js | 78 ++--- examples/leaderboard/leaderboard.js | 25 +- examples/parties/client/client.js | 142 +++++---- examples/todos/client/todos.js | 154 ++++----- examples/wordplay/client/wordplay.js | 154 ++++----- .../accounts-ui-unstyled/login_buttons.js | 61 ++-- .../login_buttons_dropdown.js | 295 +++++++++--------- .../login_buttons_single.js | 27 +- packages/autoupdate/QA.md | 2 +- packages/facebook/facebook_configure.js | 21 +- packages/facts/facts.js | 24 +- packages/github/github_configure.js | 20 +- packages/google/google_configure.js | 20 +- packages/meetup/meetup_configure.js | 20 +- .../meteor_developer_configure.js | 20 +- packages/twitter/twitter_configure.js | 20 +- packages/weibo/weibo_configure.js | 22 +- 19 files changed, 622 insertions(+), 535 deletions(-) diff --git a/docs/client/api.html b/docs/client/api.html index 71a6c262da..9743eb8151 100644 --- a/docs/client/api.html +++ b/docs/client/api.html @@ -1633,14 +1633,18 @@ Example: {{lt}}/template> ///// in JS file - Template.postsView.posts = function() { - return Posts.find(); - }; + Template.postsView.helpers({ + posts: function() { + return Posts.find(); + } + }); - Template.postItem.postClass = function() { - return Session.equals("selectedPost", this._id) ? - "selected" : ""; - }; + Template.postItem.helpers({ + postClass: function() { + return Session.equals("selectedPost", this._id) ? + "selected" : ""; + } + }); Template.postItem.events({ 'click': function() { @@ -2220,12 +2224,6 @@ Example: Now you can invoke this helper with `{{dstache}}foo}}` in the template defined with `<{{! }}template name="myTemplate">`. -The following syntax is a shorthand for when you only have one helper to define: - - Template.myTemplate.foo = function () { - return Session.get("foo"); - }; - To create a helper that can be used in any template, use [`Template.registerHelper`](#template_registerhelper). diff --git a/docs/client/concepts.html b/docs/client/concepts.html index 0ed6f0e76b..01ef117987 100644 --- a/docs/client/concepts.html +++ b/docs/client/concepts.html @@ -457,9 +457,11 @@ functions in JavaScript. Just add the helper functions directly on the {{lt}}/template> // in client/myapp.js: reactive helper function - Template.forecast.prediction = function () { - return Session.get("weather"); - }; + Template.forecast.helpers({ + prediction: function () { + return Session.get("weather"); + } + }); // in the JavaScript console > Session.set("weather", "cloudy"); @@ -481,9 +483,11 @@ To iterate over an array or database cursor, use `{{dstache}}#each}}`: {{lt}}/template> // in myapp.js - Template.players.topScorers = function () { - return Users.find({score: {$gt: 100}}, {sort: {score: -1}}); - }; + Template.players.helpers({ + topScorers: function () { + return Users.find({score: {$gt: 100}}, {sort: {score: -1}}); + } + }); In this case, the data is coming from a database query. When the database cursor is passed to `{{dstache}}#each}}`, it will wire up all of the @@ -495,9 +499,11 @@ in `this`. Note that some block helpers change the current context (notably `{{dstache}}#each}}` and `{{dstache}}#with}}`): // in a JavaScript file - Template.players.leagueIs = function (league) { - return this.league === league; - }; + Template.players.helpers({ + leagueIs: function (league) { + return this.league === league; + } + });