diff --git a/js/actionCreators.js b/js/actionCreators.js
index dcf4b4e1..36d507a3 100644
--- a/js/actionCreators.js
+++ b/js/actionCreators.js
@@ -303,10 +303,16 @@ export function setSkinFromUrl(url) {
return setSkinFromFile(skinFile);
}
-export function openFileDialog(fileInput) {
- fileInput.click();
- // No reducers currently respond to this.
- return { type: OPEN_FILE_DIALOG };
+export function openFileDialog() {
+ return dispatch => {
+ // Does this represent a memory leak somehow?
+ const fileInput = document.createElement("input");
+ fileInput.type = "file";
+ fileInput.addEventListener("change", e => {
+ dispatch(loadFilesFromReferences(e.target.files));
+ });
+ fileInput.click();
+ };
}
export function setEqBand(band, value) {
diff --git a/js/components/App.js b/js/components/App.js
index 3a26054a..35797ed7 100644
--- a/js/components/App.js
+++ b/js/components/App.js
@@ -15,15 +15,7 @@ const genWindowMap = {
const GEN_WINDOWS = ["AVS_WINDOW"];
-const App = ({
- media,
- fileInput,
- loading,
- closed,
- equalizer,
- playlist,
- openWindows
-}) => {
+const App = ({ media, loading, closed, equalizer, playlist, openWindows }) => {
if (closed) {
return null;
}
@@ -42,9 +34,9 @@ const App = ({
diff --git a/js/components/PlaylistWindow/index.js b/js/components/PlaylistWindow/index.js
index 109c73d8..8f4b9e50 100644
--- a/js/components/PlaylistWindow/index.js
+++ b/js/components/PlaylistWindow/index.js
@@ -163,7 +163,8 @@ class PlaylistWindow extends React.Component {
}
}
-const mapDispatchToProps = (dispatch, ownProps) => ({
+// TODO: Convert to object syntax
+const mapDispatchToProps = dispatch => ({
focusPlaylist: () =>
dispatch({
type: SET_FOCUSED_WINDOW,
@@ -172,7 +173,7 @@ const mapDispatchToProps = (dispatch, ownProps) => ({
play: () => dispatch(play()),
pause: () => dispatch(pause()),
stop: () => dispatch(stop()),
- openFileDialog: () => dispatch(openFileDialog(ownProps.fileInput)),
+ openFileDialog: () => dispatch(openFileDialog()),
close: () => dispatch({ type: TOGGLE_PLAYLIST_WINDOW }),
toggleShade: () => dispatch({ type: TOGGLE_PLAYLIST_SHADE_MODE }),
toggleVisualizerStyle: () => dispatch(toggleVisualizerStyle()),
diff --git a/js/hotkeys.js b/js/hotkeys.js
index 9080bbb4..c552bf94 100644
--- a/js/hotkeys.js
+++ b/js/hotkeys.js
@@ -22,7 +22,7 @@ import {
import { arraysAreEqual } from "./utils";
-export default function(fileInput, { dispatch }) {
+export default function(dispatch) {
let keylog = [];
const trigger = [
78, // N
@@ -72,7 +72,7 @@ export default function(fileInput, { dispatch }) {
dispatch(pause());
break;
case 76: // L
- dispatch(openFileDialog(fileInput));
+ dispatch(openFileDialog());
break;
case 82: // R
dispatch(toggleRepeat());
@@ -90,7 +90,7 @@ export default function(fileInput, { dispatch }) {
dispatch(previous());
break;
case 96: // numpad 0
- dispatch(openFileDialog(fileInput));
+ dispatch(openFileDialog());
break;
case 97: // numpad 1
dispatch(nextN(-10));
diff --git a/js/media/index.js b/js/media/index.js
index aefa5ba1..5707fb59 100644
--- a/js/media/index.js
+++ b/js/media/index.js
@@ -5,7 +5,7 @@ import BufferSource from "./bufferSource";
import ElementSource from "./elementSource";
export default class Media {
- constructor(fileInput) {
+ constructor() {
this._context = new (window.AudioContext || window.webkitAudioContext)();
this._callbacks = {
waiting: function() {},
@@ -18,7 +18,6 @@ export default class Media {
};
this._balance = 0;
this.name = null;
- this.fileInput = fileInput;
// The _source node has to be recreated each time it's stopped or
// paused, so we don't create it here. Instead we create this dummy
diff --git a/js/winamp.js b/js/winamp.js
index 908f1ff3..3da1ba74 100644
--- a/js/winamp.js
+++ b/js/winamp.js
@@ -6,11 +6,7 @@ import getStore from "./store";
import App from "./components/App";
import Hotkeys from "./hotkeys";
import Media from "./media";
-import {
- setSkinFromUrl,
- loadMediaFromUrl,
- loadFilesFromReferences
-} from "./actionCreators";
+import { setSkinFromUrl, loadMediaFromUrl } from "./actionCreators";
import { SET_AVALIABLE_SKINS } from "./actionTypes";
@@ -18,25 +14,17 @@ class Winamp {
constructor(options) {
this.options = options;
- this.fileInput = document.createElement("input");
- this.fileInput.type = "file";
- this.fileInput.style.display = "none";
-
- this.media = new Media(this.fileInput);
+ this.media = new Media();
this.store = getStore(this.media, this.options.__initialState);
}
render(node) {
render(
-
+
,
node
);
- this.fileInput.addEventListener("change", e => {
- this.store.dispatch(loadFilesFromReferences(e.target.files));
- });
-
if (this.options.initialTrack && this.options.initialTrack.url) {
this.store.dispatch(
loadMediaFromUrl(
@@ -54,7 +42,7 @@ class Winamp {
}
this.store.dispatch(setSkinFromUrl(this.options.initialSkin.url));
- new Hotkeys(this.fileInput, this.store);
+ new Hotkeys(this.store.dispatch);
}
}