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