Skip to content

Commit 39a6f63

Browse files
committed
keep refactoring to encapsulate app state
1 parent fbf4627 commit 39a6f63

2 files changed

Lines changed: 33 additions & 40 deletions

File tree

‎v3/js/opt-frontend-common.js‎

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -61,25 +61,16 @@ var rawInputLst = []; // a list of strings inputted by the user in response to r
6161

6262
function getQueryStringOptions() {
6363
// note that any of these can be 'undefined'
64-
var preseededCode = $.bbq.getState('code');
65-
var preseededCurInstr = Number($.bbq.getState('curInstr'));
66-
var pyState = $.bbq.getState('py');
67-
var verticalStack = $.bbq.getState('verticalStack');
68-
var heapPrimitives = $.bbq.getState('heapPrimitives');
69-
var drawParentPointers = $.bbq.getState('drawParentPointers');
70-
var textRefs = $.bbq.getState('textReferences');
71-
var showOnlyOutputs = $.bbq.getState('showOnlyOutputs');
72-
var cumulativeState = $.bbq.getState('cumulative');
73-
74-
return {preseededCode: preseededCode,
75-
preseededCurInstr: preseededCurInstr,
76-
pyState: pyState,
77-
verticalStack: verticalStack,
78-
heapPrimitives: heapPrimitives,
79-
drawParentPointers: drawParentPointers,
80-
textRefs: textRefs,
81-
showOnlyOutputs: showOnlyOutputs,
82-
cumulativeState: cumulativeState};
64+
return {preseededCode: $.bbq.getState('code'),
65+
preseededCurInstr: Number($.bbq.getState('curInstr')),
66+
verticalStack: $.bbq.getState('verticalStack'),
67+
py: $.bbq.getState('py'),
68+
cumulative: $.bbq.getState('cumulative'),
69+
heapPrimitives: $.bbq.getState('heapPrimitives'),
70+
drawParentPointers: $.bbq.getState('drawParentPointers'),
71+
textReferences: $.bbq.getState('textReferences'),
72+
showOnlyOutputs: $.bbq.getState('showOnlyOutputs'),
73+
};
8374
}
8475

8576

‎v3/js/opt-frontend.js‎

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,28 @@ function getAppState() {
7373
py: $('#pythonVersionSelector').val()};
7474
}
7575

76+
function setToggleOptions(dat) {
77+
// ugh, ugly tristate due to the possibility of each being undefined
78+
if (dat.py !== undefined) {
79+
$('#pythonVersionSelector').val(dat.py);
80+
}
81+
if (dat.cumulative !== undefined) {
82+
$('#cumulativeModeSelector').val(dat.cumulative);
83+
}
84+
if (dat.heapPrimitives !== undefined) {
85+
$('#heapPrimitivesSelector').val(dat.heapPrimitives);
86+
}
87+
if (dat.drawParentPointers !== undefined) {
88+
$('#drawParentPointerSelector').val(dat.drawParentPointers);
89+
}
90+
if (dat.textReferences !== undefined) {
91+
$('#textualMemoryLabelsSelector').val(dat.textReferences);
92+
}
93+
if (dat.showOnlyOutputs !== undefined) {
94+
$('#showOnlyOutputsSelector').val(dat.showOnlyOutputs);
95+
}
96+
}
97+
7698
$(document).ready(function() {
7799
setSurveyHTML();
78100

@@ -526,6 +548,7 @@ $(document).ready(function() {
526548

527549

528550
var queryStrOptions = getQueryStringOptions();
551+
setToggleOptions(queryStrOptions);
529552

530553
if (queryStrOptions.preseededCode) {
531554
setCodeMirrorVal(queryStrOptions.preseededCode);
@@ -535,27 +558,6 @@ $(document).ready(function() {
535558
$("#aliasExampleLink").trigger('click');
536559
}
537560

538-
// ugh, ugly tristate due to the possibility of each being undefined
539-
if (queryStrOptions.pyState !== undefined) {
540-
$('#pythonVersionSelector').val(queryStrOptions.pyState);
541-
}
542-
if (queryStrOptions.cumulativeState !== undefined) {
543-
$('#cumulativeModeSelector').val(queryStrOptions.cumulativeState);
544-
}
545-
if (queryStrOptions.heapPrimitives !== undefined) {
546-
$('#heapPrimitivesSelector').val(queryStrOptions.heapPrimitives);
547-
}
548-
if (queryStrOptions.drawParentPointers !== undefined) {
549-
$('#drawParentPointerSelector').val(queryStrOptions.drawParentPointers);
550-
}
551-
if (queryStrOptions.textRefs !== undefined) {
552-
$('#textualMemoryLabelsSelector').val(queryStrOptions.textRefs);
553-
}
554-
if (queryStrOptions.showOnlyOutputs !== undefined) {
555-
$('#showOnlyOutputsSelector').val(queryStrOptions.showOnlyOutputs);
556-
}
557-
558-
559561
appMode = $.bbq.getState('mode'); // assign this to the GLOBAL appMode
560562
if ((appMode == 'display' || appMode == 'visualize' /* 'visualize' is deprecated */) &&
561563
queryStrOptions.preseededCode /* jump to display only with pre-seeded code */) {

0 commit comments

Comments
 (0)