thinkpixellab / PxLoader

PxLoader is a simple JavasScript library for creating preloaders and resource downloaders for HTML5 apps.
http://thinkpixellab.com/pxloader
1.11k stars 173 forks source link

AMD support #25

Closed arboleya closed 8 years ago

arboleya commented 11 years ago

Even tough there seems to be some work done for providing AMD compatibility, there are some inconsistencies that may still fail.

For example, I can have:

define [
  'pxloader'
  'pxloaderimage'
  'pxloadersound',
  'pxloadervideo'
], ( pxloader, pxloadersound, pxloaderimage,  pxloadervideo)->
    # code here...

Which may fail, since PxLoaderimage, PxLoaderSound and PxLoaderVideo will try to add some methods on PxLoader prototype through it's global definition.

PxLoader.prototype.addVideo = function(url, tags, priority) {
PxLoader.prototype.addSound = function(id, url, tags, priority) {
PxLoader.prototype.addImage = function(url, tags, priority) {

As AMD do not load files orderly, the sound, image and video plugins may finish loading first, specially because they are much smaller. And every time it happens, an error will be raised.

Uncaught ReferenceError: PxLoader is not defined 

In order to fix this, this raw prototype calls should be made as a AMD require as well in case define and amd.define is present, so the PxLoader reference will never be undefined.

robinnorth commented 8 years ago

This is fixed by #48 πŸŽ‰

robinnorth commented 8 years ago

@joelfillmore: This can be closed now πŸ˜„