Skip to content

Commit

Permalink
Merge 54ffe69 into ee4cc34
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas-P committed Feb 1, 2018
2 parents ee4cc34 + 54ffe69 commit 509eaf0
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,18 @@ export interface RecordOfflineStore {
delete: (recordName: string, callback: offlineStoreWriteResponse) => void
}

export interface Services {
export interface UninitializedServices {
logger: Logger
connection: Connection
timeoutRegistry: TimeoutRegistry
timerRegistry: TimerRegistry
socketFactory: SocketFactory
storage: RecordOfflineStore
}

export interface Services extends UninitializedServices {
connection: Connection
timeoutRegistry: TimeoutRegistry
}

export class Client extends EventEmitter {
public event: EventHandler
public rpc: RPCHandler
Expand All @@ -41,17 +44,21 @@ export class Client extends EventEmitter {
constructor (url: string, options: any = {}) {
super()
this.options = Object.assign({}, DefaultOptions, options)
const services: any = {}
services.storage = options.storage || new Storage(this.options)
services.logger = new Logger(this)
services.timerRegistry = new TimerRegistry()
services.timeoutRegistry = new TimeoutRegistry(services, this.options)
services.socketFactory = options.socketFactory || socketFactory
services.connection = new Connection(services, this.options, url, this)
this.services = services as Services
let services: UninitializedServices = {
storage: options.storage || new Storage(this.options),
logger: new Logger(this),
timerRegistry: new TimerRegistry(),
socketFactory: options.socketFactory || socketFactory,
}
// @todo -> remove dependency on the own service object
// @todo use a factory method instead and remove as Services, to be clear with constraint
services = this.services = Object.assign(services, {
timeoutRegistry: new TimeoutRegistry(services as Services, this.options),
connection: new Connection(services as Services, this.options, url, this),
})

this.services.connection.onLost(
services.timeoutRegistry.onConnectionLost.bind(services.timeoutRegistry)
this.services.timeoutRegistry.onConnectionLost.bind(this.services.timeoutRegistry)
)

this.event = new EventHandler(this.services, this.options)
Expand Down

0 comments on commit 509eaf0

Please sign in to comment.