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 fetchPosts (subreddit) { | |
return dispatch => { | |
dispatch(requestPosts(subreddit)) | |
return fetch('http://www.reddit.com/r/${subreddit}.json') | |
.then(response => response.json()) | |
.then(json => dispatch(receivePosts(subreddit, json))) | |
} | |
} |
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 MoverInputType = new GraphQLInputObjectType(MoverType); | |
const Mutation = new GraphQLObjectType({ | |
name: 'Mutation', | |
description: 'methods to create mover', | |
fields: () => { | |
return { | |
addMover: { | |
type: MoverType, | |
args: { |
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
'use strict'; | |
const R = require('ramda'); | |
const activityDetails = [ | |
{ | |
id: '395478', | |
title: 'Unique Warner Bros. Studio Tour London – The Making of Harry Potter', | |
imageUrl: '//a.travel-assets.com/lxweb/media-vault/395478_m.jpeg?v=102150', | |
largeImageURL: '//a.travel-assets.com/lxweb/media-vault/395478_l.jpeg?v=102150', | |
fromPrice: '$151', |
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 updateRecords (id, prop, value) { | |
if (prop === 'artist') { | |
collection[id][prop] = value | |
if (value === '') { | |
delete collection[id][prop] | |
} | |
} | |
else if (prop === 'tracks') { |
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 person = { | |
name: 'ken', | |
favoriteFood: [] | |
} |
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 favoriteFood (food) { | |
person.favoriteFood.push(food) | |
} | |
favoriteFood('ramen') | |
// { name: 'ken', favoriteFood: [ 'ramen' ] } |
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
/* | |
You can use any testing suite and assertion library you want. | |
I test with mocha & chai | |
*/ | |
const person = { | |
name: 'ken', | |
favoriteFood: [] | |
} | |
function favoriteFood (food) { |
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 reducer (state = person, action) { | |
switch (action.type) { | |
case 'ADD_FOOD': | |
return Object.assign({}, state, { | |
favoriteFood: state.favoriteFood.concat(action.data.food) | |
}) | |
} | |
} |
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 person = { | |
name: 'ken', | |
favoriteFood: [] | |
} | |
/* | |
It's the same reducer function from above, I just extracted the operation for | |
'ADD_FOOD', turned into a function and named it addFood. | |
*/ | |
function addFood (state, action) { |
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 person = { | |
name: 'ken', | |
favoriteFood: [] | |
} | |
function addFood (state, action) { | |
return Object.assign({}, state, { | |
favorite: state.favoriteFood.concat(action.data.food) | |
}) | |
} |
OlderNewer