Skip to content

Commit

Permalink
remove handling of unhandled pledge rejections
Browse files Browse the repository at this point in the history
Fixes #5
  • Loading branch information
dlueth committed Aug 7, 2020
1 parent 393f1be commit 9c0e34c
Show file tree
Hide file tree
Showing 18 changed files with 40 additions and 46 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.

8 changes: 4 additions & 4 deletions package-lock.json

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": "7.0.7",
"version": "7.0.8",
"homepage": "https://github.com/dlueth/qoopido.demand",
"author": {
"name": "Dirk Lueth",
Expand Down
16 changes: 0 additions & 16 deletions src/class/pledge.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,29 +40,13 @@ var ClassPledge = (function() {
});
}

function handleUncaught(values) {
var i = 0, value;

console.warn(ERROR_UNHANDLED_PLEDGE_REJECTION);

for(; (value = values[i]) !== undefined; i++) {
if(validatorIsInstanceOf(value, Error) || validatorIsInstanceOf(value, ClassFailure)) {
throw value;
}
}
}

function handle(state, parameter) {
var properties = storage.get(this),
pointer, result;

if(properties.state === PLEDGE_PENDING) {
properties.state = state;
properties.value = parameter;

if(state === PLEDGE_REJECTED && !properties[state].length) {
handleUncaught(parameter)
}
}

while(pointer = properties[properties.state].shift()) {
Expand Down
3 changes: 1 addition & 2 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,4 @@ var DEMAND_ID = 'demand',
ERROR_LOAD = 'error loading',
ERROR_PROVIDE = 'error providing',
ERROR_RESOLVE = 'error resolving',
ERROR_PROVIDE_ANONYMOUS = 'unspecified anonymous provide',
ERROR_UNHANDLED_PLEDGE_REJECTION = 'unhandled pledge rejection';
ERROR_PROVIDE_ANONYMOUS = 'unspecified anonymous provide';
26 changes: 19 additions & 7 deletions src/function/demand.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* global
global, document, demand, provide, queue, processor, settings, setTimeout, clearTimeout,
STRING_BOOLEAN, STRING_STRING, EVENT_PRE_RESOLVE, EVENT_POST_RESOLVE, EVENT_PRE_CONFIGURE, EVENT_POST_CONFIGURE, EVENT_CACHE_MISS, EVENT_CACHE_HIT, EVENT_PRE_REQUEST, EVENT_POST_REQUEST, EVENT_PRE_PROCESS, EVENT_POST_PROCESS, NULL, FALSE,
STRING_BOOLEAN, STRING_STRING, EVENT_REJECT, EVENT_PRE_RESOLVE, EVENT_POST_RESOLVE, EVENT_PRE_CONFIGURE, EVENT_POST_CONFIGURE, EVENT_CACHE_MISS, EVENT_CACHE_HIT, EVENT_PRE_REQUEST, EVENT_POST_REQUEST, EVENT_PRE_PROCESS, EVENT_POST_PROCESS, NULL, FALSE,
validatorIsTypeOf, validatorIsObject, validatorIsPositive, validatorIsInstanceOf, validatorIsSemver,
functionIterate, functionMerge, functionDefer, functionIdle, functionToArray,
ClassPledge, ClassDependency, ClassPattern, ClassLoader,
Expand Down Expand Up @@ -48,28 +48,40 @@ demand = (function() {
function demand() {
var dependencies = functionToArray(arguments),
context = this !== global ? this : NULL,
i = 0, uri, dfd, result;
pledges = [], i = 0, uri, dfd, result;

singletonEvent.emit(EVENT_PRE_RESOLVE, NULL, dependencies, context);

for(; (uri = dependencies[i]); i++) {
if(validatorIsTypeOf(uri, STRING_STRING)) {
dependencies[i] = ClassDependency.resolve(uri, context).pledge;
dependencies[i] = ClassDependency.resolve(uri, context);
} else {
dependencies[i] = (dfd = ClassPledge.defer()).pledge;
dependencies[i] = (dfd = ClassPledge.defer());

dfd.resolve(uri);
}

pledges.push(dependencies[i].pledge);
}

if(dependencies.length > 1) {
result = ClassPledge.all(dependencies);
result = ClassPledge.all(pledges);
} else {
result = dependencies[0];
result = pledges[0];
}

return result.always(function() {
singletonEvent.emit(EVENT_POST_RESOLVE, NULL, dependencies, context);
singletonEvent.emit(EVENT_POST_RESOLVE, NULL, pledges, context);

if(result.isRejected()) {
functionIterate(dependencies, function(_, dependency) {
if(dependency.pledge.isRejected()) {
singletonEvent.emit(EVENT_REJECT, dependency.path, dependency);
}
});

return ClassPledge.reject.apply(null, arguments);
}
});
}

Expand Down
5 changes: 2 additions & 3 deletions src/function/provide.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* global
global, document, demand, provide, queue, processor, settings, setTimeout, clearTimeout, log,
EVENT_PROVIDE, EVENT_REJECT, STRING_STRING, STRING_UNDEFINED, STRING_FUNCTION, ERROR_PROVIDE, ERROR_PROVIDE_ANONYMOUS, NULL,
EVENT_PROVIDE, STRING_STRING, STRING_UNDEFINED, STRING_FUNCTION, ERROR_PROVIDE, ERROR_PROVIDE_ANONYMOUS, NULL,
validatorIsTypeOf, validatorIsInstanceOf, validatorIsArray,
singletonEvent,
ClassDependency, ClassFailure, ClassPledge
Expand Down Expand Up @@ -51,8 +51,7 @@ provide = function provide() {
}

module.dfd.pledge.then(
function() { singletonEvent.emit(EVENT_PROVIDE, module.path, module); },
function() { singletonEvent.emit(EVENT_REJECT, module.path, module); }
function() { singletonEvent.emit(EVENT_PROVIDE, module.path, module); }
);

return module.dfd.pledge;
Expand Down

0 comments on commit 9c0e34c

Please sign in to comment.