Commit ad6ab698 authored by Romain Courteaud's avatar Romain Courteaud

Add service management on gadget.

A service is function which is executed outside the promise tree when the
gadget is attached to the DOM.
Services are stopped when the gadget is removed from the DOM.

You can declare a service with the "declareService" method, which takes a
function as parameter.

Service errors are reported to the parent gadget by acquisition on
"reportServiceError".
If no gadget catched the service error, the application will crash (document
body will display the raw error).
parent eea2661b
......@@ -61,7 +61,9 @@ module.exports = function (grunt) {
'document',
'DOMParser',
'Channel',
'XMLHttpRequest'
'XMLHttpRequest',
'MutationObserver',
'Node'
]
}
},
......
This diff is collapsed.
......@@ -3,11 +3,15 @@
"use strict";
var gk = rJS(window),
ready_called = false;
ready_called = false,
service_started = false;
gk.ready(function (g) {
ready_called = true;
})
.declareService(function () {
service_started = true;
})
.declareMethod('getBaseHref', function () {
return document.querySelector('base')
.getAttribute('href');
......@@ -19,6 +23,9 @@
.declareMethod('wasReadyCalled', function () {
return ready_called;
})
.declareMethod('wasServiceStarted', function () {
return service_started;
})
.declareMethod('isSubGadgetDictInitialize', function () {
return ((this.hasOwnProperty("__sub_gadget_dict")) &&
(JSON.stringify(this.__sub_gadget_dict) === "{}"));
......@@ -26,6 +33,9 @@
.declareMethod('isAcquisitionDictInitialize', function () {
return (this.__acquired_method_dict !== undefined);
})
.declareMethod('isServiceListInitialize', function () {
return (this.constructor.__service_list !== undefined);
})
.declareMethod('triggerError', function (value) {
throw new Error("Manually triggered embedded error");
})
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment