Skip to content

Commit

Permalink
v-services type fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
erwinmombay committed Sep 8, 2016
1 parent b446588 commit f5f301f
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 17 deletions.
1 change: 0 additions & 1 deletion src/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ export class Log {
* @param {...*} var_args Arguments substituted into %s in the message.
* @return {T} The value of shouldBeTrueish.
* @template T
* @throws {Error}
*/
/*eslint "google-camelcase/google-camelcase": 0*/
assert(shouldBeTrueish, opt_message, var_args) {
Expand Down
6 changes: 3 additions & 3 deletions src/observable.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ export class Observable {

/**
* Fires an event. All observers are called.
* @param {TYPE} event
* @param {TYPE=} opt_event
*/
fire(event) {
fire(opt_event) {
const handlers = this.handlers_;
for (let i = 0; i < handlers.length; i++) {
const handler = handlers[i];
handler(event);
handler(opt_event);
}
}

Expand Down
25 changes: 17 additions & 8 deletions src/service/viewer-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export class Viewer {
/** @private {number} */
this.prerenderSize_ = 1;

/** @private {string} */
/** @private {ViewportType} */
this.viewportType_ = ViewportType.NATURAL;

/** @private {number} */
Expand Down Expand Up @@ -188,7 +188,7 @@ export class Viewer {
this.isRuntimeOn_ = !parseInt(this.params_['off'], 10);
dev().fine(TAG_, '- runtimeOn:', this.isRuntimeOn_);

this.overtakeHistory_ = parseInt(this.params_['history'], 10) ||
this.overtakeHistory_ = !!(parseInt(this.params_['history'], 10)) ||
this.overtakeHistory_;
dev().fine(TAG_, '- history:', this.overtakeHistory_);

Expand Down Expand Up @@ -237,6 +237,9 @@ export class Viewer {
// Wait for document to become visible.
this.docState_.onVisibilityChanged(this.recheckVisibilityState_.bind(this));

/** @private {function()|undefined} */
this.messagingReadyResolver_ = undefined;

/**
* This promise will resolve when communications channel has been
* established or timeout in 20 seconds. The timeout is needed to avoid
Expand All @@ -248,10 +251,10 @@ export class Viewer {
timerFor(this.win).timeoutPromise(
20000,
new Promise(resolve => {
/** @private @const {function()|undefined} */
this.messagingReadyResolver_ = resolve;
})).catch(reason => {
throw getChannelError(reason);
throw getChannelError(/** @type {!Error|string|undefined} */ (
reason));
}) : null;

/**
Expand All @@ -265,7 +268,8 @@ export class Viewer {
this.messagingReadyPromise_
.catch(reason => {
// Don't fail promise, but still report.
reportError(getChannelError(reason));
reportError(getChannelError(
/** @type {!Error|string|undefined} */ (reason)));
}) : null;

// Trusted viewer and referrer.
Expand All @@ -283,17 +287,22 @@ export class Viewer {
this.isTrustedViewerOrigin_(this.win.location.ancestorOrigins[0]));
trustedViewerPromise = Promise.resolve(trustedViewerResolved);
} else {

/** @private {!function(boolean)|undefined} */
this.trustedViewerResolver_ = undefined;
// Wait for comms channel to confirm the origin.
trustedViewerResolved = undefined;
trustedViewerPromise = new Promise(resolve => {
/** @const @private {!function(boolean)|undefined} */
this.trustedViewerResolver_ = resolve;
});
}

/** @const @private {!Promise<boolean>} */
this.isTrustedViewer_ = trustedViewerPromise;

/** @private {!function(string)|undefined} */
this.viewerOriginResolver_ = undefined;

/** @const @private {!Promise<string>} */
this.viewerOrigin_ = new Promise(resolve => {
if (!this.isEmbedded()) {
Expand Down Expand Up @@ -876,7 +885,7 @@ export class Viewer {
/**
* Requests AMP document to receive a message from Viewer.
* @param {string} eventType
* @param {*} data
* @param {!JSONType} data
* @param {boolean} unusedAwaitResponse
* @return {(!Promise<*>|undefined)}
* @export
Expand Down Expand Up @@ -1073,7 +1082,7 @@ function parseParams_(str, allParams) {

/**
* Creates an error for the case where a channel cannot be established.
* @param {!Error=} opt_reason
* @param {!Error|string=} opt_reason
* @return {!Error}
*/
function getChannelError(opt_reason) {
Expand Down
6 changes: 3 additions & 3 deletions src/service/viewport-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,8 +500,8 @@ export class Viewport {
return null;
}
if (this.viewportMeta_ === undefined) {
this.viewportMeta_ = this.win_.document.querySelector(
'meta[name=viewport]');
this.viewportMeta_ = /** @type {?HTMLMetaElement} */ (
this.win_.document.querySelector('meta[name=viewport]'));
if (this.viewportMeta_) {
this.originalViewportMetaString_ = this.viewportMeta_.content;
}
Expand Down Expand Up @@ -1253,7 +1253,7 @@ export function updateViewportMetaString(currentValue, updateParams) {
if (params[k] !== updateParams[k]) {
changed = true;
if (updateParams[k] !== undefined) {
params[k] = updateParams[k];
params[k] = /** @type {string} */ (updateParams[k]);
} else {
delete params[k];
}
Expand Down
2 changes: 1 addition & 1 deletion src/service/vsync-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export class Vsync {
* will be undefined.
*
* @param {!VsyncTaskSpecDef} task
* @param {VsyncStateDef=} opt_state
* @param {!VsyncStateDef=} opt_state
*/
run(task, opt_state) {
this.tasks_.push(task);
Expand Down
2 changes: 1 addition & 1 deletion src/service/xhr-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class Xhr {
if (opt_init && opt_init.responseType == 'document') {
return fetchPolyfill(input, opt_init);
}
return fetchPolyfill(input, opt_init);
return (this.win.fetch || fetchPolyfill).apply(null, arguments);
}

/**
Expand Down

0 comments on commit f5f301f

Please sign in to comment.