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
// From https://github.com/MostlyAdequate/mostly-adequate-guide/blob/master/ch5.md#pointfree | |
// Not point-free because we mention the data: name | |
let initials = (name) => name.split(' ').map(compose(toUpperCase, head)).join('. '); | |
// Point-free style | |
let initials = compose( | |
join('. '), | |
map(compose(toUpperCase, head)), | |
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
function addOnClickTests ( context ) { | |
let model, view, behavior, options; | |
beforeEach( () => { | |
model = new context.ModelClass(); | |
view = new context.ViewClass( { model: model } ); | |
// Retrieve instantiated behavior and its actual options under this context. | |
behavior = _.findWhere( view._behaviors, { id: "addOnClick" } ); |
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
describe( "Like View", () => { | |
const View = LikeView.extend( { template: _.template( "" ) } ); | |
describe( "AddOnClick Behavior", () => { | |
addOnClickTests( { ViewClass: View, ModelClass: LikeModel } ); | |
} ); |
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
function addOnClickTests ( context ) { | |
let model, view; | |
beforeEach( () => { | |
model = new context.ModelClass(); | |
view = new context.ViewClass( { model: model } ); | |
} ); | |
it( "should increase the model size by 1 when we click on the view", () => { |
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
describe( "Alert Behavior", () => { | |
let view; | |
beforeEach( () => { | |
view = Marionette.ItemView.extend( { | |
template: _.template( "" ), | |
behaviors: { |
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
const ShareView = Marionette.ItemView.extend( { | |
template: "#card", | |
behaviors: { | |
AlertOnShare: { | |
behaviorClass: AlertBehavior, | |
title: "Shared", | |
message: "Your message has been shared!" | |
} |
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
module.exports = ( plop ) => { | |
// We declare a new generator called "module" | |
plop.setGenerator( "module", { | |
// Succintly describes what generator does. | |
description: "Create a new module", | |
// Get inputs from the user. | |
// That's Inquirer.js doing the job behind the hood. |
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
import {trimRight, isEmpty} from "lodash"; | |
const ensurePlural = ( text ) => trimRight( text, "s" ) + "s"; | |
const isNotEmptyFor = ( name ) => { | |
return ( value ) => { | |
if ( isEmpty( value ) ) return name + " is required"; | |
return true; | |
} | |
} |
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
const modulePath = "app/modules/{{camelCase name}}.js"; | |
module.exports = ( plop ) => { | |
plop.setGenerator( "model", { | |
// … | |
actions: [ | |
// Add a new model + tests boilerplate. |
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
/** | |
* TODO - Describe what your model does. | |
* | |
* @class {{pascalCase name}}.Model | |
* @module {{pascalCase name}} | |
* @constructor | |
*/ | |
import {Model} from "backbone"; | |
export default Model.extend( { |