From 2be8205aeebee78dc27f2488ea35d773dcb98e1e Mon Sep 17 00:00:00 2001 From: Christopher Willis-Ford Date: Thu, 23 Mar 2017 11:58:07 -0700 Subject: [PATCH] Move scratch-storage init/attach to vmListenerHOC Attaching the storage module in `vmListenerHOC` means it can propagate down to the GUI, stage, and blocks naturally. The default VM property value has been removed from those places so that we're not instantiating extra VM instances any more. Instead, using one of those components outside of the `vmListenerHOC` framework will require providing a VM instance as a property. --- src/components/gui/gui.jsx | 9 ++------- src/containers/blocks.jsx | 5 ++--- src/containers/stage.jsx | 6 +----- src/lib/vm-listener-hoc.jsx | 6 +++++- 4 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/components/gui/gui.jsx b/src/components/gui/gui.jsx index 4ef85e06f..aad6c62cd 100644 --- a/src/components/gui/gui.jsx +++ b/src/components/gui/gui.jsx @@ -11,8 +11,6 @@ const MenuBar = require('../menu-bar/menu-bar.jsx'); const Box = require('../box/box.jsx'); const styles = require('./gui.css'); -const Storage = require('../../lib/storage'); - const GUIComponent = props => { const { basePath, @@ -72,12 +70,9 @@ const GUIComponent = props => { GUIComponent.propTypes = { basePath: React.PropTypes.string, children: React.PropTypes.node, - vm: React.PropTypes.instanceOf(VM) + vm: React.PropTypes.instanceOf(VM).isRequired }; GUIComponent.defaultProps = { - basePath: '/', - vm: new VM(), - storage: new Storage() + basePath: '/' }; -GUIComponent.defaultProps.vm.attachStorage(GUIComponent.defaultProps.storage); module.exports = GUIComponent; diff --git a/src/containers/blocks.jsx b/src/containers/blocks.jsx index 200f0a92d..b5f979853 100644 --- a/src/containers/blocks.jsx +++ b/src/containers/blocks.jsx @@ -159,7 +159,7 @@ Blocks.propTypes = { dragShadowOpacity: React.PropTypes.number }) }), - vm: React.PropTypes.instanceOf(VM) + vm: React.PropTypes.instanceOf(VM).isRequired }; Blocks.defaultOptions = { @@ -188,8 +188,7 @@ Blocks.defaultOptions = { }; Blocks.defaultProps = { - options: Blocks.defaultOptions, - vm: new VM() + options: Blocks.defaultOptions }; module.exports = Blocks; diff --git a/src/containers/stage.jsx b/src/containers/stage.jsx index 3f693b78c..e5e0c0602 100644 --- a/src/containers/stage.jsx +++ b/src/containers/stage.jsx @@ -175,11 +175,7 @@ class Stage extends React.Component { } Stage.propTypes = { - vm: React.PropTypes.instanceOf(VM) -}; - -Stage.defaultProps = { - vm: new VM() + vm: React.PropTypes.instanceOf(VM).isRequired }; module.exports = Stage; diff --git a/src/lib/vm-listener-hoc.jsx b/src/lib/vm-listener-hoc.jsx index 87c76c56a..7ddb6493a 100644 --- a/src/lib/vm-listener-hoc.jsx +++ b/src/lib/vm-listener-hoc.jsx @@ -2,6 +2,8 @@ const bindAll = require('lodash.bindall'); const React = require('react'); const VM = require('scratch-vm'); +const Storage = require('./storage'); + const {connect} = require('react-redux'); const targets = require('../reducers/targets'); @@ -89,9 +91,11 @@ const vmListenerHOC = function (WrappedComponent) { onTargetsUpdate: React.PropTypes.func, vm: React.PropTypes.instanceOf(VM).isRequired }; + const defaultVM = new VM('vm-listener-hoc'); + defaultVM.attachStorage(new Storage()); VMListener.defaultProps = { attachKeyboardEvents: true, - vm: new VM() + vm: defaultVM }; const mapStateToProps = () => ({}); const mapDispatchToProps = dispatch => ({