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';
/**
* @typedef ThreadProps
* @prop {Thread} thread
* @prop {Object} threadsService - Injected service
* @prop {import('../services/threads').ThreadsService} threadsService
*/
/**
......
......@@ -112,7 +112,7 @@ import sessionService from './services/session';
import { StreamFilter } from './services/stream-filter';
import streamerService from './services/streamer';
import tagsService from './services/tags';
import threadsService from './services/threads';
import { ThreadsService } from './services/threads';
import { ToastMessengerService } from './services/toast-messenger';
// Redux store.
......@@ -150,7 +150,7 @@ function startApp(config, appEl) {
.register('streamer', streamerService)
.register('streamFilter', StreamFilter)
.register('tags', tagsService)
.register('threadsService', threadsService)
.register('threadsService', ThreadsService)
.register('toastMessenger', ToastMessengerService)
.register('store', store);
......
import threadsService from '../threads';
import { ThreadsService } from '../threads';
const NESTED_THREADS = {
id: 'top',
......@@ -60,7 +60,7 @@ const NESTED_THREADS = {
],
};
describe('threadsService', () => {
describe('ThreadsService', () => {
let fakeStore;
let service;
......@@ -68,7 +68,7 @@ describe('threadsService', () => {
fakeStore = {
setForcedVisible: sinon.stub(),
};
service = threadsService(fakeStore);
service = new ThreadsService(fakeStore);
});
describe('#forceVisible', () => {
......
......@@ -2,8 +2,18 @@
* @typedef {import('../helpers/build-thread').Thread} Thread
*/
/**
* A service for performing operations related to the current set of threads.
*/
// @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
* "unhiding" a thread which is currently hidden by an applied search filter
......@@ -12,16 +22,12 @@ export default function threadsService(store) {
*
* @param {Thread} thread
*/
function forceVisible(thread) {
forceVisible(thread) {
thread.children.forEach(child => {
forceVisible(child);
this.forceVisible(child);
});
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