4 var BooksModel = (function() {
21 my.map = {}, // map from book.Id to index into cache[]
27 my.listen = function(subscriber) {
28 listeners.push(subscriber);
31 my.refreshData = function () {
33 var url = '/info/?ids=';
35 for (i = my.first; i <= my.last; ++i) {
41 my.map[id] = i - my.first;
44 fetch(url, {method:'GET', cache:'default'})
45 .then(response => response.json())
46 .then((jsonValue) => {
47 console.log('JSON response for info: ', jsonValue);
49 notifyAll(); // inform all subscribers that the model has been updated
52 var msg = 'Error fetching book details via URL: ' + url + ': ' + err;
53 console.log(msg, err.stack);
61 function notifyAll() {
62 for (var i in listeners) {
63 listeners[i].notify();