@enact/core
Advanced tools
Comparing version 1.11.0 to 1.12.0
@@ -5,2 +5,8 @@ # Change Log | ||
## [1.12.0] - 2017-10-27 | ||
### Added | ||
- `core/util.Job` APIs `idle`, `idleUntil`, `startRaf` and `startRafAfter` | ||
## [1.11.0] - 2017-10-24 | ||
@@ -124,3 +130,3 @@ | ||
### Addded | ||
### Added | ||
@@ -127,0 +133,0 @@ - `core/handle` function `forEventProp` to test properties on an event |
{ | ||
"name": "@enact/core", | ||
"version": "1.11.0", | ||
"version": "1.12.0", | ||
"description": "Enact is an open source JavaScript framework containing everything you need to create a fast, scalable mobile or web application.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -108,2 +108,39 @@ 'use strict'; | ||
/** | ||
* Executes job when the CPU is idle, or when the timeout is reached, whichever occurs first. | ||
* | ||
* @method | ||
* @memberof core/util.Job | ||
* @param {Number} timeout The number of milliseconds to wait before executing the | ||
* job. This guarantees that the job is run, if a positive value | ||
* is specified. | ||
* @param {...*} [args] Any args passed are forwarded to the callback | ||
* @returns {undefined} | ||
* @public | ||
*/ | ||
/** | ||
* Executes job before the next repaint. | ||
* | ||
* @method | ||
* @memberof core/util.Job | ||
* @param {...*} [args] Any args passed are forwarded to the callback | ||
* @returns {undefined} | ||
* @public | ||
*/ | ||
/** | ||
* Executes job before the next repaint after a given amount of timeout. | ||
* | ||
* @method | ||
* @memberof core/util.Job | ||
* @param {Number} timeout The number of milliseconds to wait before running requestAnimationFrame. | ||
* @param {...*} [args] Any args passed are forwarded to the callback | ||
* @returns {undefined} | ||
* @public | ||
*/ | ||
}]); | ||
@@ -146,6 +183,8 @@ | ||
window.cancelIdleCallback(_this.id); | ||
} else if (_this.type === 'raf') { | ||
window.cancelAnimationFrame(_this.id); | ||
} else { | ||
clearTimeout(_this.id); | ||
_this.id = null; | ||
} | ||
_this.id = null; | ||
} | ||
@@ -178,2 +217,10 @@ }; | ||
_this.idleUntil.apply(_this, [null].concat(args)); | ||
}; | ||
this.idleUntil = function (timeout) { | ||
for (var _len6 = arguments.length, args = Array(_len6 > 1 ? _len6 - 1 : 0), _key6 = 1; _key6 < _len6; _key6++) { | ||
args[_key6 - 1] = arguments[_key6]; | ||
} | ||
if (typeof window !== 'undefined') { | ||
@@ -184,3 +231,3 @@ if (window.requestIdleCallback) { | ||
return _this.run(args); | ||
}); | ||
}, { timeout: timeout }); | ||
} else { | ||
@@ -192,2 +239,38 @@ // If requestIdleCallback is not supported just run the function immediately | ||
}; | ||
this.startRaf = function () { | ||
for (var _len7 = arguments.length, args = Array(_len7), _key7 = 0; _key7 < _len7; _key7++) { | ||
args[_key7] = arguments[_key7]; | ||
} | ||
_this.startRafAfter.apply(_this, [_this.timeout].concat(args)); | ||
}; | ||
this.startRafAfter = function (timeout) { | ||
for (var _len8 = arguments.length, args = Array(_len8 > 1 ? _len8 - 1 : 0), _key8 = 1; _key8 < _len8; _key8++) { | ||
args[_key8 - 1] = arguments[_key8]; | ||
} | ||
_this.type = 'raf'; | ||
if (typeof window !== 'undefined') { | ||
var time = null; | ||
var callback = function callback(timestamp) { | ||
if (time === null) { | ||
time = timestamp; | ||
} | ||
if (timeout && timestamp - time < timeout) { | ||
_this.id = window.requestAnimationFrame(callback); | ||
} else { | ||
time = null; | ||
_this.run(args); | ||
window.cancelAnimationFrame(_this.id); | ||
_this.id = null; | ||
} | ||
}; | ||
_this.id = window.requestAnimationFrame(callback); | ||
} else { | ||
// If requestAnimationFrame is not supported just run the function immediately | ||
_this.fn.apply(_this, args); | ||
} | ||
}; | ||
}; | ||
@@ -194,0 +277,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
140240
3655