Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions src/containers/list-monitor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import React from 'react';
import VM from 'scratch-vm';
import {connect} from 'react-redux';
import {getEventXY} from '../lib/touch-utils';
import {getVariableValue, setVariableValue} from '../lib/variable-utils';
import ListMonitorComponent from '../components/monitor/list-monitor.jsx';

class ListMonitor extends React.Component {
Expand Down Expand Up @@ -46,9 +45,9 @@ class ListMonitor extends React.Component {
// Submit any in-progress value edits on blur
if (this.state.activeIndex !== null) {
const {vm, targetId, id: variableId} = this.props;
const newListValue = getVariableValue(vm, targetId, variableId);
const newListValue = vm.getVariableValue(targetId, variableId);
newListValue[this.state.activeIndex] = this.state.activeValue;
setVariableValue(vm, targetId, variableId, newListValue);
vm.setVariableValue(targetId, variableId, newListValue);
this.setState({activeIndex: null, activeValue: null});
}
}
Expand Down Expand Up @@ -82,11 +81,11 @@ class ListMonitor extends React.Component {
this.handleDeactivate(); // Submit in-progress edits
const newListItemValue = ''; // Enter adds a blank item
const newValueOffset = e.shiftKey ? 0 : 1; // Shift-enter inserts above
const listValue = getVariableValue(vm, targetId, variableId);
const listValue = vm.getVariableValue(targetId, variableId);
const newListValue = listValue.slice(0, previouslyActiveIndex + newValueOffset)
.concat([newListItemValue])
.concat(listValue.slice(previouslyActiveIndex + newValueOffset));
setVariableValue(vm, targetId, variableId, newListValue);
vm.setVariableValue(targetId, variableId, newListValue);
const newIndex = this.wrapListIndex(previouslyActiveIndex + newValueOffset, newListValue.length);
this.setState({
activeIndex: newIndex,
Expand All @@ -103,10 +102,10 @@ class ListMonitor extends React.Component {
e.preventDefault(); // Default would blur input, prevent that.
e.stopPropagation(); // Bubbling would activate, which will be handled here
const {vm, targetId, id: variableId} = this.props;
const listValue = getVariableValue(vm, targetId, variableId);
const listValue = vm.getVariableValue(targetId, variableId);
const newListValue = listValue.slice(0, this.state.activeIndex)
.concat(listValue.slice(this.state.activeIndex + 1));
setVariableValue(vm, targetId, variableId, newListValue);
vm.setVariableValue(targetId, variableId, newListValue);
const newActiveIndex = Math.min(newListValue.length - 1, this.state.activeIndex);
this.setState({
activeIndex: newActiveIndex,
Expand All @@ -117,8 +116,8 @@ class ListMonitor extends React.Component {
handleAdd () {
// Add button appends a blank value and switches to it
const {vm, targetId, id: variableId} = this.props;
const newListValue = getVariableValue(vm, targetId, variableId).concat(['']);
setVariableValue(vm, targetId, variableId, newListValue);
const newListValue = vm.getVariableValue(targetId, variableId).concat(['']);
vm.setVariableValue(targetId, variableId, newListValue);
this.setState({activeIndex: newListValue.length - 1, activeValue: ''});
}

Expand Down
3 changes: 1 addition & 2 deletions src/containers/slider-monitor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import bindAll from 'lodash.bindall';
import PropTypes from 'prop-types';
import React from 'react';
import VM from 'scratch-vm';
import {setVariableValue} from '../lib/variable-utils';
import {connect} from 'react-redux';

import SliderMonitorComponent from '../components/monitor/slider-monitor.jsx';
Expand All @@ -26,7 +25,7 @@ class SliderMonitor extends React.Component {
handleSliderUpdate (e) {
this.setState({value: Number(e.target.value)});
const {vm, targetId, id: variableId} = this.props;
setVariableValue(vm, targetId, variableId, Number(e.target.value));
vm.setVariableValue(targetId, variableId, Number(e.target.value));
}
render () {
const {
Expand Down
24 changes: 0 additions & 24 deletions src/lib/variable-utils.js

This file was deleted.