Ability to remove handlers from worker-channel and metadata-manager
parent
ba24cde76d
commit
656b129543
|
@ -92,12 +92,11 @@ define([
|
|||
var opts = {
|
||||
password: pData.password
|
||||
};
|
||||
var done = false;
|
||||
ctx.sframeChan.on("EV_CRYPTGET_PROGRESS", function (data) {
|
||||
if (done || data.hash !== parsed.hash) { return; }
|
||||
var handler = ctx.sframeChan.on("EV_CRYPTGET_PROGRESS", function (data) {
|
||||
if (data.hash !== parsed.hash) { return; }
|
||||
updateProgress.progress(data.progress);
|
||||
if (data.progress === 1) {
|
||||
done = true;
|
||||
handler.stop();
|
||||
updateProgress.progress2(1);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -194,6 +194,15 @@ define(['json.sortify'], function (Sortify) {
|
|||
onChange: function (f) { changeHandlers.push(f); },
|
||||
onChangeLazy: function (f) { lazyChangeHandlers.push(f); },
|
||||
onRequestSync: function (f) { syncHandlers.push(f); },
|
||||
off: function (name, f) {
|
||||
var h = [];
|
||||
if (name === 'change') { h = changeHandlers; }
|
||||
else if (name === 'lazy') { h = lazyChangeHandlers; }
|
||||
else if (name === 'title') { h = titleChangeHandlers; }
|
||||
else if (name === 'sync') { h = syncHandlers; }
|
||||
var idx = h.indexOf(f);
|
||||
if (idx !== -1) { h.splice(idx, 1); }
|
||||
},
|
||||
isConnected : function () {
|
||||
return members.indexOf(meta.user.netfluxId) !== -1;
|
||||
},
|
||||
|
|
|
@ -81,17 +81,25 @@ define([
|
|||
// If the type is a query, your handler will be invoked with a reply function that takes
|
||||
// one argument (the content to reply with).
|
||||
chan.on = function (queryType, handler, quiet) {
|
||||
(handlers[queryType] = handlers[queryType] || []).push(function (data, msg) {
|
||||
var h = function (data, msg) {
|
||||
handler(data.content, function (replyContent) {
|
||||
postMsg(JSON.stringify({
|
||||
txid: data.txid,
|
||||
content: replyContent
|
||||
}));
|
||||
}, msg);
|
||||
});
|
||||
};
|
||||
(handlers[queryType] = handlers[queryType] || []).push(h);
|
||||
if (!quiet) {
|
||||
event('EV_REGISTER_HANDLER', queryType);
|
||||
}
|
||||
return {
|
||||
stop: function () {
|
||||
var idx = handlers[queryType].indexOf(h);
|
||||
if (idx === -1) { return; }
|
||||
handlers[queryType].splice(idx, 1);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// If a particular handler is registered, call the callback immediately, otherwise it will be called
|
||||
|
|
Loading…
Reference in New Issue