Skip to content

Commit e00e0dc

Browse files
committed
Add skeleton files.
Created package.json file ➕
1 parent 54b1f86 commit e00e0dc

File tree

1,105 files changed

+73237
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,105 files changed

+73237
-0
lines changed

dom.js

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// part 2 linking it all together
2+
// The function here is called an iife,
3+
// it keeps everything inside hidden from the rest of our application
4+
(function() {
5+
// This is the dom node where we will keep our todo
6+
var container = document.getElementById('todo-container');
7+
var addTodoForm = document.getElementById('add-todo');
8+
9+
var state = [
10+
{ id: -3, description: 'first todo' },
11+
{ id: -2, description: 'second todo' },
12+
{ id: -1, description: 'third todo' },
13+
]; // this is our initial todoList
14+
15+
// This function takes a todo, it returns the DOM node representing that todo
16+
var createTodoNode = function(todo) {
17+
var todoNode = document.createElement('li');
18+
// you will need to use addEventListener
19+
20+
// add span holding description
21+
22+
// this adds the delete button
23+
var deleteButtonNode = document.createElement('button');
24+
deleteButtonNode.addEventListener('click', function(event) {
25+
var newState = todoFunctions.deleteTodo(state, todo.id);
26+
update(newState);
27+
});
28+
todoNode.appendChild(deleteButtonNode);
29+
30+
// add markTodo button
31+
32+
// add classes for css
33+
34+
return todoNode;
35+
};
36+
37+
// bind create todo form
38+
if (addTodoForm) {
39+
addTodoForm.addEventListener('submit', function(event) {
40+
// https://developer.mozilla.org/en-US/docs/Web/Events/submit
41+
// what does event.preventDefault do?
42+
// what is inside event.target?
43+
44+
var description = '?'; // event.target ....
45+
46+
// hint: todoFunctions.addTodo
47+
var newState = []; // ?? change this!
48+
update(newState);
49+
});
50+
}
51+
52+
// you should not need to change this function
53+
var update = function(newState) {
54+
state = newState;
55+
renderState(state);
56+
};
57+
58+
// you do not need to change this function
59+
var renderState = function(state) {
60+
var todoListNode = document.createElement('ul');
61+
62+
state.forEach(function(todo) {
63+
todoListNode.appendChild(createTodoNode(todo));
64+
});
65+
66+
// you may want to add a class for css
67+
container.replaceChild(todoListNode, container.firstChild);
68+
};
69+
70+
if (container) renderState(state);
71+
})();

index.html

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
<!DOCTYPE html>
3+
<html>
4+
<head>
5+
<meta charset="utf-8">
6+
<title>tdd todo</title>
7+
<link rel="stylesheet" href="./style.css">
8+
</head>
9+
<body>
10+
<div id = "todo-container">
11+
<ul>
12+
</ul>
13+
</div>
14+
<form id="add-todo">
15+
<input type="text" name="description" value="">
16+
<input type="submit" name="" value="Submit">
17+
</form>
18+
</body>
19+
<script type="text/javascript" src = "./logic.js"></script>
20+
<script type="text/javascript" src = "./dom.js"></script>
21+
</html>

logic.js

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Part 1. Fill in any missing parts of the todoFunction object!
2+
// you can access these on todo.todoFunctions
3+
// For part one we expect you to use tdd
4+
5+
var todoFunctions = {
6+
// todoFunctions.generateId() will give you a unique id
7+
// You do not need to understand the implementation of this function.
8+
generateId: (function() {
9+
var idCounter = 0;
10+
11+
function incrementCounter() {
12+
return (idCounter += 1);
13+
}
14+
15+
return incrementCounter;
16+
})(),
17+
18+
//cloneArrayOfObjects will create a copy of the todos array
19+
//changes to the new array don't affect the original
20+
cloneArrayOfObjects: function(todos) {
21+
return todos.map(function(todo){
22+
return JSON.parse(JSON.stringify(object));
23+
});
24+
},
25+
26+
addTodo: function(todos, newTodo) {
27+
// should leave the input argument todos unchanged (you can use cloneArrayOfObjects)
28+
// returns a new array, it should contain todos with the newTodo added to the end.
29+
// add an id to the newTodo. You can use the generateId function to create an id.
30+
// hint: array.concat
31+
},
32+
deleteTodo: function(todos, idToDelete) {
33+
// should leave the input argument todos unchanged (you can use cloneArrayOfObjects)
34+
// return a new array, this should not contain any todo with an id of idToDelete
35+
// hint: array.filter
36+
},
37+
markTodo: function(todos, idToMark) {
38+
// should leave the input argument todos unchanged (you can use cloneArrayOfObjects)
39+
// in the new todo array, all elements will remain unchanged except the one with id: idToMark
40+
// this element will have its done value toggled
41+
// hint: array.map
42+
},
43+
sortTodos: function(todos, sortFunction) {
44+
// stretch goal! Do this last
45+
// should leave the input arguement todos unchanged (you can use cloneArrayOfObjects)
46+
// sortFunction will have same signature as the sort function in array.sort
47+
// hint: array.slice, array.sort
48+
},
49+
};
50+
51+
52+
// Why is this if statement necessary?
53+
// The answer has something to do with needing to run code both in the browser and in Node.js
54+
// See this article for more details:
55+
// http://www.matteoagosti.com/blog/2013/02/24/writing-javascript-modules-for-both-browser-and-node/
56+
if (typeof module !== 'undefined') {
57+
module.exports = todoFunctions;
58+
}

node_modules/.bin/tap-out

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/tap-spec

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/tape

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/tspec

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/ansi-regex/index.js

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/ansi-regex/license

+21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/ansi-regex/package.json

+109
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/ansi-regex/readme.md

+39
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)