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.
This commit is contained in:
1 parent
d79a25aa1e
commit
2be8205aee
4 files changed
+10
-16
No files matched your search
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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 => ({
|
||||
|
||||
Reference in new issue
Block a user