Skip to content

Commit

Permalink
make provide accept pledges as argument so that async provides are po…
Browse files Browse the repository at this point in the history
…ssible
  • Loading branch information
dlueth committed Apr 15, 2020
1 parent 09229a1 commit ff32bad
Show file tree
Hide file tree
Showing 14 changed files with 25 additions and 18 deletions.
2 changes: 1 addition & 1 deletion dist/cache/dispose.js

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

2 changes: 1 addition & 1 deletion dist/cache/states.js

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

4 changes: 2 additions & 2 deletions dist/demand.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/demand.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/handler/css.js

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

2 changes: 1 addition & 1 deletion dist/handler/html.js

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

2 changes: 1 addition & 1 deletion dist/handler/json.js

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

2 changes: 1 addition & 1 deletion dist/handler/legacy.js

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

2 changes: 1 addition & 1 deletion dist/handler/text.js

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

2 changes: 1 addition & 1 deletion dist/plugin/cookie.js

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

2 changes: 1 addition & 1 deletion dist/plugin/lzstring.js

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

2 changes: 1 addition & 1 deletion dist/plugin/sri.js

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "qoopido.demand",
"title": "Qoopido.demand",
"description": "Promise like module loader using XHR requests and localStorage caching to dynamically load JavaScript and CSS + dynamic dependency resolution + support for custom handlers",
"version": "5.3.0",
"version": "5.3.1",
"homepage": "https://github.com/dlueth/qoopido.demand",
"author": {
"name": "Dirk Lueth",
Expand Down
15 changes: 11 additions & 4 deletions src/function/provide.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
/* global
global, document, demand, provide, queue, processor, settings, setTimeout, clearTimeout,
EVENT_PROVIDE, EVENT_REJECT, STRING_STRING, STRING_UNDEFINED, STRING_FUNCTION, ERROR_PROVIDE, ERROR_PROVIDE_ANONYMOUS, NULL,
validatorIsTypeOf, validatorIsArray,
validatorIsTypeOf, validatorIsInstanceOf, validatorIsArray,
singletonEvent,
ClassDependency, ClassFailure
ClassDependency, ClassFailure, ClassPledge
*/

//=require constants.js
//=require validator/isTypeOf.js
//=require validator/isInstanceOf.js
//=require validator/isArray.js
//=require singleton/event.js
//=require class/dependency.js
//=require class/failure.js
//=require class/pledge.js

/*eslint no-global-assign: [2, { "exceptions": ["provide"] }] */
provide = function provide() {
var uri = validatorIsTypeOf(arguments[0], STRING_STRING) ? arguments[0] : NULL,
context = this !== global ? this : NULL,
dependencies = validatorIsArray(arguments[uri ? 1 : 0]) ? arguments[uri ? 1 : 0] : NULL,
definition = dependencies ? arguments[uri ? 2 : 1] : arguments[uri ? 1 : 0],
module, isFunction;
module, isPledge, isFunction;

if(!uri && processor.current) {
module = processor.current;
Expand All @@ -30,6 +32,7 @@ provide = function provide() {

if(uri) {
module = module || new ClassDependency(uri, context);
isPledge = validatorIsInstanceOf(definition, ClassPledge);
isFunction = validatorIsTypeOf(definition, STRING_FUNCTION);

if(dependencies) {
Expand All @@ -40,7 +43,11 @@ provide = function provide() {
function() { module.dfd.reject(new ClassFailure(ERROR_PROVIDE, module.id, arguments)); }
);
} else {
module.dfd.resolve(isFunction ? definition() : definition);
if(isPledge) {
definition.then(module.dfd.resolve, module.dfd.reject);
} else {
module.dfd.resolve(isFunction ? definition() : definition);
}
}

module.dfd.pledge.then(
Expand Down

0 comments on commit ff32bad

Please sign in to comment.