Skip to content

Commit

Permalink
make it so the dispatcher can be configured for different adapters
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlee committed Aug 30, 2023
1 parent fda9af7 commit 703ff84
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions src/dataLayerLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,37 @@ import * as H from './commandHandler'
import * as R from './entryRepository'
// import * as E from './entry'
import * as F from './fileStoreAdapter'
import * as M from './memoryStoreAdapter'

export function dispatcher() {
const adapter = new F.FileStoreAdapter('/tmp/hello')
import { DataStoreAdapter } from './dataStoreAdapter'

interface Configuration {
adapter: string,
path: string, // TODO fix typings
}

const defaults: Configuration = {
adapter: 'file',
path: `${process.env.HOME}/.config/projector/entries.json`
}
export function dispatcher(options = {}) {
const props: Configuration = {...defaults, ...options}
let adapter: DataStoreAdapter

switch(props.adapter) {
case 'file':
adapter = new F.FileStoreAdapter(props.path)
break
case 'memory':
adapter = new M.MemoryStoreAdapter()
break
default:
throw new Error('Illegal adapter')
}

const reader = new R.EntryReader(adapter)
const writer = new R.EntryWriter(adapter)

const handler = new H.CommandHandler(reader, writer)

return new D.Dispatcher(handler)
Expand Down

0 comments on commit 703ff84

Please sign in to comment.