Skip to content

Commit

Permalink
Updated jquery.defer.js and samples to work with recent breaking chan…
Browse files Browse the repository at this point in the history
…ges in jQuery APIs for Deferred()
  • Loading branch information
BorisMoore committed May 28, 2013
1 parent 4afe68f commit 41bbd74
Show file tree
Hide file tree
Showing 14 changed files with 50 additions and 130 deletions.
24 changes: 19 additions & 5 deletions README.md
Original file line number Original file line Diff line number Diff line change
@@ -1,3 +1,17 @@
# JsDefer recent Status:

There have been some breaking changes in jQuery APIs for Deferred since JsDefer was implemented.

A recent JsDefer commit modifies jquery.defer.js to make it agains compatible with current
jQuery APIs.

However the non-jquery version of JsDefer - jsdefer.js - uses the previous Deferred APIs,
which means that you cannot currently load jsdefer.js and then have it load jQuery!
You need to determine up front whether you want the version with or without jQuery...

Apart from the above fixes, JsDefer is not being actively updated at the moment, but will
probably become active again at some point after JsViews V1.0 has shipped.

# JsDefer Features: # JsDefer Features:


* Wrapped scripts * Wrapped scripts
Expand Down Expand Up @@ -29,16 +43,16 @@ are provided to illustrate different use scenarios for JsDefer.
### Feature tests: ### Feature tests:


* Basic Features: Currently no unit tests are provided (they will come) but the * Basic Features: Currently no unit tests are provided (they will come) but the
[FeatureTests/Basic](https://github.com/BorisMoore/jsdefer/tree/master/demos/featuretests/basic) [FeatureTests/Basic](https://github.com/BorisMoore/jsdefer/tree/master/demos/feature-tests/basic)
folder provides some examples for testing different feature details. folder provides some examples for testing different feature details.
* Advanced Features: * Advanced Features:
[This folder](https://github.com/BorisMoore/jsdefer/tree/master/demos/featuretests/withorwithoutjquery) [This folder](https://github.com/BorisMoore/jsdefer/tree/master/demos/featuretests/with-or-without-jquery)
shows how to use JsDefer with or without jQuery. shows how to use JsDefer with or without jQuery.
[These samples](https://github.com/BorisMoore/jsdefer/tree/master/demos/featuretests/advanced) [These samples](https://github.com/BorisMoore/jsdefer/tree/master/demos/feature-tests/advanced)
illustrate some less-commonly used features. illustrate some less-commonly used features.
The [AsyncTemplates](https://github.com/BorisMoore/jsdefer/tree/master/demos/featuretests/advanced/asynctemplates) The [AsyncTemplates](https://github.com/BorisMoore/jsdefer/tree/master/demos/feature-tests/advanced/async-templates)
folder explores some experimental integration with folder explores some experimental integration with
[jQuery Templates](https://github.com/jquery/jquery-tmpl). [jQuery Templates](https://github.com/BorisMoore/jquery-tmpl).




## Syntax Examples: ## Syntax Examples:
Expand Down
2 changes: 1 addition & 1 deletion demos/feature-tests/basic/2a_def.html
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
a: { a: {
url: "../resources/folder1/a.js", url: "../resources/folder1/a.js",
minUrl: "../resources/folder1/a.min.js", minUrl: "../resources/folder1/a.min.js",
depends: [ "e", "../resources/f.js" ] depends: [ "e", "../../resources/f.js" ]
}, },
e: "../resources/folder2/e.js" e: "../resources/folder2/e.js"
}); });
Expand Down
6 changes: 3 additions & 3 deletions demos/feature-tests/basic/3_join-with-when.html
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
<script src="../../../jquery.defer.js" type="text/javascript"></script> <script src="../../../jquery.defer.js" type="text/javascript"></script>


<script type="text/javascript"> <script type="text/javascript">

var $ready = $.ready.promise();
var f = $.defer( "../resources/f.js", { var f = $.defer( "../resources/f.js", {
delayDomReady: true delayDomReady: true
}) })
.done( function(){ .done( function(){
log( "f loaded. DomReady: " + $.ready.isResolved() ); log( "f loaded. DomReady: " + ($ready.state() === "resolved"));
}); });


var a = $.defer( "../resources/folder1/a.js" ); var a = $.defer( "../resources/folder1/a.js" );
Expand All @@ -22,7 +22,7 @@
f f
) )
.done( function(){ .done( function(){
log( "a and f loaded. DomReady: " + $.ready.isResolved() ); log( "a and f loaded. DomReady: " + ($ready.state() === "resolved"));
}); });


