Skip to content

Latest commit

 

History

History
21 lines (11 loc) · 492 Bytes

File metadata and controls

21 lines (11 loc) · 492 Bytes

An example of Dependency Injecttion using a functional approach.

type LoggingTool = (a: any) => void

const simpleLog: LoggingTool = a => console.log(a)

const logInitialiser = (loggingTool: LoggingTool) => (a: any) => loggingTool(a)

// Set up our logging tool...

const log = logInitialiser(simpleLog)

// Now we can log

log('hello world')

// In production, we may swap out simpleLog for something more sophisticated - but we don't need to change our log statements.