|
1 | 1 | import{Observable}from'rx'; |
2 | 2 | import{ENTER_KEY,ESC_KEY}from'../../utils'; |
3 | 3 |
|
| 4 | +// THE INTENT FOR THE LIST |
4 | 5 | exportdefaultfunctionintent(DOM,hashchange,initialHash,itemAction$){ |
5 | 6 | return{ |
| 7 | +// THE ROUTE STREAM |
| 8 | +// The stream of the initial hash is being concatenated with |
| 9 | +// the hashchange stream. |
6 | 10 | changeRoute$:Observable.concat( |
7 | 11 | initialHash.map(hash=>hash.replace('#','')), |
8 | 12 | hashchange.map(ev=>ev.newURL.match(/\#[^\#]*$/)[0].replace('#','')) |
9 | 13 | ), |
10 | 14 |
|
| 15 | +// CLEAR INPUT STREAM |
| 16 | +// A stream of ESC key strokes in the `.new-todo` field. |
11 | 17 | clearInput$:DOM.select('.new-todo').events('keydown') |
12 | 18 | .filter(ev=>ev.keyCode===ESC_KEY), |
13 | 19 |
|
| 20 | +// ENTER KEY STREAM |
| 21 | +// A stream of ENTER key strokes in the `.new-todo` field. |
14 | 22 | insertTodo$:DOM.select('.new-todo').events('keydown') |
| 23 | +// Trim value and only let the data through when there |
| 24 | +// is anything but whitespace in the field and the ENTER key was hit. |
15 | 25 | .filter(ev=>{ |
16 | 26 | consttrimmedVal=String(ev.target.value).trim(); |
17 | 27 | returnev.keyCode===ENTER_KEY&&trimmedVal; |
18 | 28 | }) |
| 29 | +// Return the trimmed value. |
19 | 30 | .map(ev=>String(ev.target.value).trim()), |
20 | 31 |
|
| 32 | +// TOGGLE STREAM |
| 33 | +// Create a stream out of all the toggle actions on the todo items. |
21 | 34 | toggleTodo$:itemAction$.filter(action=>action.type==='toggle'), |
22 | 35 |
|
| 36 | +// DELETE STREAM |
| 37 | +// Create a stream out of all the destroy actions on the todo items. |
23 | 38 | deleteTodo$:itemAction$.filter(action=>action.type==='destroy'), |
24 | 39 |
|
| 40 | +// EDIT STREAM |
| 41 | +// Create a stream out of all the doneEdit actions on the todo items. |
25 | 42 | editTodo$:itemAction$.filter(action=>action.type==='doneEdit'), |
26 | 43 |
|
| 44 | +// TOGGLE ALL STREAM |
| 45 | +// Create a stream out of the clicks on the `.toggle-all` button. |
27 | 46 | toggleAll$:DOM.select('.toggle-all').events('click'), |
28 | 47 |
|
| 48 | +// DELETE COMPLETED TODOS STREAM |
| 49 | +// A stream of click events on the `.clear-completed` element. |
29 | 50 | deleteCompleteds$:DOM.select('.clear-completed').events('click') |
30 | 51 | }; |
31 | 52 | }; |