Skip to content

Commit

Permalink
fix: declare all variables before their usage
Browse files Browse the repository at this point in the history
This commits fixes the errors found by the no-use-before-define eslint rule, not all of these were
similar cases to the linked ticket as they were used in event handlers, but it's better to have the
rule than not

Fixes TIMOB-28401
  • Loading branch information
ewanharris authored and sgtcoolguy committed Mar 23, 2021
1 parent 8d4a7be commit 062c06d
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 53 deletions.
28 changes: 15 additions & 13 deletions cli/lib/webpack/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,20 @@ class WebpackService extends EventEmitter {
await this.subcribeToWebpackStatusChanges();

return new Promise((resolve, reject) => {
const showTimeoutInfo = () => {
const buildUrl = `${this.webUiUrl}/build/${this.jobIdentifier}`.cyan;
const logcatCommand = `${process.env.APPC_ENV ? 'appc ' : ''}appcd logcat "*webpack*"`;
this.logger.info('Did not receive any Webpack status updates in the last 30 seconds while waiting');
this.logger.info('for the build to complete.');
this.logger.info('');
this.logger.info(` - Open ${buildUrl.cyan} to see full build details`);
this.logger.info(` - Use ${'--force'.grey} to restart the Webpack build`);
this.logger.info(` - View Daemon logs from Webpack with ${logcatCommand.grey}`);
this.logger.info('');
const error = new Error('Timeout while waiting for the Webpack build to complete.');
reject(error);
};

const handler = e => {
if (e.state === STATE_READY || e.state === STATE_ERROR) {
this.off('status', handler);
Expand All @@ -240,19 +254,7 @@ class WebpackService extends EventEmitter {
return reject(new Error('Webpack compilation failed.'));
}
};
const showTimeoutInfo = () => {
const buildUrl = `${this.webUiUrl}/build/${this.jobIdentifier}`.cyan;
const logcatCommand = `${process.env.APPC_ENV ? 'appc ' : ''}appcd logcat "*webpack*"`;
this.logger.info('Did not receive any Webpack status updates in the last 30 seconds while waiting');
this.logger.info('for the build to complete.');
this.logger.info('');
this.logger.info(` - Open ${buildUrl.cyan} to see full build details`);
this.logger.info(` - Use ${'--force'.grey} to restart the Webpack build`);
this.logger.info(` - View Daemon logs from Webpack with ${logcatCommand.grey}`);
this.logger.info('');
const error = new Error('Timeout while waiting for the Webpack build to complete.');
reject(error);
};

this.on('status', handler);
this.on('timeout', showTimeoutInfo);
});
Expand Down
74 changes: 37 additions & 37 deletions common/Resources/ti.internal/extensions/node/slowbuffer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,43 @@
import { isBuffer } from './internal/util';
import { stringToHexBytes } from './internal/buffer';

// Use a Proxy to hack array style index accessors
const arrayIndexHandler = {
get(target, propKey, receiver) {
if (typeof propKey === 'string') {
const num = Number(propKey);
if (Number.isSafeInteger(num)) {
return getAdjustedIndex(target, num);
}
} else if (propKey === isBuffer) {
return true;
}
return Reflect.get(target, propKey, receiver);
},

set(target, propKey, value, receiver) {
if (typeof propKey === 'string') {
const num = Number(propKey);
if (Number.isSafeInteger(num)) {
setAdjustedIndex(target, num, value);
return true;
}
}
return Reflect.set(target, propKey, value, receiver);
},

has(target, key) {
if (typeof key === 'string') {
const num = Number(key);
if (Number.isSafeInteger(num)) {
// ensure it's a positive "safe" integer within the range of the buffer
return num >= 0 && num < target._tiBuffer.length;
}
}
return key in target;
}
};

// This is a special Buffer that wraps Ti.Buffer
// as a result it is *much* slower to read/write values
// because we need to go across the JS/Native boundary per-byte!
Expand Down Expand Up @@ -140,43 +177,6 @@ export default class SlowBuffer {
}
}

// Use a Proxy to hack array style index accessors
const arrayIndexHandler = {
get(target, propKey, receiver) {
if (typeof propKey === 'string') {
const num = Number(propKey);
if (Number.isSafeInteger(num)) {
return getAdjustedIndex(target, num);
}
} else if (propKey === isBuffer) {
return true;
}
return Reflect.get(target, propKey, receiver);
},

set(target, propKey, value, receiver) {
if (typeof propKey === 'string') {
const num = Number(propKey);
if (Number.isSafeInteger(num)) {
setAdjustedIndex(target, num, value);
return true;
}
}
return Reflect.set(target, propKey, value, receiver);
},

has(target, key) {
if (typeof key === 'string') {
const num = Number(key);
if (Number.isSafeInteger(num)) {
// ensure it's a positive "safe" integer within the range of the buffer
return num >= 0 && num < target._tiBuffer.length;
}
}
return key in target;
}
};

function getAdjustedIndex(buf, index) {
if (index < 0) {
return undefined;
Expand Down
3 changes: 2 additions & 1 deletion iphone/cli/commands/_build.js
Original file line number Diff line number Diff line change
Expand Up @@ -5776,6 +5776,8 @@ iOSBuilder.prototype.createAppIconSetAndiTunesArtwork = async function createApp
let defaultIconChanged = false;
let defaultIconHasAlpha = false;
const defaultIcon = this.defaultIcons.find(icon => fs.existsSync(icon));
const flattenedDefaultIconDest = path.join(this.buildDir, 'DefaultIcon.png');

if (defaultIcon) {
const defaultIconPrev = this.previousBuildManifest.files && this.previousBuildManifest.files['DefaultIcon.png'],
defaultIconContents = fs.readFileSync(defaultIcon),
Expand Down Expand Up @@ -5942,7 +5944,6 @@ iOSBuilder.prototype.createAppIconSetAndiTunesArtwork = async function createApp
missingIcons = missingIcons.concat(await this.processLaunchLogos(launchLogos, resourcesToCopy, defaultIcon, defaultIconChanged));

// Do we need to flatten the default icon?
const flattenedDefaultIconDest = path.join(this.buildDir, 'DefaultIcon.png');
if (missingIcons.length !== 0 && defaultIcon && defaultIconChanged && defaultIconHasAlpha) {
this.defaultIcons = [ flattenedDefaultIconDest ];
flattenIcons.push({
Expand Down
4 changes: 2 additions & 2 deletions tests/Resources/ti.ui.listview.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,8 @@ describe('Titanium.UI.ListView', function () {
extendEdges: [ Ti.UI.EXTEND_EDGE_ALL ]
});

const control = Ti.UI.createRefreshControl();

window.addEventListener('open', function () {
control.beginRefreshing();
});
Expand All @@ -1024,8 +1026,6 @@ describe('Titanium.UI.ListView', function () {
window: window
});

const control = Ti.UI.createRefreshControl();

const listView = Ti.UI.createListView({
refreshControl: control
});
Expand Down

0 comments on commit 062c06d

Please sign in to comment.