Skip to content

Commit 6262f06

Browse files
committed
Initialize input value from JSON but maintain it as jQuery data
1 parent 0e62607 commit 6262f06

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

srcjs/input.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)