DEV: Remove code that is not being used.

Code was added in e15c86e8c5 but it isn't
necessary anymore.

Follow-up to e15c86e8c5
This commit is contained in:
Alan Guo Xiang Tan 2021-08-11 15:40:59 +08:00
parent 16ff3ea2f1
commit 2fb17b7b17
2 changed files with 5 additions and 29 deletions

View File

@ -49,7 +49,6 @@ const TopicTrackingState = EmberObject.extend({
@on("init") @on("init")
_setup() { _setup() {
this.states = new Map(); this.states = new Map();
this.messageIncrementCallbacks = {};
this.stateChangeCallbacks = {}; this.stateChangeCallbacks = {};
this._trackedTopicLimit = 4000; this._trackedTopicLimit = 4000;
}, },
@ -381,7 +380,7 @@ const TopicTrackingState = EmberObject.extend({
* in-memory state. * in-memory state.
* *
* Any state changes will make a callback to all state change callbacks defined * Any state changes will make a callback to all state change callbacks defined
* via onStateChange and all message increment callbacks defined via onMessageIncrement * via onStateChange.
* *
* @method sync * @method sync
* @param {TopicList} list * @param {TopicList} list
@ -410,19 +409,12 @@ const TopicTrackingState = EmberObject.extend({
incrementMessageCount() { incrementMessageCount() {
this.incrementProperty("messageCount"); this.incrementProperty("messageCount");
Object.values(this.messageIncrementCallbacks).forEach((cb) => cb());
}, },
_generateCallbackId() { _generateCallbackId() {
return Math.random().toString(12).substr(2, 9); return Math.random().toString(12).substr(2, 9);
}, },
onMessageIncrement(cb) {
let callbackId = this._generateCallbackId();
this.messageIncrementCallbacks[callbackId] = cb;
return callbackId;
},
onStateChange(cb) { onStateChange(cb) {
let callbackId = this._generateCallbackId(); let callbackId = this._generateCallbackId();
this.stateChangeCallbacks[callbackId] = cb; this.stateChangeCallbacks[callbackId] = cb;

View File

@ -451,22 +451,14 @@ discourseModule("Unit | Model | topic-tracking-state", function (hooks) {
]); ]);
}); });
test("message count is incremented and callback is called", function (assert) { test("message count is incremented", function (assert) {
let messageIncrementCalled = false;
trackingState.onMessageIncrement(() => {
messageIncrementCalled = true;
});
publishToMessageBus(`/unread/${currentUser.id}`, unreadTopicPayload); publishToMessageBus(`/unread/${currentUser.id}`, unreadTopicPayload);
assert.equal( assert.equal(
trackingState.messageCount, trackingState.messageCount,
1, 1,
"message count incremented" "message count incremented"
); );
assert.equal(
messageIncrementCalled,
true,
"message increment callback called"
);
}); });
test("state is modified and callback is called", function (assert) { test("state is modified and callback is called", function (assert) {
@ -617,22 +609,14 @@ discourseModule("Unit | Model | topic-tracking-state", function (hooks) {
); );
}); });
test("message count is incremented and callback is called", function (assert) { test("message count is incremented", function (assert) {
let messageIncrementCalled = false;
trackingState.onMessageIncrement(() => {
messageIncrementCalled = true;
});
publishToMessageBus("/new", newTopicPayload); publishToMessageBus("/new", newTopicPayload);
assert.equal( assert.equal(
trackingState.messageCount, trackingState.messageCount,
1, 1,
"message count incremented" "message count incremented"
); );
assert.equal(
messageIncrementCalled,
true,
"message increment callback called"
);
}); });
test("state is modified and callback is called", function (assert) { test("state is modified and callback is called", function (assert) {