@@ -67,13 +67,17 @@ export function reactShinyInput(selector,
6767 this . getCallback ( el ) ( ) ;
6868 this . render ( el ) ;
6969 }
70+ initialize ( el ) {
71+ $ ( el ) . data ( 'value' , JSON . parse ( $ ( el ) . next ( ) . text ( ) ) ) ;
72+ $ ( el ) . data ( 'configuration' , JSON . parse ( $ ( el ) . next ( ) . next ( ) . text ( ) ) ) ;
73+ }
7074 subscribe ( el , callback ) {
7175 $ ( el ) . data ( 'callback' , callback ) ;
7276 this . render ( el ) ;
7377 }
7478 unsubscribe ( el , callback ) {
75- // TODO at a minimum, 'undo' subscribe() actions (remove callback from data)
76- // Figure out the right way to un- render the component
79+ $ ( el ) . removeData ( ' callback' ) ;
80+ ReactDOM . render ( null , el ) ;
7781 }
7882 receiveMessage ( el , data ) {
7983 options . receiveMessage . call ( this , el , data ) ;
@@ -84,19 +88,17 @@ export function reactShinyInput(selector,
8488 * through `this` in receiveMessage
8589 * */
8690
87- // TODO Initialize value and config in initialize() method, don't sync back
88- // to DOM
8991 getInputValue ( el ) {
90- return JSON . parse ( $ ( el ) . next ( ) . text ( ) ) ;
92+ return $ ( el ) . data ( 'value' ) ;
9193 }
9294 setInputValue ( el , value ) {
93- $ ( el ) . next ( ) . text ( JSON . stringify ( value ) ) ;
95+ $ ( el ) . data ( ' value' , value ) ;
9496 }
9597 getInputConfiguration ( el ) {
96- return JSON . parse ( $ ( el ) . next ( ) . next ( ) . text ( ) ) ;
98+ return $ ( el ) . data ( 'configuration' ) ;
9799 }
98- setInputConfiguration ( el , value ) {
99- $ ( el ) . next ( ) . next ( ) . text ( JSON . stringify ( value ) ) ;
100+ setInputConfiguration ( el , configuration ) {
101+ $ ( el ) . data ( 'configuration' , configuration ) ;
100102 }
101103 getCallback ( el ) {
102104 return $ ( el ) . data ( 'callback' ) ;
0 commit comments