Skip to content

Commit 2285179

Browse files
committed
Minor miscellaneous refactorings
1 parent df14cfb commit 2285179

File tree

2 files changed

+9
-15
lines changed

2 files changed

+9
-15
lines changed

lib/index.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,8 @@ var FileInput = function (_React$Component) {
4343

4444

4545
_this.handleChange = function (e) {
46-
var files = [];
47-
for (var i = 0; i < e.target.files.length; i++) {
48-
// Convert to Array.
49-
files.push(e.target.files[i]);
50-
}
46+
var files = Array.prototype.slice.call(e.target.files); // Convert into Array
47+
var readAs = (_this.props.as || 'url').toLowerCase();
5148

5249
// Build Promise List, each promise resolved by FileReader.onload.
5350
Promise.all(files.map(function (file) {
@@ -60,7 +57,7 @@ var FileInput = function (_React$Component) {
6057
};
6158

6259
// Read the file with format based on this.props.as.
63-
switch ((_this.props.as || 'url').toLowerCase()) {
60+
switch (readAs) {
6461
case 'binary':
6562
{
6663
reader.readAsBinaryString(file);
@@ -94,7 +91,7 @@ var FileInput = function (_React$Component) {
9491
};
9592

9693
var win = (typeof window === 'undefined' ? 'undefined' : _typeof(window)) === 'object' ? window : {};
97-
if ((typeof window === 'undefined' ? 'undefined' : _typeof(window)) === 'object' && (!win.File || !win.FileReader || !win.FileList || !win.Blob)) {
94+
if (!win.File || !win.FileReader || !win.FileList || !win.Blob) {
9895
console.warn('[react-file-reader-input] Some file APIs detected as not supported.' + ' File reader functionality may not fully work.');
9996
}
10097
return _this;

src/index.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,17 @@ export default class FileInput extends React.Component {
1414
super(props);
1515

1616
const win = typeof window === 'object' ? window : {};
17-
if ((typeof window === 'object') && (!win.File || !win.FileReader || !win.FileList || !win.Blob)) {
17+
if (!win.File || !win.FileReader || !win.FileList || !win.Blob) {
1818
console.warn(
1919
'[react-file-reader-input] Some file APIs detected as not supported.' +
2020
' File reader functionality may not fully work.'
2121
);
2222
}
2323
}
2424

25-
handleChange = e => {
26-
const files = [];
27-
for (let i = 0; i < e.target.files.length; i++) {
28-
// Convert to Array.
29-
files.push(e.target.files[i]);
30-
}
25+
handleChange = (e) => {
26+
const files = Array.prototype.slice.call(e.target.files); // Convert into Array
27+
const readAs = (this.props.as || 'url').toLowerCase();
3128

3229
// Build Promise List, each promise resolved by FileReader.onload.
3330
Promise.all(files.map(file => new Promise((resolve, reject) => {
@@ -39,7 +36,7 @@ export default class FileInput extends React.Component {
3936
};
4037

4138
// Read the file with format based on this.props.as.
42-
switch ((this.props.as || 'url').toLowerCase()) {
39+
switch (readAs) {
4340
case 'binary': {
4441
reader.readAsBinaryString(file);
4542
break;

0 commit comments

Comments
 (0)