Skip to content

Instantly share code, notes, and snippets.

@mattgstevens
Created October 27, 2016 19:38
Show Gist options
  • Save mattgstevens/2fa6d42fb3c1ce51e08250e62c4e2d05 to your computer and use it in GitHub Desktop.
Save mattgstevens/2fa6d42fb3c1ce51e08250e62c4e2d05 to your computer and use it in GitHub Desktop.
<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