Created
October 27, 2016 19:38
-
-
Save mattgstevens/2fa6d42fb3c1ce51e08250e62c4e2d05 to your computer and use it in GitHub Desktop.
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
<html> | |
<body> | |
<script> | |
document.addEventListener('click', function(event) { | |
console.log('doucment', event); | |
}) | |
const ReduxLibrary = (function() { | |
//magic and ponies goes here | |
return { | |
updateStore, | |
subscribe, | |
} | |
}) | |
const UserStore = (function() { | |
const store = []; | |
// i/o for users goes here... | |
return { | |
getUsers: function () { return store; } | |
} | |
}()); | |
const TodoStore = (function () { | |
const store = []; | |
let nextId = 0; | |
function performAction (command, data) { | |
switch (command) { | |
case('ADD_TODO'): store.push(nextId++); break; | |
case('REMOVE_TODO'): store.splice(store.indexOf(data.id), 1); break; | |
default: console.log('I dont know that trick'); | |
} | |
render(); | |
} | |
// event handlers | |
function addTodo(event) { | |
console.log(event); | |
performAction('ADD_TODO'); | |
} | |
function removeTodo(event) { | |
performAction('REMOVE_TODO', { id: event.target.id }); | |
render(); | |
} | |
// Component | |
function render() { | |
document.getElementById('count').innerHTML = store.join(' '); | |
} | |
return { | |
removeTodo, | |
addTodo, | |
}; | |
}()); | |
</script> | |
<div onclick=TodoStore.addTodo(event)>Click me</div> | |
<div id='count'> | |
</div> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment