3. Exploiting Derived Inverse Reference Properties in the User Interface

We can now exploit the derived inverse reference properties Publisher::publishedBooks and Author::authoredBooks for more efficiently creating a list of associated books in the list publishers and list authors use cases.

3.1. Show information about published books in the List Publishers use case

For showing information about published books in the list publishers use case, we can now exploit the derived inverse reference property publishedBooks:

pl.view.publishers.list = {
  setupUserInterface: function () {
    var tableBodyEl = document.querySelector("div#listPublishers>table>tbody");
    var pKeys = Object.keys( Publisher.instances);
    var row=null, publisher=null, listEl=null;
    tableBodyEl.innerHTML = "";
    for (var i=0; i < pKeys.length; i++) {
      publisher = Publisher.instances[pKeys[i]];
      row = tableBodyEl.insertRow(-1);
      row.insertCell(-1).textContent = publisher.name;      
      row.insertCell(-1).textContent = publisher.address;
      // create list of books published by this publisher
      listEl = util.createListFromAssocArray( publisher.publishedBooks, "title");
      row.insertCell(-1).appendChild( listEl);
    }
    document.getElementById("managePublishers").style.display = "none";
    document.getElementById("listPublishers").style.display = "block";
  }
};