Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

services type fixes #4249

Merged
merged 2 commits into from
Sep 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -884,7 +893,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 @@ -1081,7 +1090,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