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
Show hidden characters
{ | |
"parser": "@typescript-eslint/parser", | |
"plugins": [ | |
"@typescript-eslint", | |
"prettier" | |
], | |
"extends": [ | |
"eslint:recommended", | |
"plugin:@typescript-eslint/eslint-recommended", | |
"plugin:@typescript-eslint/recommended", |
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
async function addComment(comment) { | |
const post = await fetchPostBySlug(comment.postSlug); | |
if (!post.isCommentingEnabled) { | |
throw new Error('Commenting is disabled.'); | |
} | |
const isAllowed = await isUserAllowedToComment(post, comment.user); | |
if (!isAllowed) { |
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 addComment(comment) { | |
return fetchPostBySlug(comment.postSlug) | |
.then((post) => { | |
if (!post.isCommentingEnabled) { | |
return Promise.reject(new Error('Commenting is disabled.')); | |
} | |
return isUserAllowedToComment(post, comment.user) | |
.then((isAllowed) => ({ isAllowed, post })); | |
}).then((input) => { |
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 addComment(comment) { | |
return fetchPostBySlug(comment.postSlug).then((post) => { | |
if (!post.isCommentingEnabled) { | |
return Promise.reject(new Error('Commenting is disabled.')); | |
} | |
return isUserAllowedToComment(post, comment.user).then((isAllowed) => { | |
if (!isAllowed) { | |
return Promise.reject( | |
new Error('The user is not allowed to comment on this post.') |
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 addComment(comment, done) { | |
fetchPostBySlug(comment.postSlug, (err, post) => { | |
if (err) return done(err); | |
if (!post.isCommentingEnabled) { | |
return done(new Error('Commenting is disabled.')); | |
} | |
isUserAllowedToComment(post, comment.user, (err, isAllowed) => { | |
if (err) return done(err); |
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
{ | |
"user": "58bb380d222c2239a2b16ae9", | |
"postSlug": "is-learning-dangerous", | |
"comment": "A little learning is a dangerous thing." | |
} |
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 {tagged} = require('daggy'); | |
// const | |
const K = (a) => (b) => a; | |
// Reader Transformer | |
module.exports = (M) => { | |
const ReaderT = tagged('run'); | |
ReaderT.lift = ReaderT.prototype.lift = (m) => ReaderT(K(m)); |
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 {tagged} = require('daggy'); | |
// const | |
const K = (a) => (b) => a; | |
// Reader Transformer | |
module.exports = (M) => { | |
const ReaderT = tagged('run'); | |
ReaderT.lift = (m) => ReaderT(K(m)); |
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 short program will encrypt the user password | |
* and insert a new record into a mock database. | |
*/ | |
const Reader = require('fantasy-readers'); | |
const Future = require('fluture'); | |
const R = require('ramda'); | |
const crypto = require('crypto'); | |
// our mock database |
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 short program will encrypt the user password | |
* and insert a new record into a mock database. | |
*/ | |
const Reader = require('fantasy-readers'); | |
const R = require('ramda'); | |
const crypto = require('crypto'); | |
// our mock database | |
const database = [ |
NewerOlder