Skip to content

Instantly share code, notes, and snippets.

@gemmadlou
Created November 23, 2017 07:31
Show Gist options
  • Select an option

  • Save gemmadlou/85a2084a39b22f1a9400cedd388dc57d to your computer and use it in GitHub Desktop.

Select an option

Save gemmadlou/85a2084a39b22f1a9400cedd388dc57d to your computer and use it in GitHub Desktop.
Funny
console.clear()
let state = {
todos: []
}
let box = data => ({
map: fun => box(fun(data)),
fold: fun => fun(data),
val: data
})
let getposts = (time) => new Promise((resolve, reject) => {
setTimeout(() => {
resolve(box(['abc']))
}, time || 3000)
})
let addTodos = (state, data) => {
let clone = Object.assign({}, state);
clone.todos = clone.todos.concat(data.val);
return ['todoAdded', clone];
}
let todoView = (state) => {
return state.todos
.map(todo => '<li>' + todo + '</li>').join('')
}
let apply = ([event, newstate]) => {
let actions = {
todoAdded: () => {
let view = todoView(newstate)
document.querySelector('.todos').innerHTML = view
}
}
state = newstate;
actions[event]()
}
getposts()
.then(data => apply(addTodos(state, data)))
getposts(5000)
.then(data => apply(addTodos(state, data)))
@kingmad998

Copy link
Copy Markdown

It’s meant more as a joke or light-hearted coding fun than serious utility. It’s a good example of how developers sometimes write quirky scripts just to make others smile or poke fun at common patterns in code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment