Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | 1x 1x 1x 3x 1x 1x 3x 1x | import IClock from './IClock' // use whichever clock factory is exported from clockFactories import ClockFactory from './clockFactories' export class SingletonClockFactory0 { private static theClock : IClock private constructor () {SingletonClockFactory0.theClock = undefined} public static instance () : IClock { Iif (SingletonClockFactory0.theClock === undefined) { SingletonClockFactory0.theClock = (new ClockFactory).instance() } return SingletonClockFactory0.theClock } } // the solution above depends on the fact that in TS, 'undefined' is a value. // here's a solution that doesn't depend on that language property export class SingletonClockFactory { private static isInitialized : boolean private constructor() {SingletonClockFactory.isInitialized = false} private static theClock : IClock public static instance () : IClock { if (!(SingletonClockFactory.isInitialized)) { SingletonClockFactory.theClock = (new ClockFactory).instance() SingletonClockFactory.isInitialized = true } return SingletonClockFactory.theClock } } export default SingletonClockFactory |