Skip to content

Commit a47b24c

Browse files
committed
[WiP] add outline of Acceptance Criteria for Editing a Todo List Item for #60 ... putting this "on hold" to focus on nelsonic/nelsonic.github.io#511 for the next 36h
1 parent b277b6c commit a47b24c

File tree

3 files changed

+122
-2
lines changed

3 files changed

+122
-2
lines changed

Diff for: examples/counter-basic/index.html

+18
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,23 @@
9494
</script>
9595
<script src="../counter-basic-test/test.js"></script> <!-- load test.js last -->
9696

97+
<div onclick="doubleclick(this, function(){alert('single')}, function(){alert('double')})">click me</div>
98+
<script>
99+
function doubleclick(el, onsingle, ondouble) {
100+
if (el.getAttribute("data-dblclick") == null) {
101+
el.setAttribute("data-dblclick", 1);
102+
setTimeout(function () {
103+
if (el.getAttribute("data-dblclick") == 1) {
104+
onsingle();
105+
}
106+
el.removeAttribute("data-dblclick");
107+
}, 300);
108+
} else {
109+
el.removeAttribute("data-dblclick");
110+
ondouble();
111+
}
112+
}
113+
</script>
114+
97115
</body>
98116
</html>

Diff for: test/todo-app.test.js

+20-1
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ test('3. Mark all as completed ("TOGGLE_ALL")', function (t) {
307307
t.end();
308308
});
309309

310-
test.only('4. Item: should allow me to mark items as complete', function (t) {
310+
test('4. Item, should allow me to mark items as complete', function (t) {
311311
elmish.empty(document.getElementById(id));
312312
localStorage.removeItem('elmish_' + id);
313313
const model = {
@@ -336,3 +336,22 @@ test.only('4. Item: should allow me to mark items as complete', function (t) {
336336
'Item should allow me to un-mark items as complete');
337337
t.end();
338338
});
339+
340+
test.skip('4.1 Item, should allow me to edit an item ("EDIT")' , function (t) {
341+
elmish.empty(document.getElementById(id));
342+
localStorage.removeItem('elmish_' + id);
343+
const model = {
344+
todos: [
345+
{ id: 0, title: "Make something people want.", done: false }
346+
],
347+
hash: '#/' // the "route" to display
348+
};
349+
// render the view and append it to the DOM inside the `test-app` node:
350+
elmish.mount(model, app.update, app.view, id, app.subscriptions);
351+
const item = document.getElementById('0')
352+
t.equal(item.textContent, model.todos[0].title, 'Item contained in model.');
353+
// confirm that the todo item is NOT done (done=false):
354+
355+
356+
t.end();
357+
});

Diff for: todo-list.md

+84-1
Original file line numberDiff line numberDiff line change
@@ -1640,7 +1640,7 @@ sample code:
16401640
[**`examples/todo-list/todo-app.js`**](https://github.com/dwyl/learn-elm-architecture-in-javascript/pull/45/files#diff-6be3e16fe7cfb4c00788d4d587374afdR46)
16411641

16421642

1643-
### 4. Item
1643+
### 4. Item (Toggle, Edit & Delete)
16441644

16451645
```
16461646
4. Item
@@ -1693,12 +1693,95 @@ in order to make this test pass; just run it and move on.
16931693

16941694

16951695

1696+
16961697
#### 4.2 `EDIT` an Item
16971698

16981699
```
16991700
should allow me to edit an item
17001701
```
17011702

1703+
Editing a Todo List item is (_by far_)
1704+
the most "complex" functionality in the TodoMVC app
1705+
because it involves multiple steps and "dynamic UI".
1706+
1707+
1708+
1709+
+ [ ] Double-click on Item **`<label>title</label>`** to begin editing.
1710+
+ [ ] Render an **`<input class="edit">`** if in "**editing _mode_**"
1711+
(_see screenshot and markup below_)
1712+
+ [ ] Add `case` in `keyup` Event Listener for **`[Enter]`** keyup
1713+
(_see **`subscriptions`** above_) if we are in "**editing _mode_**",
1714+
get the text value from the **`<input class="edit">`**
1715+
_instead_ of **`<input id="new-todo">`**
1716+
so that we _update_ the _existing_ Todo Item title (text).
1717+
+ [ ] When **`[Enter]`** is pressed while in "**editing _mode_**",
1718+
Dispatch the **`END_EDIT`** action: `signal('END_EDIT')`
1719+
1720+
![todo-edit-html](https://user-images.githubusercontent.com/194400/43995210-f4f484e0-9da1-11e8-8cc5-09f7309db963.png)
1721+
1722+
Here is the _sample_ HTML in "**editing _mode_**"
1723+
(_copy-pasted_) from the VanillaJS TodoMVC implementation
1724+
the _second_ **`<li>`** is the one being edited (_as per screenshot above_):
1725+
```HTML
1726+
<ul class="todo-list">
1727+
<li data-id="1533987109280" class="completed ">
1728+
<div class="view">
1729+
<input class="toggle" type="checkbox" checked="">
1730+
<label>hello world</label>
1731+
<button class="destroy"></button>
1732+
</div>
1733+
</li>
1734+
<li data-id="1534013859716" class="editing">
1735+
<div class="view"><input class="toggle" type="checkbox">
1736+
<label>totes editing this todo item</label>
1737+
<button class="destroy">
1738+
</button>
1739+
</div>
1740+
<input class="edit">
1741+
</li>
1742+
</ul>
1743+
```
1744+
1745+
1746+
1747+
```js
1748+
1749+
```
1750+
1751+
There are _two_ steps to Editing a Todo List item:
1752+
1753+
+ [ ] Receiving the `singal('EDIT', item.id)` "activates" editing mode.
1754+
1755+
1756+
1757+
1758+
BEFORE:
1759+
```js
1760+
function render_item (item, signal) {
1761+
return (
1762+
li([
1763+
"data-id=" + item.id,
1764+
"id=" + item.id,
1765+
item.done ? "class=completed" : ""
1766+
], [
1767+
div(["class=view"], [
1768+
input([
1769+
item.done ? "checked=true" : "",
1770+
"class=toggle",
1771+
"type=checkbox",
1772+
typeof signal === 'function' ? signal('TOGGLE', item.id) : ''
1773+
],
1774+
[]), // <input> does not have any nested elements
1775+
label([], [text(item.title)]),
1776+
button(["class=destroy"])
1777+
]) // </div>
1778+
]) // </li>
1779+
)
1780+
}
1781+
```
1782+
1783+
1784+
17021785
#### 4.1 `DELETE` an Item
17031786

17041787
```

0 commit comments

Comments
 (0)