package Ġcom . red uk s . red uk s Ċ Ċ import Ġcom . red uk s . red uk s . subscription . Subscriber Ċ import Ġcom . red uk s . red uk s . subscription . Subscription Ċ Ċ class ĠStore < State >( initialState : ĠState , Ġinitial Reducer : Ġ( state : ĠState , Ġaction : ĠAction < State >) Ġ-> ĠState , Ġen h ancer : ĠEn h ancer < State >? Ġ= Ġnull ) Ġ{ ĊĊĠĠĠ Ġprivate Ġval Ġsubscribers : ĠMutable List < Subscriber < State >> Ġ= Ġmutable ListOf () ĊĠĠĠ Ġprivate Ġvar Ġis Current Dispatch ing Ġ= Ġfalse ĊĠĠĠ Ġprivate Ġval Ġreducer : Ġ( state : ĠState , Ġaction : ĠAction < State >) Ġ-> ĠState Ġ= Ġen h ancer ?. en hance ( en hance Reducer With Dispatch ( initial Reducer ), Ġthis ) Ġ?: Ġenhance Reducer With Dispatch ( initial Reducer ) ĊĠĠĠ Ġprivate Ġvar Ġstate : ĠState Ġ= ĠinitialState ĊĊĠĠĠ Ġfun Ġsubscribe ( subscriber : ĠSubscriber < State >): ĠSubscription Ġ{ ĊĠĠĠĠĠĠĠ Ġsubscribers . add ( subscriber ) ĊĠĠĠĠĠĠĠ Ġreturn ĠSubscription Ġ{ Ġsubscribers . remove ( subscriber ) Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġdispatch ( action : ĠAction < State >) Ġ: ĠAction < State > Ġ{ ĊĠĠĠĠĠĠĠ Ġreducer ( state , Ġaction ) ĊĠĠĠĠĠĠĠ Ġreturn Ġaction ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun ĠgetState () Ġ: ĠState Ġ= Ġstate ĊĊĠĠĠ Ġprivate Ġfun Ġenhance Reducer With Dispatch ( reducer : Ġ( state : ĠState , Ġaction : ĠAction < State >) Ġ-> ĠState ): Ġ( state : ĠState , Ġaction : ĠAction < State >) Ġ-> ĠState Ġ= Ġ{ Ġstate , Ġaction Ġ-> ĊĠĠĠĠĠĠĠ Ġstart Dispatch ing () ĊĠĠĠĠĠĠĠ Ġthis . state Ġ= Ġreducer ( state , Ġaction ) ĊĠĠĠĠĠĠĠ Ġstop Dispatch ing () ĊĠĠĠĠĠĠĠ Ġnotify Sub scribers () ĊĠĠĠĠĠĠĠ Ġthis . state ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġnotify Sub scribers () Ġ{ ĊĠĠĠĠĠĠĠ Ġsubscribers . forEach Ġ{ Ġit . state Changed ( state ) Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġstart Dispatch ing () Ġ{ ĊĠĠĠĠĠĠĠ Ġif Ġ( is Current Dispatch ing ) Ġthrow ĠIllegalStateException (" You Ġcan 't Ġdispatch Ġinside Ġa Ġdispatch ") ĊĠĠĠĠĠĠĠ Ġis Current Dispatch ing Ġ= Ġtrue ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġstop Dispatch ing () Ġ{ ĊĠĠĠĠĠĠĠ Ġis Current Dispatch ing Ġ= Ġfalse ĊĠĠĠ Ġ} Ċ }