concept UI in category javascript

This is an excerpt from Manning's book Single Page Web Applications: JavaScript end-to-end.
The Model doesn’t require a browser. This means the Model must not assume the presence of a document object or that browser-specific methods like document.location are available. It’s good MVC hygiene to have the Shell and (especially) the feature modules render the representation of Model data. And this separation makes automated unit and regression testing much simpler. We’ve found that as you get into browser interaction, the value of automated testing diminishes greatly as the cost of implementation rises. But by avoiding the DOM, we can test everything up to the UI without having to run a browser.
Listing 6.4. Test spa.model.chat.join() without a UI or server
/ create a jQuery collection #1 var $t = $('<div/>'); // Have $t subscribe to global custom events with test functions #2 $.gevent.subscribe( $t, 'spa-login', function () { console.log( 'Hello!', arguments ); }); $.gevent.subscribe( $t, 'spa-listchange', function () { #3 console.log( '*Listchange', arguments ); }); // get the current user object #4 var currentUser = spa.model.people.get_user(); // confirm this is not yet signed-in #5 currentUser.get_is_anon(); >> true // try to join chat without being signed-in #6 spa.model.chat.join(); >> User must be defined before joining chat // sign-in, wait 3s. The UI updates too! #7 spa.model.people.login( 'Fred' ); >> Hello! > [jQuery.Event, Object] // get the people collection #8 var peopleDb = spa.model.people.get_db(); // show the names of all people in the collection. #9 peopleDb().each(function(person, idx){console.log(person.name);}); >> anonymous >> Fred // join the chat #10 spa.model.chat.join(); >> true // the spa-listchange event should fire almost immediately. #11 >> *Listchange > [jQuery.Event, Array[1]] #12 // inspect the user list again. We see the people list has // been updated to show all online people. var peopleDb = spa.model.people.get_db(); #13 peopleDb().each(function(person, idx){console.log(person.name);}); >> Betty >> Fred #14 >> Mike >> Pebbles >> Wilma #1 Create a jQuery collection ($t) that isn’t attached to the browser document. We’ll use this for event testing. #2 Have the $t jQuery collection subscribe to the spa-login event with a function that prints “Hello!” and the list of arguments to the console. #3 Have the $t jQuery collection subscribe to the spalistchange event with a function that prints “*Listchange” and the list of arguments to the console. #4 Get the current user object from the people object. $5 Confirm the user isn’t yet signed in using the get_is_anon() method. #6 Try to join the chat without signing in. Per our API specification, we’re denied #7 Sign in as Fred. In the user area in the top-right corner of the browser, you’ll see the text proceed from “Please signin” to “... processing ...” to “Fred.” At the end of sign-in, the spa-login event will publish. This invokes the function we subscribed to the spalogin event on the $t jQuery collection, so we see the “Hello!” message and the list of arguments. #8 Get the TaffyDB people collection from the people object. #9 Confirm that only Fred and anonymous are in the people collection. This makes sense, as we haven’t yet joined the chat. #10 Join the chat. #11 Less than one second after join(), the spa-listchange event should publish. This invokes the function we subscribed to the spalistchange event on the $t jQuery collection, and so we see the “Hello!” message along with the list of arguments. #12 Confirm we see a Socket.IOstyle array of arguments returned. An updated user list is the first in the argument array #13 Get the updated people list. #14 Confirm the people list now contains our mock chat-party along with our user, Fred. !@%STYLE%@! {"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":1,\"ch\":0},{\"line\":1,\"ch\":21}],[{\"line\":3,\"ch\":1},{\"line\":3,\"ch\":51}],[{\"line\":8,\"ch\":0},{\"line\":8,\"ch\":46}],[{\"line\":10,\"ch\":0},{\"line\":10,\"ch\":26}],[{\"line\":13,\"ch\":0},{\"line\":13,\"ch\":22}],[{\"line\":25,\"ch\":0},{\"line\":25,\"ch\":22}],[{\"line\":16,\"ch\":0},{\"line\":16,\"ch\":33}],[{\"line\":19,\"ch\":0},{\"line\":19,\"ch\":41}],[{\"line\":31,\"ch\":0},{\"line\":31,\"ch\":41}],[{\"line\":21,\"ch\":0},{\"line\":21,\"ch\":66}],[{\"line\":32,\"ch\":0},{\"line\":32,\"ch\":66}],[{\"line\":13,\"ch\":0},{\"line\":13,\"ch\":22}],[{\"line\":25,\"ch\":0},{\"line\":25,\"ch\":22}],[{\"line\":21,\"ch\":0},{\"line\":21,\"ch\":66}],[{\"line\":32,\"ch\":0},{\"line\":32,\"ch\":66}]]"} !@%STYLE%@!

This is an excerpt from Manning's book Prototype and Scriptaculous in Action.
There is quite a lot going on here, so let’s pick through it piece by piece. The updateUI() method takes an optional argument delta, which we’ll ignore when we initially call it in the constructor
. It then proceeds to build up a set of HTML markup as a string, defining the UI that we saw in figure 1.1 as an HTML table. This string is then assigned to the target element using the innerHTML property
.
The UI for the slideshow will be very simple, as we only need to present a single image and caption at any one time. We can specify the layout using CSS, as we did for the slideshow editor. Listing 12.16 presents the new CSS classes required by the viewer.
When composing a slideshow, we’ll want to be able to roam freely across the filesystem, using the existing functionality. We therefore need a separate UI element to provide a view of the slideshow in progress. This will need to be large enough to accommodate thumbnail images and reasonably large captions. We can’t, therefore, fit it into the top or left areas without getting crowded. We’ve decided to add it to the right side of the UI, and to place a trash can underneath it for disposing of unwanted elements in the slideshow.
. It then proceeds to build up a set of HTML markup as a string, defining the UI that we saw in
.