Skip to content

Commit

Permalink
Grab Promise in a try/catch Fixes #875
Browse files Browse the repository at this point in the history
  • Loading branch information
Rycochet committed Aug 2, 2020
1 parent e55cf8b commit 5fd16ef
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 25 deletions.
14 changes: 10 additions & 4 deletions packages/velocity/src/velocityFn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
// Typedefs
import {
AnimationCall, AnimationFlags, HTMLorSVGElement, Properties, StrictVelocityOptions,
VelocityElements, VelocityExtended, VelocityObjectArgs, VelocityOptions, VelocityPromise,
VelocityProperty, VelocityResult,
VelocityElements, VelocityObjectArgs, VelocityOptions, VelocityPromise, VelocityProperty,
VelocityResult,
} from "./../velocity.d";

// Project
Expand All @@ -32,6 +32,12 @@ import {defaults as DefaultObject} from "./Velocity/defaults";
import {SequencesObject} from "./Velocity/sequencesObject";
import {State as StateObject} from "./Velocity/state";

let globalPromise: PromiseConstructor;

try {
globalPromise = Promise;
} catch {/**/}

/* tslint:disable:max-line-length */
/**
* The main Velocity function. Acts as a gateway to everything else.
Expand Down Expand Up @@ -163,8 +169,8 @@ export function Velocity(this: VelocityElements | void, ...argsList: any[]): Vel
optionsMap = opts;
}
// Create the promise if supported and wanted.
if (Promise && getValue(optionsMap && optionsMap.promise, defaults.promise)) {
promise = new Promise((resolve, reject) => {
if (globalPromise && getValue(optionsMap && optionsMap.promise, defaults.promise)) {
promise = new globalPromise((resolve, reject) => {
rejecter = reject;
// IMPORTANT:
// If a resolver tries to run on a Promise then it will wait until
Expand Down
8 changes: 6 additions & 2 deletions packages/velocity/velocity.es5.js

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

2 changes: 1 addition & 1 deletion packages/velocity/velocity.es5.js.map

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions packages/velocity/velocity.js

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

2 changes: 1 addition & 1 deletion packages/velocity/velocity.js.map

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions packages/velocity/velocity.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ Te([e,i,Ft(i)])}}catch(t){console.error("VelocityJS: Error when trying to identi
*/
function(e,t){if(void 0===t)return""}]);
// Automatically generated
var zt,$t=Xt;
var zt,$t=Kt;
// Project
/******************
Unsupported
Expand Down Expand Up @@ -965,7 +965,7 @@ e.defaults=U,
* <code>jQuery</code>, <code>Zepto</code>, and several classes that return
* Nodes or lists of Nodes.
*/
e.patch=Kt,
e.patch=en,
/**
* Set to true, 1 or 2 (most verbose) to output debug info to console.
*/
Expand All @@ -984,7 +984,7 @@ e.version="2.0.4",
/**
* Added as a fallback for "import {Velocity} from 'velocity-animate';".
*/
e.Velocity=Xt}(zt||(zt={})),function(){if(document.documentMode)return document.documentMode;for(var e=7;e>4;e--){var t=document.createElement("div");if(t.innerHTML="\x3c!--[if IE "+e+"]><span></span><![endif]--\x3e",t.getElementsByTagName("span").length)return t=null,e}}()<=8)throw new Error("VelocityJS cannot run on Internet Explorer 8 or earlier");
e.Velocity=Kt}(zt||(zt={})),function(){if(document.documentMode)return document.documentMode;for(var e=7;e>4;e--){var t=document.createElement("div");if(t.innerHTML="\x3c!--[if IE "+e+"]><span></span><![endif]--\x3e",t.getElementsByTagName("span").length)return t=null,e}}()<=8)throw new Error("VelocityJS cannot run on Internet Explorer 8 or earlier");
/******************
Frameworks
******************/if(window){
Expand All @@ -998,7 +998,7 @@ e.Velocity=Xt}(zt||(zt={})),function(){if(document.documentMode)return document.
* both act on wrapped DOM elements and stand alone for targeting raw DOM
* elements.
*/
var Gt=window.jQuery,Qt=window.Zepto;Kt(window,!0),Kt(Element&&Element.prototype),Kt(NodeList&&NodeList.prototype),Kt(HTMLCollection&&HTMLCollection.prototype),Kt(Gt,!0),Kt(Gt&&Gt.fn),Kt(Qt,!0),Kt(Qt&&Qt.fn)}
var Gt=window.jQuery,Qt=window.Zepto;en(window,!0),en(Element&&Element.prototype),en(NodeList&&NodeList.prototype),en(HTMLCollection&&HTMLCollection.prototype),en(Gt,!0),en(Gt&&Gt.fn),en(Qt,!0),en(Qt&&Qt.fn)}
// Make sure that the values within Velocity are read-only and upatchable.
var Dt=function(t){if(zt.hasOwnProperty(t))switch(void 0===t?"undefined":e(t)){case"number":case"boolean":f($t,t,{get:function(){return zt[t]},set:function(e){zt[t]=e}},!0);break;default:f($t,t,zt[t],!0)}};for(var Ut in zt)Dt(Ut);
// Project
Expand All @@ -1007,10 +1007,10 @@ var Zt=/(\d*\.\d+|\d+\.?|from|to)/g;function Yt(e,t){var n=e.tweens=Object.creat
* Used to register a sequence. This should never be called by users
* directly, instead it should be called via an action:<br/>
* <code>Velocity("registerSequence", ""name", VelocitySequence);</code>
*/
*/y(["registerSequence",function e(t){if(a(t[0]))for(var n in t[0])t[0].hasOwnProperty(n)&&e([n,t[0][n]]);else if(l(t[0])){var r=t[0],i=t[1];if(l(r))if(a(i)){Oe[r]&&console.warn("VelocityJS: Replacing named sequence:",r);var s={},u=new Array(100),c=[],f=Oe[r]={},d=R(i.duration);for(var v in f.tweens={},o(d)&&(f.duration=d),i)if(i.hasOwnProperty(v)){var p=String(v).match(Zt);if(p){var g=!0,y=!1,h=void 0;try{for(var w,b=p[Symbol.iterator]();!(g=(w=b.next()).done);g=!0){var S=w.value,x="from"===S?0:"to"===S?100:parseFloat(S);if(x<0||x>100)console.warn("VelocityJS: Trying to use an invalid value as a percentage (0 <= n <= 100):",r,x);else if(isNaN(x))console.warn("VelocityJS: Trying to use an invalid number as a percentage:",r,v,S);else for(var k in s[String(x)]||(s[String(x)]=[]),s[String(x)].push(v),i[v])c.includes(k)||c.push(k)}}catch(e){y=!0,h=e}finally{try{!g&&b.return&&b.return()}finally{if(y)throw h}}}}var _=Object.keys(s).sort(function(e,t){var n=parseFloat(e),r=parseFloat(t);return n>r?1:n<r?-1:0});_.forEach(function(e){u.push.apply(s[e])});var O=!0,E=!1,T=void 0;try{for(var M,q=c[Symbol.iterator]();!(O=(M=q.next()).done);O=!0){var V=M.value,A=[],N=Ne(V),L=!0,J=!1,C=void 0;try{for(var I,j=_[Symbol.iterator]();!(L=(I=j.next()).done);L=!0){var P=I.value,F=!0,H=!1,B=void 0;try{for(var z,$=s[P][Symbol.iterator]();!(F=(z=$.next()).done);F=!0){var G=i[z.value];G[N]&&A.push(l(G[N])?G[N]:G[N][0])}}catch(e){H=!0,B=e}finally{try{!F&&$.return&&$.return()}finally{if(H)throw B}}}}catch(e){J=!0,C=e}finally{try{!L&&j.return&&j.return()}finally{if(J)throw C}}if(A.length){var Q=Ze(A,N),D=0;if(Q){var U=!0,Z=!1,Y=void 0;try{for(var X,K=_[Symbol.iterator]();!(U=(X=K.next()).done);U=!0){var ee=X.value,te=!0,ne=!1,re=void 0;try{for(var ie,oe=s[ee][Symbol.iterator]();!(te=(ie=oe.next()).done);te=!0){var ae=i[ie.value][N];ae&&(Array.isArray(ae)&&ae.length>1&&(l(ae[1])||Array.isArray(ae[1]))&&(Q[D].easing=W(ae[1],f.duration||m)),Q[D++].percent=parseFloat(ee)/100)}}catch(e){ne=!0,re=e}finally{try{!te&&oe.return&&oe.return()}finally{if(ne)throw re}}}}catch(e){Z=!0,Y=e}finally{try{!U&&K.return&&K.return()}finally{if(Z)throw Y}}f.tweens[N]=Q}}}}catch(e){E=!0,T=e}finally{try{!O&&q.return&&q.return()}finally{if(E)throw T}}}else console.warn("VelocityJS: Trying to set 'registerSequence' sequence to an invalid value:",r,i);else console.warn("VelocityJS: Trying to set 'registerSequence' name to an invalid value:",r)}}],!0);
// Project
/* tslint:enable:max-line-length */
function Xt(){for(var e=arguments.length,t=Array(e),o=0;o<e;o++)t[o]=arguments[o];var
var Xt=void 0;try{Xt=Promise}catch(/**/e){}/**/
/* tslint:enable:max-line-length */function Kt(){for(var e=arguments.length,t=Array(e),o=0;o<e;o++)t[o]=arguments[o];var
/**
* A shortcut to the default options.
*/
Expand Down Expand Up @@ -1085,14 +1085,14 @@ w=[this]:u(this)?(
// previous Velocity() call then grab the animations it's related to.
w=c(this),s(this)&&(x=this.velocity.animations)):m?(w=c(y.elements||y.e),h++):i(y)?(w=c([y]),h++):u(y)&&(w=c(y),h++),
// Allow elements to be chained.
w&&(f(w,"velocity",Xt.bind(w)),x&&f(w.velocity,"animations",x));
w&&(f(w,"velocity",Kt.bind(w)),x&&f(w.velocity,"animations",x));
// Get any options map passed in as arguments first, expand any direct
// options if possible.
var E="reverse"===(
// Next get the propertiesMap and options.
b=m?d(y.properties,y.p):p[h++]),T=!E&&l(b),M=T&&Oe[b],q=m?d(y.options,y.o):p[h];a(q)&&(S=q),
// Create the promise if supported and wanted.
Promise&&d(S&&S.promise,v.promise)&&(k=new Promise(function(e,t){O=t,
Xt&&d(S&&S.promise,v.promise)&&(k=new Xt(function(e,t){O=t,
// IMPORTANT:
// If a resolver tries to run on a Promise then it will wait until
// that Promise resolves - but in this case we're running on our own
Expand Down Expand Up @@ -1165,9 +1165,9 @@ ft(!1),x&&f(w.velocity,"animations",x)}
* By default Velocity will try to patch <code>window</code>,
* <code>jQuery</code>, <code>Zepto</code>, and several classes that return
* Nodes or lists of Nodes.
*/function Kt(e,t){try{f(e,(t?"V":"v")+"elocity",Xt)}catch(e){console.warn("VelocityJS: Error when trying to add prototype.",e)}}
*/function en(e,t){try{f(e,(t?"V":"v")+"elocity",Kt)}catch(e){console.warn("VelocityJS: Error when trying to add prototype.",e)}}
// Project
y(["registerSequence",function e(t){if(a(t[0]))for(var n in t[0])t[0].hasOwnProperty(n)&&e([n,t[0][n]]);else if(l(t[0])){var r=t[0],i=t[1];if(l(r))if(a(i)){Oe[r]&&console.warn("VelocityJS: Replacing named sequence:",r);var s={},u=new Array(100),c=[],f=Oe[r]={},d=R(i.duration);for(var v in f.tweens={},o(d)&&(f.duration=d),i)if(i.hasOwnProperty(v)){var p=String(v).match(Zt);if(p){var g=!0,y=!1,h=void 0;try{for(var w,b=p[Symbol.iterator]();!(g=(w=b.next()).done);g=!0){var S=w.value,x="from"===S?0:"to"===S?100:parseFloat(S);if(x<0||x>100)console.warn("VelocityJS: Trying to use an invalid value as a percentage (0 <= n <= 100):",r,x);else if(isNaN(x))console.warn("VelocityJS: Trying to use an invalid number as a percentage:",r,v,S);else for(var k in s[String(x)]||(s[String(x)]=[]),s[String(x)].push(v),i[v])c.includes(k)||c.push(k)}}catch(e){y=!0,h=e}finally{try{!g&&b.return&&b.return()}finally{if(y)throw h}}}}var _=Object.keys(s).sort(function(e,t){var n=parseFloat(e),r=parseFloat(t);return n>r?1:n<r?-1:0});_.forEach(function(e){u.push.apply(s[e])});var O=!0,E=!1,T=void 0;try{for(var M,q=c[Symbol.iterator]();!(O=(M=q.next()).done);O=!0){var V=M.value,A=[],N=Ne(V),L=!0,J=!1,C=void 0;try{for(var I,j=_[Symbol.iterator]();!(L=(I=j.next()).done);L=!0){var P=I.value,F=!0,H=!1,B=void 0;try{for(var z,$=s[P][Symbol.iterator]();!(F=(z=$.next()).done);F=!0){var G=i[z.value];G[N]&&A.push(l(G[N])?G[N]:G[N][0])}}catch(e){H=!0,B=e}finally{try{!F&&$.return&&$.return()}finally{if(H)throw B}}}}catch(e){J=!0,C=e}finally{try{!L&&j.return&&j.return()}finally{if(J)throw C}}if(A.length){var Q=Ze(A,N),D=0;if(Q){var U=!0,Z=!1,Y=void 0;try{for(var X,K=_[Symbol.iterator]();!(U=(X=K.next()).done);U=!0){var ee=X.value,te=!0,ne=!1,re=void 0;try{for(var ie,oe=s[ee][Symbol.iterator]();!(te=(ie=oe.next()).done);te=!0){var ae=i[ie.value][N];ae&&(Array.isArray(ae)&&ae.length>1&&(l(ae[1])||Array.isArray(ae[1]))&&(Q[D].easing=W(ae[1],f.duration||m)),Q[D++].percent=parseFloat(ee)/100)}}catch(e){ne=!0,re=e}finally{try{!te&&oe.return&&oe.return()}finally{if(ne)throw re}}}}catch(e){Z=!0,Y=e}finally{try{!U&&K.return&&K.return()}finally{if(Z)throw Y}}f.tweens[N]=Q}}}}catch(e){E=!0,T=e}finally{try{!O&&q.return&&q.return()}finally{if(E)throw T}}}else console.warn("VelocityJS: Trying to set 'registerSequence' sequence to an invalid value:",r,i);else console.warn("VelocityJS: Trying to set 'registerSequence' name to an invalid value:",r)}}],!0);var en,tn=Xt;
var tn,nn=Kt;
/**
* These parts of Velocity absolutely must be included, even if they're unused!
*/
Expand Down Expand Up @@ -1208,7 +1208,7 @@ e.defaults=U,
* <code>jQuery</code>, <code>Zepto</code>, and several classes that return
* Nodes or lists of Nodes.
*/
e.patch=Kt,
e.patch=en,
/**
* Set to true, 1 or 2 (most verbose) to output debug info to console.
*/
Expand All @@ -1227,7 +1227,7 @@ e.version="2.0.4",
/**
* Added as a fallback for "import {Velocity} from 'velocity-animate';".
*/
e.Velocity=Xt}(en||(en={})),function(){if(document.documentMode)return document.documentMode;for(var e=7;e>4;e--){var t=document.createElement("div");if(t.innerHTML="\x3c!--[if IE "+e+"]><span></span><![endif]--\x3e",t.getElementsByTagName("span").length)return t=null,e}}()<=8)throw new Error("VelocityJS cannot run on Internet Explorer 8 or earlier");
e.Velocity=Kt}(tn||(tn={})),function(){if(document.documentMode)return document.documentMode;for(var e=7;e>4;e--){var t=document.createElement("div");if(t.innerHTML="\x3c!--[if IE "+e+"]><span></span><![endif]--\x3e",t.getElementsByTagName("span").length)return t=null,e}}()<=8)throw new Error("VelocityJS cannot run on Internet Explorer 8 or earlier");
/******************
Frameworks
******************/if(window){
Expand All @@ -1241,6 +1241,6 @@ e.Velocity=Xt}(en||(en={})),function(){if(document.documentMode)return document.
* both act on wrapped DOM elements and stand alone for targeting raw DOM
* elements.
*/
var nn=window.jQuery,rn=window.Zepto;Kt(window,!0),Kt(Element&&Element.prototype),Kt(NodeList&&NodeList.prototype),Kt(HTMLCollection&&HTMLCollection.prototype),Kt(nn,!0),Kt(nn&&nn.fn),Kt(rn,!0),Kt(rn&&rn.fn)}
var rn=window.jQuery,on=window.Zepto;en(window,!0),en(Element&&Element.prototype),en(NodeList&&NodeList.prototype),en(HTMLCollection&&HTMLCollection.prototype),en(rn,!0),en(rn&&rn.fn),en(on,!0),en(on&&on.fn)}
// Make sure that the values within Velocity are read-only and upatchable.
var on=function(t){if(en.hasOwnProperty(t))switch(void 0===t?"undefined":e(t)){case"number":case"boolean":f(tn,t,{get:function(){return en[t]},set:function(e){en[t]=e}},!0);break;default:f(tn,t,en[t],!0)}};for(var an in en)on(an);return tn});
var an=function(t){if(tn.hasOwnProperty(t))switch(void 0===t?"undefined":e(t)){case"number":case"boolean":f(nn,t,{get:function(){return tn[t]},set:function(e){tn[t]=e}},!0);break;default:f(nn,t,tn[t],!0)}};for(var ln in tn)an(ln);return nn});

0 comments on commit 5fd16ef

Please sign in to comment.