package Ġcom . ark iv an ov . mv ik otlin . core . instance keeper Ċ Ċ import Ġcom . ark iv an ov . mv ik otlin . core . lifecycle . Lifecycle Ċ import Ġcom . ark iv an ov . mv ik otlin . core . lifecycle . do On Destroy Ċ import Ġcom . ark iv an ov . mv ik otlin . core . store . Store Ċ import Ġcom . ark iv an ov . mv ik otlin . ke e pers . instance keeper . Instance Keeper Ċ import Ġcom . ark iv an ov . mv ik otlin . core . instance keeper . Instance Keeper Ġas ĠOld Instance Keeper Ċ Ċ /** Ċ Ġ* ĠEither Ġreturns Ġa Ġcurrently Ġretained Ġinstance Ġor Ġcreates Ġ( and Ġret ains ) Ġa Ġnew Ġone . Ċ Ġ* Ċ Ġ* ĠSee Ġ[ Instance Keeper ] Ġfor Ġmore Ġinformation . Ċ Ġ* Ċ Ġ* Ġ@ param Ġfactory Ġa Ġfactory Ġfunction , Ġaccepts Ġthe Ġ[ Instance Keeper ]' s Ġ[ Lifecycle ], Ċ Ġ* Ġcalled Ġwhen Ġthere Ġis Ġno Ġretained Ġinstance Ġyet Ċ Ġ* Ġ@ return Ġeither Ġa Ġcurrently Ġretained Ġinstance Ġor Ġa Ġnew Ġone Ċ Ġ*/ Ċ @ Experimental Instance Keeper Api Ċ inline Ġfun Ġ< T Ġ: ĠAny > ĠOld Instance Keeper < T >. get OrCreate ( factory : Ġ( Lifecycle ) Ġ-> ĠT ): ĠT Ġ{ ĊĠĠĠ Ġcheck ( lifecycle . state Ġ!= ĠLifecycle . State . DESTROY ED ) Ġ{ Ġ" The ĠInstance Keeper Ġis Ġalready Ġdestroyed " Ġ} ĊĊĠĠĠ Ġreturn Ġinstance Ġ?: Ġfactory ( lifecycle ). also Ġ{ Ġinstance Ġ= Ġit Ġ} Ċ } Ċ Ċ /** Ċ Ġ* ĠEither Ġreturns Ġa Ġcurrently Ġretained Ġ[ Store ] Ġinstance Ġor Ġcreates Ġ( and Ġret ains ) Ġa Ġnew Ġone . Ċ Ġ* ĠThe Ġretained Ġ[ Store ] Ġis Ġautomatically Ġdisposed Ġat Ġthe Ġend Ġof Ġthe Ġ[ Instance Keeper ]' s Ġlifecycle . Ċ Ġ* Ċ Ġ* ĠSee Ġ[ Instance Keeper ] Ġfor Ġmore Ġinformation . Ċ Ġ* Ċ Ġ* Ġ@ param Ġfactory Ġa Ġfactory Ġfunction , Ġcalled Ġwhen Ġthere Ġis Ġno Ġretained Ġinstance Ġyet Ċ Ġ* Ġ@ return Ġeither Ġa Ġcurrently Ġretained Ġ[ Store ] Ġinstance Ġor Ġa Ġnew Ġone Ċ Ġ*/ Ċ @ Experimental Instance Keeper Api Ċ fun Ġ< T Ġ: ĠStore < *, Ġ*, Ġ* >> ĠOld Instance Keeper < T >. get OrCreate Store ( factory : Ġ() Ġ-> ĠT ): ĠT Ġ= ĊĠĠĠ Ġget OrCreate Ġ{ Ġlifecycle Ġ-> ĊĠĠĠĠĠĠĠ Ġval Ġstore Ġ= Ġfactory () ĊĠĠĠĠĠĠĠ Ġlifecycle . do On Destroy ( store :: dispose ) ĊĠĠĠĠĠĠĠ Ġstore ĊĠĠĠ Ġ} Ċ Ċ @ com . ark iv an ov . mv ik otlin . ke e pers . instance keeper . Experimental Instance Keeper Api Ċ fun Ġ< T Ġ: ĠStore < *, Ġ*, Ġ* >> ĠInstance Keeper . get Store ( key : ĠAny , Ġfactory : Ġ() Ġ-> ĠT ): ĠT Ġ= ĊĠĠĠ Ġget ( key ) Ġ{ ĊĠĠĠĠĠĠĠ ĠStore Instance ( factory ()) ĊĠĠĠ Ġ}. store Ċ Ċ @ com . ark iv an ov . mv ik otlin . ke e pers . instance keeper . Experimental Instance Keeper Api Ċ inline Ġfun Ġ< re ified ĠT Ġ: ĠStore < *, Ġ*, Ġ* >> ĠInstance Keeper . get Store ( no inline Ġfactory : Ġ() Ġ-> ĠT ): ĠT Ġ= Ġget Store ( T :: class , Ġfactory ) Ċ Ċ @ com . ark iv an ov . mv ik otlin . ke e pers . instance keeper . Experimental Instance Keeper Api Ċ private Ġclass ĠStore Instance < out ĠT Ġ: ĠStore < *, Ġ*, Ġ* >>( ĊĠĠĠ Ġval Ġstore : ĠT Ċ ) Ġ: ĠInstance Keeper . Instance Ġ{ ĊĠĠĠ Ġoverride Ġfun Ġon Destroy () Ġ{ ĊĠĠĠĠĠĠĠ Ġstore . dispose () ĊĠĠĠ Ġ} Ċ } Ċ