From 6302488095060f40cd445dc1226df7b9079a301b Mon Sep 17 00:00:00 2001 From: Salvatore Iovene Date: Tue, 5 Feb 2013 14:56:13 +0200 Subject: [PATCH] (hoofbeats) Fixes some anonymous closures and gets scanning working. --- examples/hoofbeats/javascripts/app/app.js | 25 ++++++++++++++++++----- examples/hoofbeats/javascripts/app/router.js | 2 +- examples/hoofbeats/javascripts/app/store.js | 29 ++++++++++++++++++++++++--- examples/hoofbeats/javascripts/library.js | 10 ++++----- examples/hoofbeats/javascripts/musicbrainz.js | 6 +++--- 5 files changed, 55 insertions(+), 17 deletions(-) diff --git a/examples/hoofbeats/javascripts/app/app.js b/examples/hoofbeats/javascripts/app/app.js index a226a26..967b310 100644 --- a/examples/hoofbeats/javascripts/app/app.js +++ b/examples/hoofbeats/javascripts/app/app.js @@ -1,9 +1,24 @@ /* vi: set et sw=4 ts=4 si: */ (function(win) { - 'use strict'; - - win.Hoofbeats = window.Ember.Application.create({ + win.Hoofbeats = win.Ember.Application.create({ VERSION: '0.1', - rootElement: '#application' + rootElement: '#application', + initialized: false, + init: function() { + var self = this; + + if (self.initialized) { + return; + } + + if (win.HoofbeatsLibrary) { + self.library = new win.HoofbeatsLibrary(); + self.initialized = true; + } else { + setTimeout(function() { + self.init(); + }, 100); + } + } }); -})(window); +}(window)); diff --git a/examples/hoofbeats/javascripts/app/router.js b/examples/hoofbeats/javascripts/app/router.js index f024b7d..09525b3 100644 --- a/examples/hoofbeats/javascripts/app/router.js +++ b/examples/hoofbeats/javascripts/app/router.js @@ -25,4 +25,4 @@ }); app.Router = Router; -})(window.Hoofbeats, window.Ember); +}(window.Hoofbeats, window.Ember)); diff --git a/examples/hoofbeats/javascripts/app/store.js b/examples/hoofbeats/javascripts/app/store.js index fcd786d..8bebca5 100644 --- a/examples/hoofbeats/javascripts/app/store.js +++ b/examples/hoofbeats/javascripts/app/store.js @@ -1,10 +1,33 @@ /* vi: set et sw=4 ts=4 si: */ (function(app) { - 'use strict'; - - var Store = function() {} + var Store = function() { + this.reset(); + this.scan(); + } Store.prototype = { + reset: function() { + this.scanCompleted = false; + }, + + scan: function() { + var self = this; + + if (self.scanCompleted) { + return; + } + + if (app.library) { + app.library.scan().then(function() { + self.scanCompleted = true; + }); + } else { + setTimeout(function() { + self.scan(); + }, 100); + } + }, + getArtists: function() { var artists = []; return artists; diff --git a/examples/hoofbeats/javascripts/library.js b/examples/hoofbeats/javascripts/library.js index 6a5d570..32c97c7 100644 --- a/examples/hoofbeats/javascripts/library.js +++ b/examples/hoofbeats/javascripts/library.js @@ -1,5 +1,5 @@ /* vi: set et sw=4 ts=4 si: */ -$(function() { +(function(win, $) { var library = function() { // For readability: this.initialized = false; @@ -12,7 +12,7 @@ $(function() { if (this.initialized) return; - if (window.tizen === undefined) { + if (win.tizen === undefined) { throw Error("You need the Tizen web API to run Hoofbeats."); } @@ -54,7 +54,7 @@ $(function() { items.forEach(function(item, index, items) { self.mediaItems.push(item); - window.MusicBrainz.getArtist(item.name).done(function(data) { + win.MusicBrainz.getArtist(item.artists[0]).done(function(data) { console.log(data); }); }); @@ -81,5 +81,5 @@ $(function() { get initialized() { return this._initialized; } }; - window.HoofbeatsLibrary = library; -}); + win.HoofbeatsLibrary = library; +}(window, jQuery)); diff --git a/examples/hoofbeats/javascripts/musicbrainz.js b/examples/hoofbeats/javascripts/musicbrainz.js index 5b63fc1..adaae9e 100644 --- a/examples/hoofbeats/javascripts/musicbrainz.js +++ b/examples/hoofbeats/javascripts/musicbrainz.js @@ -1,5 +1,5 @@ /* vi: set et sw=4 ts=4 si: */ -$(function() { +(function(win, $) { var musicbrainz = function() { this.baseUrl = 'http://musicbrainz.org/ws/2/'; this.fmtArg = 'fmt=json'; @@ -30,5 +30,5 @@ $(function() { }; } - window.MusicBrainz = new musicbrainz(); -}); + win.MusicBrainz = new musicbrainz(); +}(window, jQuery)); -- 2.7.4