$.when( $.when(
Expand Down
8 changes: 4 additions & 4 deletions demos/feature-tests/resources/f.js
Original file line number Original file line Diff line number Diff line change
@@ -1,8 +1,8 @@
((window.$deferRun || function( run ){ run(); }) ( ((window.$deferRun || function( run ){ run(); }) (


function( $, options ) { function( $, options ) {
window.testloaded.f = ""; window.testloaded.f = "";
return options && options.myVal + ". File: f"; return options && options.myVal + ". File: f";
} }


)); ));
13 changes: 5 additions & 8 deletions demos/feature-tests/resources/folder1/a.js
Original file line number Original file line Diff line number Diff line change
@@ -1,13 +1,10 @@
((window.$deferRun || function( run ){ run(); }) ( ((window.$deferRun || function( run ){ run(); }) (


function( $, options ) { function( $, options ) {

window.testloaded.a = "";
window.testloaded.a = ""; if ( $ ) {
if ( $ ) { return options && options.myVal + ". File: a";
return options && options.myVal + ". File: a"; }
} }


}

//);
)); ));
10 changes: 2 additions & 8 deletions demos/feature-tests/resources/folder1/a.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions demos/feature-tests/resources/folder2/c.js
Original file line number Original file line Diff line number Diff line change
@@ -1,8 +1,8 @@
((window.$deferRun || function( run ){ run(); }) ( ((window.$deferRun || function( run ){ run(); }) (


function( $, options ) { function( $, options ) {
window.testloaded.c = ""; window.testloaded.c = "";
return options && options.myVal + ". File: c"; return options && options.myVal + ". File: c";
} }


)); ));
8 changes: 4 additions & 4 deletions demos/feature-tests/resources/folder2/d.js
Original file line number Original file line Diff line number Diff line change
@@ -1,8 +1,8 @@
((window.$deferRun || function( run ){ run(); }) ( ((window.$deferRun || function( run ){ run(); }) (


function( $, options ) { function( $, options ) {
window.testloaded.d = ""; window.testloaded.d = "";
return options && options.myVal + ". File: d"; return options && options.myVal + ". File: d";
} }


)); ));

This file was deleted.

This file was deleted.

11 changes: 1 addition & 10 deletions jquery.defer.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ $.extend({
var i, thisRunCb = runCb || scriptDef.runCb; // For multiple or composite scripts, callback was passed via scriptDef var i, thisRunCb = runCb || scriptDef.runCb; // For multiple or composite scripts, callback was passed via scriptDef


if ( !(runWait--) ) { if ( !(runWait--) ) {
if ( !asyncLoad.isRejected() ) { if ( asyncLoad.state() !== "rejected" ) {
if ( parentPromise ) { if ( parentPromise ) {
asyncLoad.resolve( asyncLoad.resolve(
result || result ||
Expand Down Expand Up @@ -312,15 +312,6 @@ deferSettings = $.deferSettings;
defer = $.defer; defer = $.defer;
ready = $.ready; ready = $.ready;


readyDefer = $.Deferred();
readyDefer.promise( ready );

// Workaround, to expose domReady promise
// (only needed because the Dom Ready promise is not exposed by core).
$( function() {
readyDefer.resolve();
});

})( jQuery, window ); })( jQuery, window );




Expand Down
3 changes: 2 additions & 1 deletion jquery.defer.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions jsdefer.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var $, document = window.document,
scriptByUrl = {}, scriptByUrl = {},
loadingScripts = [], loadingScripts = [],
loadingSubScripts, loadingSubScripts,
promiseMethods = "then done fail isResolved isRejected promise".split( " " ), promiseMethods = "then done fail state promise".split( " " ),
slice = [].slice; slice = [].slice;


if ( window.jQuery ) { if ( window.jQuery ) {
Expand All @@ -26,7 +26,7 @@ if ( window.jQuery ) {
//////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////
// jQuery is not loaded. Make $ the jsDefer object // jQuery is not loaded. Make $ the jsDefer object


// Use a 'clone' of the implementation of Deferred from jQuery-1.5.js // Use a 'clone' of the implementation of Deferred from jQuery-1.10.0.js
// to provide identical Deferred APIs and behavior to jQuery. // to provide identical Deferred APIs and behavior to jQuery.


// Also provide simplified support for $.extend, DomReady and AJAX x-domain requests, // Also provide simplified support for $.extend, DomReady and AJAX x-domain requests,
Expand Down
Loading

0 comments on commit 41bbd74

Please sign in to comment.