Skip to content

Commit

Permalink
chore: standarize Store structure a bit more
Browse files Browse the repository at this point in the history
  • Loading branch information
jstarpl committed Jan 16, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 79d0064 commit 6bc681d
Showing 2 changed files with 16 additions and 15 deletions.
2 changes: 0 additions & 2 deletions packages/apps/client/src/stores/AppStore.ts
Original file line number Diff line number Diff line change
@@ -39,12 +39,10 @@ class AppStoreClass {
}

onConnected = action('onConnected', () => {
console.log('Connected')
this.connected = true
})

onDisconnected = action('onDisconnected', () => {
console.log('Disconnected')
this.connected = false
})
}
29 changes: 16 additions & 13 deletions packages/apps/client/src/stores/RundownStore.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { observable, action, flow, makeObservable, IReactionDisposer, reaction } from 'mobx'
import { RundownPlaylistId } from '@sofie-prompter-editor/shared-model'
import { RundownPlaylist, RundownPlaylistId } from '@sofie-prompter-editor/shared-model'
import { APIConnection, AppStore } from './AppStore'
import { UIRundown } from '../model/UIRundown'
import { UIRundownEntry } from '../model/UIRundownEntry'
@@ -28,7 +28,6 @@ export class RundownStore {
reaction(
() => this.appStore.connected,
async (connected) => {
console.log('Connected is: ', connected)
if (!connected) return

await this.connection.playlist.subscribeToPlaylists()
@@ -39,27 +38,31 @@ export class RundownStore {
)
)

this.connection.playlist.on(
'created',
action((playlist) => {
const newRundownEntry = new UIRundownEntry(this, playlist._id)
this.allRundowns.set(newRundownEntry.id, newRundownEntry)
newRundownEntry.updateFromJson(playlist)
})
)
this.connection.playlist.on('created', this.onPlaylistCreated)
// Note: updated and removed events are handled by the UIRundownEntry's themselves
})

private onPlaylistCreated = action('onPlaylistCreated', (json: RundownPlaylist) => {
const existing = this.allRundowns.get(json._id)

if (!existing) {
const newRundownEntry = new UIRundownEntry(this, json._id)
this.allRundowns.set(newRundownEntry.id, newRundownEntry)
newRundownEntry.updateFromJson(json)
return
}

existing.updateFromJson(json)
})

loadAllUIRundownData = flow(function* (this: RundownStore) {
const playlists = yield this.connection.playlist.find()
// add UIRundownEntries to allRundowns

this.clearAllRundowns()

for (const playlist of playlists) {
const newRundownEntry = new UIRundownEntry(this, playlist._id)
this.allRundowns.set(newRundownEntry.id, newRundownEntry)
newRundownEntry.updateFromJson(playlist)
this.onPlaylistCreated(playlist)
}
})

0 comments on commit 6bc681d

Please sign in to comment.