@enact/webos
Advanced tools
Comparing version 2.0.0-alpha.6 to 2.0.0-alpha.7
@@ -5,2 +5,9 @@ # Change Log | ||
## [2.0.0-alpha.7 - 2018-04-03] | ||
### Added | ||
- `webos/LS2Request` `send()` parameters `onTimeout` and `timeout` | ||
- `webos/LS2Request` `send()` default `onFailure` and `onTimeout` handlers | ||
## [2.0.0-alpha.6] - 2018-03-22 | ||
@@ -7,0 +14,0 @@ |
@@ -8,2 +8,4 @@ "use strict"; | ||
var _util = require("@enact/core/util"); | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
@@ -17,5 +19,2 @@ | ||
/* eslint-disable no-console */ | ||
/* global console */ | ||
var refs = {}; | ||
@@ -29,33 +28,104 @@ | ||
return path; | ||
}; // default handlers | ||
var failureHandler = function failureHandler(_ref) { | ||
var errorText = _ref.errorText; | ||
return console.error("LS2Request: ".concat(errorText)); | ||
}; | ||
var timeoutHandler = function timeoutHandler(_ref2) { | ||
var errorText = _ref2.errorText; | ||
return console.warn("LS2Request: ".concat(errorText)); | ||
}; | ||
/** | ||
* A class for managing LS2 Requests | ||
* | ||
* @memberof webos/LS2Request | ||
* @class | ||
*/ | ||
var LS2Request = | ||
/*#__PURE__*/ | ||
function () { | ||
/** | ||
* Create a new LS2 request | ||
* | ||
* @memberof webos/LS2Request.LS2Request | ||
* @constructor | ||
*/ | ||
function LS2Request() { | ||
var _this = this; | ||
_classCallCheck(this, LS2Request); | ||
Object.defineProperty(this, "timeoutJob", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: new _util.Job(function (_ref3) { | ||
var onTimeout = _ref3.onTimeout, | ||
timeout = _ref3.timeout; | ||
onTimeout({ | ||
errorCode: -2, | ||
errorText: "Request timed out after ".concat(timeout, " ms."), | ||
returnValue: false | ||
}); // cancel the request | ||
_this.cancel(); | ||
}) | ||
}); | ||
this.bridge = null; | ||
this.cancelled = false; | ||
this.subscribe = false; | ||
} | ||
/** | ||
* Send a request to an LS2 service method. | ||
* | ||
* @method | ||
* @memberof webos/LS2Request.LS2Request.prototype | ||
* @param {Object} options Options for the LS2 Request call | ||
* @param {String} options.service The name of the LS2 service. Do not include 'luna://'. | ||
* @param {String} options.method The name of the method. | ||
* @param {Object} options.parameters Any parameters required by the service method. | ||
* @param {Function} options.onSuccess The success handler for the request. | ||
* @param {Function} options.onFailure The failure handler for the request. | ||
* @param {Function} options.onComplete The handler to run when the request | ||
* is completed, regardless of return status. | ||
* @param {Function} options.onTimeout The handler to run when the request | ||
* times out. Used in conjunction with `timeout`. | ||
* @param {Boolean} options.subscribe Subscribe to service methods that support subscription. | ||
* @param {Number} options.timeout The delay in milliseconds to wait for the request to return. | ||
* @returns {webos/LS2Request} | ||
* @public | ||
*/ | ||
_createClass(LS2Request, [{ | ||
key: "send", | ||
value: function send(_ref) { | ||
var _ref$service = _ref.service, | ||
service = _ref$service === void 0 ? '' : _ref$service, | ||
_ref$method = _ref.method, | ||
method = _ref$method === void 0 ? '' : _ref$method, | ||
_ref$parameters = _ref.parameters, | ||
parameters = _ref$parameters === void 0 ? {} : _ref$parameters, | ||
_ref$onSuccess = _ref.onSuccess, | ||
onSuccess = _ref$onSuccess === void 0 ? null : _ref$onSuccess, | ||
_ref$onFailure = _ref.onFailure, | ||
onFailure = _ref$onFailure === void 0 ? null : _ref$onFailure, | ||
_ref$onComplete = _ref.onComplete, | ||
onComplete = _ref$onComplete === void 0 ? null : _ref$onComplete, | ||
_ref$subscribe = _ref.subscribe, | ||
subscribe = _ref$subscribe === void 0 ? false : _ref$subscribe; | ||
value: function send(_ref4) { | ||
var _ref4$service = _ref4.service, | ||
service = _ref4$service === void 0 ? '' : _ref4$service, | ||
_ref4$method = _ref4.method, | ||
method = _ref4$method === void 0 ? '' : _ref4$method, | ||
_ref4$parameters = _ref4.parameters, | ||
parameters = _ref4$parameters === void 0 ? {} : _ref4$parameters, | ||
_ref4$onSuccess = _ref4.onSuccess, | ||
onSuccess = _ref4$onSuccess === void 0 ? null : _ref4$onSuccess, | ||
_ref4$onFailure = _ref4.onFailure, | ||
onFailure = _ref4$onFailure === void 0 ? null : _ref4$onFailure, | ||
_ref4$onComplete = _ref4.onComplete, | ||
onComplete = _ref4$onComplete === void 0 ? null : _ref4$onComplete, | ||
_ref4$onTimeout = _ref4.onTimeout, | ||
onTimeout = _ref4$onTimeout === void 0 ? timeoutHandler : _ref4$onTimeout, | ||
_ref4$subscribe = _ref4.subscribe, | ||
subscribe = _ref4$subscribe === void 0 ? false : _ref4$subscribe, | ||
_ref4$timeout = _ref4.timeout, | ||
timeout = _ref4$timeout === void 0 ? 0 : _ref4$timeout; | ||
this.cancelled = false; | ||
if (!onFailure && !onComplete) { | ||
onFailure = failureHandler; | ||
} | ||
if ((typeof window === "undefined" ? "undefined" : _typeof(window)) !== 'object' || !window.PalmServiceBridge) { | ||
@@ -97,2 +167,10 @@ /* eslint no-unused-expressions: ["error", { "allowShortCircuit": true }]*/ | ||
this.bridge.onservicecallback = this.callback.bind(this, onSuccess, onFailure, onComplete); | ||
if (timeout) { | ||
this.timeoutJob.startAfter(timeout, { | ||
onTimeout: onTimeout, | ||
timeout: timeout | ||
}); | ||
} | ||
this.bridge.call(adjustPath(service) + method, JSON.stringify(parameters)); | ||
@@ -106,4 +184,6 @@ return this; | ||
return; | ||
} | ||
} // remove timeout job | ||
this.timeoutJob.stop(); | ||
var parsedMsg; | ||
@@ -137,5 +217,16 @@ | ||
} | ||
/** | ||
* Cancel the current LS2 request. | ||
* | ||
* @method | ||
* @memberof webos/LS2Request.LS2Request.prototype | ||
* @returns {undefined} | ||
* @public | ||
*/ | ||
}, { | ||
key: "cancel", | ||
value: function cancel() { | ||
// remove timeout job | ||
this.timeoutJob.stop(); | ||
this.cancelled = true; | ||
@@ -142,0 +233,0 @@ |
{ | ||
"name": "@enact/webos", | ||
"version": "2.0.0-alpha.6", | ||
"version": "2.0.0-alpha.7", | ||
"description": "webOS support library", | ||
@@ -8,3 +8,3 @@ "main": "index.js", | ||
"clean": "enact clean", | ||
"lint": "enact lint --framework", | ||
"lint": "enact lint --strict", | ||
"test": "echo \"No test suite\" && exit 0", | ||
@@ -11,0 +11,0 @@ "transpile": "enact transpile" |
33863
706