Skip to content

Commit

Permalink
First pass of prettier across entire codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
rsimha committed Apr 25, 2019
1 parent 3ce5546 commit 1d990a5
Show file tree
Hide file tree
Showing 1,614 changed files with 144,554 additions and 114,607 deletions.
33 changes: 20 additions & 13 deletions 3p/3d-gltf/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,15 @@ const loadThree = (global, cb) => {
const loadScriptCb = url => cb => loadScript(global, url, cb);
const loadThreeExample = examplePath =>
loadScriptCb(
'https://cdn.jsdelivr.net/npm/three@0.91/examples/js/' + examplePath);
'https://cdn.jsdelivr.net/npm/three@0.91/examples/js/' + examplePath
);

seq(
loadScriptCb(
'https://cdnjs.cloudflare.com/ajax/libs/three.js/91/three.js'),
parallel(
loadThreeExample('loaders/GLTFLoader.js'),
loadThreeExample('controls/OrbitControls.js'))
loadScriptCb('https://cdnjs.cloudflare.com/ajax/libs/three.js/91/three.js'),
parallel(
loadThreeExample('loaders/GLTFLoader.js'),
loadThreeExample('controls/OrbitControls.js')
)
)(cb);
};

Expand All @@ -65,16 +66,22 @@ export function gltfViewer(global) {
if (!e.lengthComputable) {
return;
}
nonSensitiveDataPostMessage('progress', dict({
'total': e.total,
'loaded': e.loaded,
}));
nonSensitiveDataPostMessage(
'progress',
dict({
'total': e.total,
'loaded': e.loaded,
})
);
},
onerror: err => {
user().error('3DGLTF', err);
nonSensitiveDataPostMessage('error', dict({
'error': (err || '').toString(),
}));
nonSensitiveDataPostMessage(
'error',
dict({
'error': (err || '').toString(),
})
);
},
});
listenParent(global, 'action', msg => {
Expand Down
88 changes: 46 additions & 42 deletions 3p/3d-gltf/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ import AnimationLoop from './animation-loop';

const CAMERA_DISTANCE_FACTOR = 1;
const CAMERA_FAR_FACTOR = 50;
const CAMERA_NEAR_FACTOR = .1;

const CAMERA_NEAR_FACTOR = 0.1;

export default class GltfViewer {
/**
Expand All @@ -45,8 +44,9 @@ export default class GltfViewer {

/** @private */
this.controls_ = new THREE.OrbitControls(
this.camera_,
this.renderer_.domElement);
this.camera_,
this.renderer_.domElement
);

/** @private */
this.scene_ = new THREE.Scene();
Expand All @@ -59,7 +59,7 @@ export default class GltfViewer {

/** @private */
this.ampInViewport_ =
options['initialIntersection']['intersectionRatio'] > 0;
options['initialIntersection']['intersectionRatio'] > 0;

/** @private */
this.setSize_ = this.setupSize_();
Expand All @@ -86,17 +86,20 @@ export default class GltfViewer {
* @private
*/
setModelRotation_(args) {
const xAngle = 'x' in args
? this.getModelRotationOnAxis_(args, 'x')
: this.model_.rotation.x;
const xAngle =
'x' in args
? this.getModelRotationOnAxis_(args, 'x')
: this.model_.rotation.x;

const yAngle = 'y' in args
? this.getModelRotationOnAxis_(args, 'y')
: this.model_.rotation.y;
const yAngle =
'y' in args
? this.getModelRotationOnAxis_(args, 'y')
: this.model_.rotation.y;

const zAngle = 'z' in args
? this.getModelRotationOnAxis_(args, 'z')
: this.model_.rotation.z;
const zAngle =
'z' in args
? this.getModelRotationOnAxis_(args, 'z')
: this.model_.rotation.z;

this.model_.rotation.set(xAngle, yAngle, zAngle);
this.animationLoop_.needsUpdate = true;
Expand Down Expand Up @@ -161,12 +164,12 @@ export default class GltfViewer {
*
* @private */
setupLight_() {
const amb = new THREE.AmbientLight(0xEDECD5, .5);
const amb = new THREE.AmbientLight(0xedecd5, 0.5);
const dir1 = new THREE.DirectionalLight(0xFFFFFF, .5);
const dir1 = new THREE.DirectionalLight(0xffffff, 0.5);
dir1.position.set(0, 5, 3);
const dir2 = new THREE.DirectionalLight(0xAECDD6, .4);
const dir2 = new THREE.DirectionalLight(0xaecdd6, 0.4);
dir2.position.set(-1, -2, 4);
const light = new THREE.Group();
Expand All @@ -188,12 +191,14 @@ export default class GltfViewer {
this.renderer_.gammaOutput = true;
this.renderer_.gammaFactor = 2.2;
this.renderer_.setPixelRatio(
Math.min(
this.options_['rendererSettings']['maxPixelRatio'],
devicePixelRatio));
Math.min(
this.options_['rendererSettings']['maxPixelRatio'],
devicePixelRatio
)
);
this.renderer_.setClearColor(
this.options_['rendererSettings']['clearColor'],
this.options_['rendererSettings']['clearAlpha']
this.options_['rendererSettings']['clearColor'],
this.options_['rendererSettings']['clearAlpha']
);
}
Expand Down Expand Up @@ -222,9 +227,9 @@ export default class GltfViewer {
this.camera_.far = sizeLength * CAMERA_FAR_FACTOR;
this.camera_.near = sizeLength * CAMERA_NEAR_FACTOR;
this.camera_.position.lerpVectors(
center,
bbox.max,
1 + CAMERA_DISTANCE_FACTOR
center,
bbox.max,
1 + CAMERA_DISTANCE_FACTOR
);
this.camera_.lookAt(center);

Expand All @@ -240,23 +245,22 @@ export default class GltfViewer {
loader.crossOrigin = true;

loader.load(
this.options_['src'],
/** @param {{scene: !THREE.Scene}} gltfData */
gltfData => {
this.setupCameraForObject_(gltfData.scene);
gltfData.scene.children
.slice()
.forEach(child => {
this.model_.add(child);
});

this.scene_.add(this.model_);

this.animationLoop_.needsUpdate = true;
this.handlers_.onload();
},
this.handlers_.onprogress,
this.handlers_.onerror);
this.options_['src'],
/** @param {{scene: !THREE.Scene}} gltfData */
gltfData => {
this.setupCameraForObject_(gltfData.scene);
gltfData.scene.children.slice().forEach(child => {
this.model_.add(child);
});

this.scene_.add(this.model_);

this.animationLoop_.needsUpdate = true;
this.handlers_.onload();
},
this.handlers_.onprogress,
this.handlers_.onerror
);
}

/** @private */
Expand Down
28 changes: 16 additions & 12 deletions 3p/3p.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,13 @@

// Note: loaded by 3p system. Cannot rely on babel polyfills.


import {devAssert, rethrowAsync, userAssert} from '../src/log';
import {hasOwn, map} from '../src/utils/object';
import {isArray} from '../src/types';


/** @typedef {function(!Window, !Object)} */
let ThirdPartyFunctionDef;


/**
* @const {!Object<ThirdPartyFunctionDef>}
* @visibleForTesting
Expand Down Expand Up @@ -83,8 +80,9 @@ export function run(id, win, data) {
*/
export function writeScript(win, url, opt_cb) {
/*eslint no-useless-concat: 0*/
win.document
.write('<' + 'script src="' + encodeURI(url) + '"><' + '/script>');
win.document.write(
'<' + 'script src="' + encodeURI(url) + '"><' + '/script>'
);
if (opt_cb) {
executeAfterWriteScript(win, opt_cb);
}
Expand Down Expand Up @@ -120,7 +118,7 @@ export function loadScript(win, url, opt_cb, opt_errorCb) {
export function nextTick(win, fn) {
const P = win.Promise;
if (P) {
P.resolve().then/*OK*/(fn);
P.resolve().then(/*OK*/ fn);
} else {
win.setTimeout(fn, 0);
}
Expand Down Expand Up @@ -231,8 +229,12 @@ export function validateData(data, mandatoryFields, opt_optionalFields) {
validateExactlyOne(data, field);
allowedFields = allowedFields.concat(field);
} else {
userAssert(data[field],
'Missing attribute for %s: %s.', data.type, field);
userAssert(
data[field],
'Missing attribute for %s: %s.',
data.type,
field
);
allowedFields.push(field);
}
}
Expand All @@ -248,10 +250,12 @@ export function validateData(data, mandatoryFields, opt_optionalFields) {
* @param {!Array<string>} alternativeFields
*/
function validateExactlyOne(data, alternativeFields) {
userAssert(alternativeFields.filter(field => data[field]).length === 1,
'%s must contain exactly one of attributes: %s.',
data.type,
alternativeFields.join(', '));
userAssert(
alternativeFields.filter(field => data[field]).length === 1,
'%s must contain exactly one of attributes: %s.',
data.type,
alternativeFields.join(', ')
);
}

/**
Expand Down
31 changes: 16 additions & 15 deletions 3p/ampcontext-integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {computeInMasterFrame} from './3p';
import {dev, user, userAssert} from '../src/log';
import {dict} from '../src/utils/object';


/**
* Returns the "master frame" for all widgets of a given type.
* This frame should be used to e.g. fetch scripts that can
Expand All @@ -31,8 +30,8 @@ import {dict} from '../src/utils/object';
*/
export function masterSelection(win, type) {
type = type.toLowerCase();
const configType = adConfig[type] &&
adConfig[type]['masterFrameAccessibleType'];
const configType =
adConfig[type] && adConfig[type]['masterFrameAccessibleType'];
// The master has a special name.
const masterName = 'frame_' + (configType || type) + '_master';
let master;
Expand All @@ -52,9 +51,7 @@ export function masterSelection(win, type) {
return master;
}


export class IntegrationAmpContext extends AbstractAmpContext {

/** @override */
isAbstractImplementation_() {
return false;
Expand All @@ -67,13 +64,14 @@ export class IntegrationAmpContext extends AbstractAmpContext {
updateDimensionsEnabled_() {
// Only make this available to selected embeds until the generic solution is
// available.
return (this.embedType_ === 'facebook'
|| this.embedType_ === 'twitter'
|| this.embedType_ === 'github'
|| this.embedType_ === 'mathml'
|| this.embedType_ === 'reddit'
|| this.embedType_ === 'yotpo'
|| this.embedType_ === 'embedly'
return (
this.embedType_ === 'facebook' ||
this.embedType_ === 'twitter' ||
this.embedType_ === 'github' ||
this.embedType_ === 'mathml' ||
this.embedType_ === 'reddit' ||
this.embedType_ === 'yotpo' ||
this.embedType_ === 'embedly'
);
}

Expand Down Expand Up @@ -132,9 +130,12 @@ export class IntegrationAmpContext extends AbstractAmpContext {
* @param {string} entityId See comment above for content.
*/
reportRenderedEntityIdentifier(entityId) {
this.client_.sendMessage('entity-id', dict({
'id': user().assertString(entityId),
}));
this.client_.sendMessage(
'entity-id',
dict({
'id': user().assertString(entityId),
})
);
}

/**
Expand Down
3 changes: 0 additions & 3 deletions 3p/ampcontext-lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,12 @@ import './polyfills'; // eslint-disable-line sort-imports-es6-autofix/sort-impor
import {AmpContext} from './ampcontext.js';
import {initLogConstructor, setReportError} from '../src/log';


initLogConstructor();


// TODO(alanorozco): Refactor src/error.reportError so it does not contain big
// transitive dependencies and can be included here.
setReportError(() => {});


/**
* If window.context does not exist, we must instantiate a replacement and
* assign it to window.context, to provide the creative with all the required
Expand Down
Loading

0 comments on commit 1d990a5

Please sign in to comment.