@paddybasi,
I came across this when trying to do the same in JSMVC 3.3. The
only issue I have here is that I can't see how to assign variables to
the argument that is provided to the success function ... it is always undefined.
Ideally, I want to wrap this all into a Deferred so I can call it like:
- stealWithPromised('src')
- .done(function(steal1, steal2)
- {
- // where steal1 and steal2 are javascript objects the same as if I use the standard steal function
- })
- .fail(function(status)
- {
- // status will be 404, 500, etc;
- });
this is what I have so far, all working except for the having
access to the stolen resource:
- function stealWithPromise(src)
- {
- return $.Deferred(function(deferred)
- {
- var stel = steal.make(src);
- stel.options.type = 'js';
-
- stel.loaded.done(function( /* need js object/s here */)
- {
- deferred.resolve( /* js object/s */);
- });
- stel.loaded.fail(function(status)
- {
- deferred.reject(status);
- });
-
- if (stel.isLoaded)
- {
- deferred.resolve( /* js object/s */);
- }
-
- if (stel.loading || stel.isLoaded)
- {
- return;
- // what to return here is in the deferred
- }
-
- stel.loading = true;
- steal.require(stel.options,
- function()
- {
- stel.loaded.resolve();
- },
- function()
- {
- stel.loaded.reject();
- });
- })
- .promise();
- }