Commit a20c37b8 authored by Robert Knight's avatar Robert Knight

Convert `threads` service to an ES class

Part of https://github.com/hypothesis/client/issues/3298
parent 9861eaf1
...@@ -14,7 +14,7 @@ import ModerationBanner from './ModerationBanner'; ...@@ -14,7 +14,7 @@ import ModerationBanner from './ModerationBanner';
/** /**
* @typedef ThreadProps * @typedef ThreadProps
* @prop {Thread} thread * @prop {Thread} thread
* @prop {Object} threadsService - Injected service * @prop {import('../services/threads').ThreadsService} threadsService
*/ */
/** /**
......
...@@ -112,7 +112,7 @@ import sessionService from './services/session'; ...@@ -112,7 +112,7 @@ import sessionService from './services/session';
import { StreamFilter } from './services/stream-filter'; import { StreamFilter } from './services/stream-filter';
import streamerService from './services/streamer'; import streamerService from './services/streamer';
import tagsService from './services/tags'; import tagsService from './services/tags';
import threadsService from './services/threads'; import { ThreadsService } from './services/threads';
import { ToastMessengerService } from './services/toast-messenger'; import { ToastMessengerService } from './services/toast-messenger';
// Redux store. // Redux store.
...@@ -150,7 +150,7 @@ function startApp(config, appEl) { ...@@ -150,7 +150,7 @@ function startApp(config, appEl) {
.register('streamer', streamerService) .register('streamer', streamerService)
.register('streamFilter', StreamFilter) .register('streamFilter', StreamFilter)
.register('tags', tagsService) .register('tags', tagsService)
.register('threadsService', threadsService) .register('threadsService', ThreadsService)
.register('toastMessenger', ToastMessengerService) .register('toastMessenger', ToastMessengerService)
.register('store', store); .register('store', store);
......
import threadsService from '../threads'; import { ThreadsService } from '../threads';
const NESTED_THREADS = { const NESTED_THREADS = {
id: 'top', id: 'top',
...@@ -60,7 +60,7 @@ const NESTED_THREADS = { ...@@ -60,7 +60,7 @@ const NESTED_THREADS = {
], ],
}; };
describe('threadsService', () => { describe('ThreadsService', () => {
let fakeStore; let fakeStore;
let service; let service;
...@@ -68,7 +68,7 @@ describe('threadsService', () => { ...@@ -68,7 +68,7 @@ describe('threadsService', () => {
fakeStore = { fakeStore = {
setForcedVisible: sinon.stub(), setForcedVisible: sinon.stub(),
}; };
service = threadsService(fakeStore); service = new ThreadsService(fakeStore);
}); });
describe('#forceVisible', () => { describe('#forceVisible', () => {
......
...@@ -2,8 +2,18 @@ ...@@ -2,8 +2,18 @@
* @typedef {import('../helpers/build-thread').Thread} Thread * @typedef {import('../helpers/build-thread').Thread} Thread
*/ */
/**
* A service for performing operations related to the current set of threads.
*/
// @inject // @inject
export default function threadsService(store) { export class ThreadsService {
/**
* @param {import('../store').SidebarStore} store
*/
constructor(store) {
this._store = store;
}
/** /**
* Make this thread and all of its children "visible". This has the effect of * Make this thread and all of its children "visible". This has the effect of
* "unhiding" a thread which is currently hidden by an applied search filter * "unhiding" a thread which is currently hidden by an applied search filter
...@@ -12,16 +22,12 @@ export default function threadsService(store) { ...@@ -12,16 +22,12 @@ export default function threadsService(store) {
* *
* @param {Thread} thread * @param {Thread} thread
*/ */
function forceVisible(thread) { forceVisible(thread) {
thread.children.forEach(child => { thread.children.forEach(child => {
forceVisible(child); this.forceVisible(child);
}); });
if (!thread.visible) { if (!thread.visible) {
store.setForcedVisible(thread.id, true); this._store.setForcedVisible(thread.id, true);
} }
} }
return {
forceVisible,
};
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment