discourse/app/assets/javascripts
Martin Brennan 45df579db0
DEV: Improving topic tracking state code (#12555)
The aim of this PR is to improve the topic tracking state JavaScript code and test coverage so further modifications can be made in plugins and in core. This is focused on making topic tracking state changes easier to respond to with callbacks, and changing it so all state modifications go through a single method instead of modifying `this.state` all over the place. I have also tried to improve documentation, make the code clearer and easier to follow, and make it clear what are public and private methods.

The changes I have made here should not break backwards compatibility, though there is no way to tell for sure if other plugin/theme authors are using tracking state methods that are essentially private methods. Any name changes made in the tracking-state.js code have been reflected in core.

----

We now have a `_trackedTopicLimit` in the tracking state. Previously, if a topic was neither new nor unread it was removed from the tracking state; now it is only removed if we are tracking more than `_trackedTopicLimit` topics (which is set to 4000). This is so plugins/themes adding topics with `TopicTrackingState.register_refine_method` can add topics to track that aren't necessarily new or unread, e.g. for totals counts.

Anywhere where we were doing `tracker.states["t" + data.topic_id] = newObject` has now been changed to flow through central `modifyState` and `modifyStateProp` methods. This is so state objects are not modified until they need to be (e.g. sometimes properties are set based on certain conditions) and also so we can run callback functions when the state is modified.

I added `onStateChange` and `onMessageIncrement` methods to register callbacks that are called when the state is changed and when the message count is incremented, respectively. This was done so we no longer need to do things like `@observes("trackingState.states")` in other Ember classes.

I split up giant functions like `sync` and `establishChannels` into smaller functions for readability and testability, and renamed many small functions to _functionName to designate them as private functions which not be called by consumers of `topicTrackingState`. Public functions are now all documented (well...at least ones that are not immediately obvious).

----

On the backend side, I have changed the MessageBus publish events for TopicTrackingState to send back tags and tag IDs for more channels, and done some extra code cleanup and refactoring. Plugins may override `TopicTrackingState.report` so I have made its footprint as small as possible and externalised the main parts of it into other methods.
2021-04-28 09:54:45 +10:00
..
admin FEATURE: the ability to search users by custom fields (#12762) 2021-04-27 15:52:45 +10:00
confirm-new-email
discourse DEV: Improving topic tracking state code (#12555) 2021-04-28 09:54:45 +10:00
discourse-common FIX: Tests were broken in Firefox (#12456) 2021-03-22 11:35:51 +11:00
discourse-hbr DEV: prettier 2.2.1 (#11862) 2021-01-27 12:39:20 +01:00
discourse-widget-hbs REFACTOR: Sync up master with changes for Ember-CLI (#11671) 2021-01-12 10:13:21 -05:00
docs
ember-addons
locales UX: Make moment.js produce Arabic numerals instead of Hindi numerals in the Arabic locale (#11788) 2021-01-21 22:11:51 +03:00
pretty-text DEV: replaces huge generated emoji list by a simpler regex (#11053) 2021-04-22 08:43:06 +02:00
select-kit FIX: TagDrop uses currentCategory now (#12786) 2021-04-21 21:46:52 +02:00
truth-helpers DEV: implements some of ember-truth-helpers (#12667) 2021-04-12 11:40:00 +02:00
wizard Revert "FEATURE: Allow theme tests to be run in production (#12815)" (#12840) 2021-04-26 23:05:58 +03:00
activate-account.js
admin.js.erb FIX: Load .js files from plugins in qunit testing env (#11304) 2020-12-03 10:25:42 -06:00
app-boot.js REFACTOR: Sync up master with changes for Ember-CLI (#11671) 2021-01-12 10:13:21 -05:00
application.js DEV: implements some of ember-truth-helpers (#12667) 2021-04-12 11:40:00 +02:00
auto-redirect.js
browser-detect.js
browser-update.js FIX: browser-update should work with old browsers (#12436) 2021-03-18 19:09:01 +02:00
discourse-loader.js DEV: Add more @ember modules for plugins compatibility with Ember CLI (#11972) 2021-02-04 16:26:06 +03:00
discourse-shims.js Sync up master with Ember CLI branch where possible (#11707) 2021-01-14 12:52:51 -05:00
embed-application.js DEV: prettier 2.2.1 (#11862) 2021-01-27 12:39:20 +01:00
ember_include.js.erb
ember_jquery.js
env.js
google-tag-manager.js FEATURE: Implement nonces for Google Tag Manager integration (#12531) 2021-03-26 11:19:31 -04:00
google-universal-analytics-v3.js FEATURE: Add Google Universal Analytics v4 as an option (#11123) 2020-11-06 14:15:36 -06:00
google-universal-analytics-v4.js FEATURE: Add Google Universal Analytics v4 as an option (#11123) 2020-11-06 14:15:36 -06:00
handlebars-shim.js FIX: It seems sometimes shims are evaluated by older JS engines (#11813) 2021-01-22 10:41:01 -05:00
main_include_admin.js
markdown-it-bundle.js
onpopstate-handler.js
package.json DEV: Migrate to Ember CLI (#11932) 2021-02-03 14:22:20 -05:00
polyfills.js
pretty-text-bundle.js FIX: pretty text allow list (#10977) 2020-10-28 13:22:06 +11:00
print-page.js
service-worker.js.erb DEV: debug: false for service workers to stop log spam via workbox (#12093) 2021-02-16 14:01:19 +10:00
set-prototype-polyfill.js
start-discourse.js
template_include.js
test-shims.js DEV: Migrate to Ember CLI (#11932) 2021-02-03 14:22:20 -05:00
vendor.js DEV: Remove jquery.ba-resize (#11457) 2020-12-11 11:36:32 -05:00
widget-runtime.js
wizard-application.js DEV: implements some of ember-truth-helpers (#12667) 2021-04-12 11:40:00 +02:00
wizard-shims.js
wizard-start.js
wizard-vendor.js REFACTOR: Remove SweetAlert dependency (#11183) 2020-11-10 11:31:54 -05:00
yarn.lock DEV: Support Node 15 with Ember CLI (#12679) 2021-04-14 10:16:39 -04:00