@@ -1693,94 +1693,6 @@ in order to make this test pass; just run it and move on.
1693
1693
1694
1694
1695
1695
1696
-
1697
- #### 4.2 ` EDIT ` an Item
1698
-
1699
- ```
1700
- should allow me to edit an item
1701
- ```
1702
-
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
1696
#### 4.1 ` DELETE ` an Item
1785
1697
1786
1698
```
@@ -1859,25 +1771,147 @@ test.only('4.1 DELETE item by clicking <button class="destroy">', function (t) {
1859
1771
t .equal (document .querySelectorAll (' .destroy' ).length , 1 , " one destroy button" )
1860
1772
1861
1773
const item = document .getElementById (' 0' )
1862
- t .equal (item .textContent , model .todos [0 ].title , ' Item contained in model .' );
1774
+ t .equal (item .textContent , model .todos [0 ].title , ' Item contained in DOM .' );
1863
1775
// DELETE the item by clicking on the <button class="destroy">:
1864
1776
const button = item .querySelectorAll (' button.destroy' )[0 ];
1865
1777
button .click ()
1866
1778
// confirm that there is no loger a <button class="destroy">
1867
1779
t .equal (document .querySelectorAll (' button.destroy' ).length , 0 ,
1868
1780
' there is no loger a <button class="destroy"> as the only item was DELETEd' )
1781
+ t .equal (document .getElementById (' 0' ), null , ' todo item successfully DELETEd' );
1869
1782
t .end ();
1870
1783
});
1871
1784
```
1872
1785
1873
- If you run the tests ` node test/todo-app.test.js `
1786
+ If you run the tests ` node test/todo-app.test.js `
1874
1787
you should now see:
1875
1788
![ delete-test-one-assertion-failing] ( https://user-images.githubusercontent.com/194400/44953479-21313300-ae96-11e8-971a-51757702bacc.png )
1876
1789
1790
+ The first two assertions are _ optional_ and _ should_ (_ always_ )
1791
+ pass given that they rely on functionality defined previously.
1792
+ The second two will only pass once you _ make_ them pass!
1793
+
1794
+ ##### ` DELETE ` Item _ Implementation_
1795
+
1796
+ The _ first_ step is to add an invocation of ` signal('DELETE' ...) `
1797
+ to the ` render_item ` view rendering function. _ Specifically_ the
1798
+ ` button ` line:
1799
+
1800
+ ``` js
1801
+ button ([" class=destroy" ])
1802
+ ```
1803
+ Add the ` signal ` function invocation:
1804
+ ``` js
1805
+ button ([" class=destroy" , signal (' DELETE' , item .id , model)])
1806
+ ```
1807
+
1808
+ simply adding this function invocation will set it
1809
+ as an ` onclick ` attribute for the ` <button> `
1810
+ therefore when the _ user_ clicks the button it will
1811
+ "trigger" the ` signal ` function with the appropriate arguments.
1812
+
1813
+
1814
+ _ Second_ we need to add a ` case ` statement
1815
+ to the ` update ` function.
1816
+ You should attempt to "solve" this yourself.
1817
+ There is no "right" answer, there are at least
1818
+ 5 ways of solving this, as always, you should write the code
1819
+ that you feel is most _ readable_ .
1820
+
1821
+
1822
+
1823
+
1877
1824
1878
1825
1879
1826
<!--
1880
1827
1828
+
1829
+ #### 4.2 `EDIT` an Item
1830
+
1831
+ ```
1832
+ should allow me to edit an item
1833
+ ```
1834
+
1835
+ Editing a Todo List item is (_by far_)
1836
+ the most "complex" functionality in the TodoMVC app
1837
+ because it involves multiple steps and "dynamic UI".
1838
+
1839
+
1840
+
1841
+ + [ ] Double-click on Item **`<label>title</label>`** to begin editing.
1842
+ + [ ] Render an **`<input class="edit">`** if in "**editing _mode_**"
1843
+ (_see screenshot and markup below_)
1844
+ + [ ] Add `case` in `keyup` Event Listener for **`[Enter]`** keyup
1845
+ (_see **`subscriptions`** above_) if we are in "**editing _mode_**",
1846
+ get the text value from the **`<input class="edit">`**
1847
+ _instead_ of **`<input id="new-todo">`**
1848
+ so that we _update_ the _existing_ Todo Item title (text).
1849
+ + [ ] When **`[Enter]`** is pressed while in "**editing _mode_**",
1850
+ Dispatch the **`END_EDIT`** action: `signal('END_EDIT')`
1851
+
1852
+ 
1853
+
1854
+ Here is the _sample_ HTML in "**editing _mode_**"
1855
+ (_copy-pasted_) from the VanillaJS TodoMVC implementation
1856
+ the _second_ **`<li>`** is the one being edited (_as per screenshot above_):
1857
+ ```HTML
1858
+ <ul class="todo-list">
1859
+ <li data-id="1533987109280" class="completed ">
1860
+ <div class="view">
1861
+ <input class="toggle" type="checkbox" checked="">
1862
+ <label>hello world</label>
1863
+ <button class="destroy"></button>
1864
+ </div>
1865
+ </li>
1866
+ <li data-id="1534013859716" class="editing">
1867
+ <div class="view"><input class="toggle" type="checkbox">
1868
+ <label>totes editing this todo item</label>
1869
+ <button class="destroy">
1870
+ </button>
1871
+ </div>
1872
+ <input class="edit">
1873
+ </li>
1874
+ </ul>
1875
+ ```
1876
+
1877
+
1878
+ ```js
1879
+
1880
+ ```
1881
+
1882
+ There are _two_ steps to Editing a Todo List item:
1883
+
1884
+ + [ ] Receiving the `singal('EDIT', item.id)` "activates" editing mode.
1885
+
1886
+
1887
+
1888
+
1889
+ BEFORE:
1890
+ ```js
1891
+ function render_item (item, signal) {
1892
+ return (
1893
+ li([
1894
+ "data-id=" + item.id,
1895
+ "id=" + item.id,
1896
+ item.done ? "class=completed" : ""
1897
+ ], [
1898
+ div(["class=view"], [
1899
+ input([
1900
+ item.done ? "checked=true" : "",
1901
+ "class=toggle",
1902
+ "type=checkbox",
1903
+ typeof signal === 'function' ? signal('TOGGLE', item.id) : ''
1904
+ ],
1905
+ []), // <input> does not have any nested elements
1906
+ label([], [text(item.title)]),
1907
+ button(["class=destroy"])
1908
+ ]) // </div>
1909
+ ]) // </li>
1910
+ )
1911
+ }
1912
+ ```
1913
+
1914
+
1881
1915
## What _Next_?
1882
1916
1883
1917
If you feel _confident_ with your "TEA" skills you can _either_:
0 commit comments