import { create } from '@dojo/framework/core/vdom' ; import { createICacheMiddleware } from '@dojo/framework/core/middleware/icache' ; interface RadioGroupICache { initial : string ; value : string ; } const icache = createICacheMiddleware < RadioGroupICache > ( ) ; const factory = create ( { icache } ) ; export const radioGroup = factory ( ( { middleware : { icache } } ) => { return ( onValue , initialValue , value ? ) => { if ( value === undefined ) { const existingInitialValue = icache . get ( 'initial' ) ; if ( existingInitialValue !== initialValue ) { icache . set ( 'value' , initialValue ) ; icache . set ( 'initial' , initialValue ) ; } } return ( key ) => { function checked ( ) ; function checked ( checked ) ; function checked ( checked ? ) { const existingValue = value === undefined ? icache . get ( 'value' ) : value ; if ( checked === undefined ) { return existingValue === key ; } else if ( checked && existingValue !== key ) { icache . set ( 'value' , key ) ; onValue ( key ) ; } } return { checked } ; } ; } ; } ) ;