-
Notifications
You must be signed in to change notification settings - Fork 0
Review One: Word History
The next mission pulls together everything we have covered so far.
You will revise the code from the prior dynamic kids exercise to maintain and display a history of words "entered" by the user, meaning they actually hit the 'Enter' key.
No new concepts are required, but we will demonstrate the Matrix observer mechanism as a diagnostic tool. It does more, but we have not needed it for our missions so far.
Solidify our grasp of Matrix/mxWeb basics by implementing a modest RFE:
- keep track of spelling bee words as they are entered;
- display them in a separate view as they are accumulated;
- allow the user to delete a word from the history simply by clicking it in the history list.
Feel free to tackle this on your own, without our guidance. But here is how we would proceed, holding back details you should be able to handle:
- add a custom "history" property to the
inputwidget named:word-to-spell; - initialize the custom property with an input Cell starting at nil;
- add an
onchangehandler to the widget:word-to-spellthat:- does nothing if the value entered is blank or already in the history; ie, no blanks, no dups. Else
- adds the novel word to the history.
- add a
DIVcolumn to display the history:- create a formula that:
- navigates to the widget
:word-to-spell; and - creates a SPAN for each word.
- navigates to the widget
- create a formula that:
- add an
onclickhandler to each SPAN that:- navigates back to
:word-to-spell; and - destructively deletes the clicked word from the history.
- navigates back to
- note that the deletion is from the actual history, not just the display;
- this is not
ReactJS: theonchangehandler will not fire on each keystroke; - to determine the word associated with a history span, use
(first (mget me :kids)). ie, the SPAN content becomes the first Matrixkidof a SPAN. This is our best approximation of HTML structure in which the content of a SPAN is a child; - to execute the deletion, some actual code to round out:
(md/mswap! [find the :words-to-spell widget] :entered-words
(fn [words]
(remove #{[the SPAN word]} words)))
Help learning mxWeb is available on the #matrix channel of Clojurians Slack.
Issues with this trainer can be reported on its GitHub repo.