EXPORTED_SYMBOLS = ["module"];
var module = function (application) {
var log = function (message) {
application.logger.trace("[Settings Manager] " + message);
}
;
var SettingsManager = function () {
this._wiid = "";
}
;
SettingsManager.prototype = {
constructor: SettingsManager,
init: function (api) {
var settingsManager = this;
settingsManager._settingsAPI = api.Settings;
var mailman = application.mailman;
const SUBJECT = "widget-instance-created";
var subscriber = {
receive: function ({body: wiid}) {
log("wiid received " + wiid + ".");
settingsManager._wiid = wiid;
log("stop listen for " + SUBJECT + ".");
mailman.removeSubscriber({
subject: SUBJECT,
subscriber: subscriber});
mailman.send({
subject: "settings-available",
body: wiid});
log("start listen for changes of " + wiid + ".");
settingsManager._settingsAPI.observeChanges({
onSettingChange: function (name, value) {
log(name + " of widget " + wiid + " changed.");
mailman.send({
subject: "setting-changed",
body: {
name: name,
value: value}});
}
},wiid);
}
};
log("start listen for " + SUBJECT + ".");
mailman.addSubscriber({
subject: SUBJECT,
subscriber: subscriber});
}
,
destroy: function () {
log("destroy called.");
if ("" === this._wiid)
{
return;
}

log("ignoring " + this._wiid + " changes.");
this._settingsAPI.ignoreChanges(this._wiid);
this._settingsAPI = null;
}
};
return SettingsManager;
}
;
