Features can *and should* handle under what context they disconnect

This commit is contained in:
Zixaphir 2014-01-11 12:03:50 -07:00
parent 1e24021c07
commit a20e85d30f
9 changed files with 57 additions and 38 deletions

View File

@ -5095,6 +5095,9 @@
},
disconnect: function() {
var input;
if (!(Conf['Quote Threading'] && g.VIEW === 'thread')) {
return;
}
input = $('input', this.controls);
$.off(input, 'change', this.toggle);
$.event('rmMenuEntry', this.entry);
@ -8681,6 +8684,9 @@
return d.title = Get.threadExcerpt(this);
},
disconnect: function() {
if (g.VIEW !== 'thread' || !Conf['Thread Excerpt']) {
return;
}
return Thread.callbacks.disconnect('Thread Excerpt');
}
};
@ -8733,7 +8739,7 @@
return $.on(d, 'ThreadUpdate', ThreadStats.onUpdate);
},
disconnect: function() {
if (!Conf['Thread Stats']) {
if (g.VIEW !== 'thread' || !Conf['Thread Stats']) {
return;
}
if (Conf['Updater and Stats in Header']) {
@ -8876,6 +8882,9 @@
},
disconnect: function() {
var el, entry, input, name, _i, _j, _len, _len1, _ref, _ref1;
if (g.VIEW !== 'thread' || !Conf['Thread Updater']) {
return;
}
$.off(this.timer, 'click', this.update);
$.off(this.status, 'click', this.update);
if (this.timeoutID) {
@ -9719,7 +9728,7 @@
},
disconnect: function() {
var hr, name, _i, _len, _ref;
if (!Unread.db) {
if (g.VIEW !== 'thread' || !Conf['Unread Count'] && !Conf['Unread Favicon'] && !Conf['Desktop Notifications']) {
return;
}
Unread.db.disconnect();
@ -10680,6 +10689,9 @@
},
disconnect: function(refresh) {
var status, threadID, _ref, _ref1;
if (g.VIEW === 'thread' || !Conf['Thread Expansion']) {
return;
}
_ref = ExpandThread.statuses;
for (threadID in _ref) {
status = _ref[threadID];
@ -11918,12 +11930,12 @@
g.BOARD.threads = {};
return $.rmAll($('.board'));
},
threadFeatures: [['Thread Excerpt', ThreadExcerpt], ['Unread Count', Unread], ['Quote Threading', QuoteThreading], ['Thread Stats', ThreadStats], ['Thread Updater', ThreadUpdater], ['Thread Expansion', ExpandThread]],
features: [['Thread Excerpt', ThreadExcerpt], ['Unread Count', Unread], ['Quote Threading', QuoteThreading], ['Thread Stats', ThreadStats], ['Thread Updater', ThreadUpdater], ['Thread Expansion', ExpandThread]],
disconnect: function() {
var err, errors, feature, features, name, _i, _len, _ref;
features = g.VIEW === 'thread' ? Navigate.threadFeatures : [];
for (_i = 0, _len = features.length; _i < _len; _i++) {
_ref = features[_i], name = _ref[0], feature = _ref[1];
var err, errors, feature, name, _i, _len, _ref, _ref1;
_ref = Navigate.features;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
_ref1 = _ref[_i], name = _ref1[0], feature = _ref1[1];
try {
feature.disconnect();
} catch (_error) {
@ -11942,10 +11954,10 @@
}
},
reconnect: function() {
var err, errors, feature, features, name, _i, _len, _ref;
features = g.VIEW === 'thread' ? Navigate.threadFeatures : [];
for (_i = 0, _len = features.length; _i < _len; _i++) {
_ref = features[_i], name = _ref[0], feature = _ref[1];
var err, errors, feature, name, _i, _len, _ref, _ref1;
_ref = Navigate.features;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
_ref1 = _ref[_i], name = _ref1[0], feature = _ref1[1];
try {
feature.init();
} catch (_error) {

View File

@ -5098,6 +5098,9 @@
},
disconnect: function() {
var input;
if (!(Conf['Quote Threading'] && g.VIEW === 'thread')) {
return;
}
input = $('input', this.controls);
$.off(input, 'change', this.toggle);
$.event('rmMenuEntry', this.entry);
@ -8664,6 +8667,9 @@
return d.title = Get.threadExcerpt(this);
},
disconnect: function() {
if (g.VIEW !== 'thread' || !Conf['Thread Excerpt']) {
return;
}
return Thread.callbacks.disconnect('Thread Excerpt');
}
};
@ -8716,7 +8722,7 @@
return $.on(d, 'ThreadUpdate', ThreadStats.onUpdate);
},
disconnect: function() {
if (!Conf['Thread Stats']) {
if (g.VIEW !== 'thread' || !Conf['Thread Stats']) {
return;
}
if (Conf['Updater and Stats in Header']) {
@ -8859,6 +8865,9 @@
},
disconnect: function() {
var el, entry, input, name, _i, _j, _len, _len1, _ref, _ref1;
if (g.VIEW !== 'thread' || !Conf['Thread Updater']) {
return;
}
$.off(this.timer, 'click', this.update);
$.off(this.status, 'click', this.update);
if (this.timeoutID) {
@ -9702,7 +9711,7 @@
},
disconnect: function() {
var hr, name, _i, _len, _ref;
if (!Unread.db) {
if (g.VIEW !== 'thread' || !Conf['Unread Count'] && !Conf['Unread Favicon'] && !Conf['Desktop Notifications']) {
return;
}
Unread.db.disconnect();
@ -10669,6 +10678,9 @@
},
disconnect: function(refresh) {
var status, threadID, _ref, _ref1;
if (g.VIEW === 'thread' || !Conf['Thread Expansion']) {
return;
}
_ref = ExpandThread.statuses;
for (threadID in _ref) {
status = _ref[threadID];
@ -11907,12 +11919,12 @@
g.BOARD.threads = {};
return $.rmAll($('.board'));
},
threadFeatures: [['Thread Excerpt', ThreadExcerpt], ['Unread Count', Unread], ['Quote Threading', QuoteThreading], ['Thread Stats', ThreadStats], ['Thread Updater', ThreadUpdater], ['Thread Expansion', ExpandThread]],
features: [['Thread Excerpt', ThreadExcerpt], ['Unread Count', Unread], ['Quote Threading', QuoteThreading], ['Thread Stats', ThreadStats], ['Thread Updater', ThreadUpdater], ['Thread Expansion', ExpandThread]],
disconnect: function() {
var err, errors, feature, features, name, _i, _len, _ref;
features = g.VIEW === 'thread' ? Navigate.threadFeatures : [];
for (_i = 0, _len = features.length; _i < _len; _i++) {
_ref = features[_i], name = _ref[0], feature = _ref[1];
var err, errors, feature, name, _i, _len, _ref, _ref1;
_ref = Navigate.features;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
_ref1 = _ref[_i], name = _ref1[0], feature = _ref1[1];
try {
feature.disconnect();
} catch (_error) {
@ -11931,10 +11943,10 @@
}
},
reconnect: function() {
var err, errors, feature, features, name, _i, _len, _ref;
features = g.VIEW === 'thread' ? Navigate.threadFeatures : [];
for (_i = 0, _len = features.length; _i < _len; _i++) {
_ref = features[_i], name = _ref[0], feature = _ref[1];
var err, errors, feature, name, _i, _len, _ref, _ref1;
_ref = Navigate.features;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
_ref1 = _ref[_i], name = _ref1[0], feature = _ref1[1];
try {
feature.init();
} catch (_error) {

View File

@ -37,7 +37,7 @@ Navigate =
# Delete nodes
$.rmAll $ '.board'
threadFeatures: [
features: [
['Thread Excerpt', ThreadExcerpt]
['Unread Count', Unread]
['Quote Threading', QuoteThreading]
@ -47,12 +47,7 @@ Navigate =
]
disconnect: ->
features = if g.VIEW is 'thread'
Navigate.threadFeatures
else
[]
for [name, feature] in features
for [name, feature] in Navigate.features
try
feature.disconnect()
catch err
@ -66,12 +61,7 @@ Navigate =
return
reconnect: ->
features = if g.VIEW is 'thread'
Navigate.threadFeatures
else
[]
for [name, feature] in features
for [name, feature] in Navigate.features
try
feature.init()
catch err

View File

@ -10,6 +10,7 @@ ExpandThread =
$.on a, 'click', ExpandThread.cbToggle
disconnect: (refresh) ->
return if g.VIEW is 'thread' or !Conf['Thread Expansion']
for threadID, status of ExpandThread.statuses
status.req?.abort()
delete ExpandThread.statuses[threadID]

View File

@ -6,4 +6,6 @@ ThreadExcerpt =
name: 'Thread Excerpt'
cb: @node
node: -> d.title = Get.threadExcerpt @
disconnect: -> Thread.callbacks.disconnect 'Thread Excerpt'
disconnect: ->
return if g.VIEW isnt 'thread' or !Conf['Thread Excerpt']
Thread.callbacks.disconnect 'Thread Excerpt'

View File

@ -35,7 +35,7 @@ ThreadStats =
$.on d, 'ThreadUpdate', ThreadStats.onUpdate
disconnect: ->
return unless Conf['Thread Stats']
return if g.VIEW isnt 'thread' or !Conf['Thread Stats']
if Conf['Updater and Stats in Header']
Header.rmShortcut @dialog

View File

@ -59,6 +59,7 @@ ThreadUpdater =
cb: @node
disconnect: ->
return if g.VIEW isnt 'thread' or !Conf['Thread Updater']
$.off @timer, 'click', @update
$.off @status, 'click', @update

View File

@ -13,7 +13,7 @@ Unread =
cb: @node
disconnect: ->
return unless Unread.db
return if g.VIEW isnt 'thread' or !Conf['Unread Count'] and !Conf['Unread Favicon'] and !Conf['Desktop Notifications']
Unread.db.disconnect()
$.rm hr if {hr} = Unread

View File

@ -25,6 +25,7 @@ QuoteThreading =
cb: @node
disconnect: ->
return unless Conf['Quote Threading'] and g.VIEW is 'thread'
input = $ 'input', @controls
$.off input, 'change', @toggle