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 orm from 'my_favorite_database_library' | |
export const models = { | |
user: orm.define({ | |
id: orm.PRIMARY_KEY, | |
email: orm.STRING(255) | |
}) | |
} |
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 { models } from './models' | |
export const controllers = { | |
user: { | |
get({ email }) { | |
return models.user.get({ | |
where: { | |
}, | |
limit: 1 |
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 { controllers } from './controllers' | |
export const routes = { | |
user: { | |
async get(request, response) { | |
response.json(await controllers.user.get(request.query)) | |
} | |
} | |
} |
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 express from 'express' | |
import { routes } from './routes' | |
const server = express() | |
/** | |
* Implement routes | |
* | |
* server.get('/user', routes.user.get) |
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
// not extensible | |
function getUser() { | |
return { | |
name: 'Justin', | |
email: 'justinfuller@email.com' | |
} | |
} | |
// Extensible |
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
/* json.js */ | |
export default function ({ readFileAsync, writeFileAsync }) { | |
return { | |
readJsonFile(fileName) { | |
return readFileAsync(`${fileName}.json`).then(JSON.parse) | |
}, | |
writeJsonFile(filePath, fileContent) { | |
return writeFileAsync(filePath, JSON.stringify(fileContent)) | |
} |
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
interface ComponentLifecycle { | |
constructor(props: Object); | |
componentDidMount?(): void; | |
shouldComponentUpdate?(nextProps: Object, nextState: Object, nextContext: any): boolean; | |
componentWillUnmount?(): void; | |
componentDidCatch?(error: Error, errorInfo: ErrorInfo): void; | |
setState( | |
state: ((prevState: Object, props: Object) => Object, | |
callback?: () => void | |
): void; |
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
/* This is my file I'll be testing foo.js */ | |
export default function ({ readFileAsync }) { | |
return { | |
readJsonFile (filePath) { | |
return readFileAsync(filePath).then(JSON.parse) | |
} | |
} | |
} |
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
/* This is my file I'll be testing foo.js */ | |
import fs from 'fs' | |
import { promisify } from 'util' | |
const readFileAsync = promisify(fs.readFile) | |
export function readJsonFile (filePath) { | |
return readFileAsync(filePath).then(JSON.parse) | |
} |
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
/** | |
* Normally you might do: | |
* import fs from 'fs-extra-promise' | |
* but here we will allow the user of this file to provide the fs module | |
*/ | |
export default function ({ fs }) { | |
return function(fileName) { | |
return fs.readFileAsync(fileName, 'utf8') | |
} | |
} |
NewerOlder