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
Photos = {} | |
class Photos.App | |
constructor: -> | |
@gui = new Photos.Gui($("#photos-list")) | |
@backend = new Photos.Backend() | |
start: => | |
@backend.fetchPhotos() | |
.done( |
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 asyncOnce(promiseFn) { | |
let data = null; | |
let promise = null; | |
return function returnOnce(...args) { | |
if (!promise) { | |
promise = promiseFn(...args).then((promiseReturn) => { data = promiseReturn; }) | |
} | |
return data; |
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
// Here are objects that provides use case and ports: | |
import ProcessingCustomerCart from "./ProcessingCustomerCart"; | |
import RequestingCustomerCare from "./RequestingCustomerCare"; | |
// Adapters: | |
import ProductsListUI from "./ProductsListUI"; | |
import AppRouter from "./AppRouter"; | |
import ErrorsUI from "./ErrorsUI"; | |
import CartBackend from "./CartBackend"; | |
import CustomerCareBackend from "./CustomerCareBackend" |
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 ProcessingCustomerPorts = (useCase, userInterface, router, eventBus, errorHandler) => { | |
// inbound messages - here event bus approach is used. | |
eventBus.on('addItemToCart', item => { | |
useCase.addItemToCart(item); | |
}); | |
eventBus.on('cartLoaded', items => { | |
items.forEach(item => { | |
useCase.addItemToCart(item); | |
}); |
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 MAX_TOTAL_ITEMS_IN_CART = 10; | |
const ProcessingCustomerCart = ports => { | |
let cartItems = []; | |
return { | |
addItemToCart(item) { | |
const cartItemsWithAddedItem = cartItems.concat([item]); | |
if (MAX_TOTAL_ITEMS_IN_CART < cartItemsWithAddedItem.length) { | |
ports.cartErrorHappened("Too many items in cart. Please proceed to checkout."); |
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
// ...snip | |
pub enum ClaimResult<'a> { | |
Claimed(&'a SpawnClaim), | |
ClaimedAlready(&'a SpawnClaim), | |
UnknownSpawn, | |
} | |
// ...snip | |
impl ClaimList { | |
// ...snip |
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
for(var x = 1; x < 20; ++x) { | |
var label = ''; | |
if (x % 3 === 0) { label += 'Julia'; } | |
if (x % 5 === 0) { label += 'James'; } | |
console.log(label.length > 0 ? label : x); | |
} |
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
pub enum Command<'a> { | |
ClaimSpawn { spawn_name: &'a str, message: Message }, | |
ClaimedList { message: Message }, | |
EstablishState { server_id: ServerId }, | |
Unknown, | |
} | |
impl<'a> Command<'a> { | |
fn from_message(message: Message) -> Self { | |
let content = message.content.trim(); |
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
struct TreeNode<T> | |
where T: Ord | |
{ | |
value: T, | |
left: Option<Box<TreeNode<T>>>, | |
right: Option<Box<TreeNode<T>>>, | |
} | |
impl TreeNode<T> |
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 reduceCompose = (f, g) => x => g(x, f(x)) | |
const reduceComposeArr = (...fns) => fns.reduce(reduceCompose, (x, y) => y) | |
const isNumber = (x, errors = {}) => Number.isNaN(parseInt(x, 10)) ? Object.assign({}, errors, { number: true }) : errors; | |
undefined | |
const length = (z) => (x, errors = {}) => (x && x.length < z) ? Object.assign({}, errors, { length: true }) : errors; | |
const presence = (x, errors = {}) => x === undefined ? Object.assign({}, errors, { presence: true }) : errors; | |
reduceComposeArr(presence, length(3), isNumber)('123') |
NewerOlder