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
{ | |
"name": "project", | |
"private": true, | |
"scripts": { | |
"test": "tape 'tests/unit/**/*.js'" | |
}, | |
"devDependencies": { | |
"tape": "4.2.2" | |
} | |
} |
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
// ES6 | |
class Tweet { | |
constructor (doc) { | |
_.extend(this, doc); | |
} | |
} | |
Tweets = new Mongo.Collection('tweets', { | |
transform (doc) { | |
return new Tweet(doc); |
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
// ES6 | |
Template.lead.helpers({ | |
twitterLink () { | |
return this.getTwitterLink(); | |
}, | |
weekday (timestamp) { | |
return moment(timestamp).format(‘dddd’); | |
} | |
}); |
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
// ES6 | |
UI.registerHelper('sum', function (...summands) { | |
summands.pop(); // remove last argument hash (Spacebars.kw) | |
return summands.reduce((previousValue, currentValue) => { | |
return previousValue + currentValue; | |
}); | |
}); |
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
// ES5 | |
UI.registerHelper('sum', function (/* arguments */) { | |
var summands = Array.prototype.slice.call(arguments); | |
summands.pop(); // remove last argument hash (Spacebars.kw) | |
var sum = 0; | |
for (var i = 0; i < summands.length; i++) { | |
sum += summands[i]; | |
} | |
return sum; | |
}); |
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
// ES6 | |
const versionsMap = new Map(); | |
lines.forEach( line => versionsMap.set(...line.split(‘@’)) ); |
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
// ES6 | |
const versionsMap = new Map(); | |
lines.forEach((line) => { | |
const [name, version] = line.split(‘@’); // destructuring | |
versionsMap.set(name, version); | |
}); |
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
// ES5 | |
var versionsMap = {}; | |
lines.forEach(function (line) { | |
// split name@version into [name, version] | |
var lineContents = line.split('@'); | |
var name = lineContents[0]; | |
var version = lineContents[1]; | |
versionsMap[name] = version; | |
}); |
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
// ES6 | |
Template.stats.onCreated(function () { | |
this.autorun(() => { | |
const filter = { limit: Session.get('options.limit') }; | |
this.subscribe('tweets', filter); // same "this" as in line 3 | |
}); | |
}); |