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

Allow passing optional window into getMode #4057

Merged
merged 9 commits into from Jul 18, 2016

Conversation

jridgewell
Copy link
Contributor

Separated from #4037 on @dvoytenko's suggestion.

Allows the win context to be (optionally) passed into getMode. This important for use in ServiceWorkers since they do not have a window variable.

export function getMode() {
if (mode) {
return mode;
export function getMode(opt_win) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this have any effect on us being able to DCE this code?

/cc @erwinmombay

@dvoytenko
Copy link
Contributor

This is LGTM as soon as @erwinmombay confirms no problems with DCE.

@erwinmombay
Copy link
Member

i tested this out, LGTM

@jridgewell
Copy link
Contributor Author

Can anyone help me with the type errors?

src/mode.js:46: WARNING - parameter win does not appear in getMode$$module$src$mode's parameter list
export function getMode(opt_win) {
       ^
build/experiments/experiments.max.js:130: ERROR - Function module$src$mode.getMode: called with 0 argument(s). Function requires at least 1 argument(s) and no more than 1 argument(s).
if (getMode().localDev) {
    ^
src/log.js:73: ERROR - Function module$src$mode.getMode: called with 0 argument(s). Function requires at least 1 argument(s) and no more than 1 argument(s).
    this.win = (getMode().test && win.AMP_TEST_IFRAME) ? win.parent : win;
                ^
src/log.js:96: ERROR - Function module$src$mode.getMode: called with 0 argument(s). Function requires at least 1 argument(s) and no more than 1 argument(s).
    if (getMode().log == '0') {
        ^
src/log.js:101: ERROR - Function module$src$mode.getMode: called with 0 argument(s). Function requires at least 1 argument(s) and no more than 1 argument(s).
    if (getMode().test && this.win.ENABLE_LOG) {
        ^
src/log.js:106: ERROR - Function module$src$mode.getMode: called with 0 argument(s). Function requires at least 1 argument(s) and no more than 1 argument(s).
    if (getMode().localDev && !getMode().log) {
        ^
src/log.js:106: ERROR - Function module$src$mode.getMode: called with 0 argument(s). Function requires at least 1 argument(s) and no more than 1 argument(s).
    if (getMode().localDev && !getMode().log) {
                               ^
src/log.js:111: ERROR - Function module$src$mode.getMode: called with 0 argument(s). Function requires at least 1 argument(s) and no more than 1 argument(s).
    return this.levelFunc_(getMode());
                           ^

@erwinmombay
Copy link
Member

looking

@@ -43,59 +40,57 @@ let fullVersion = '';

/**
* Provides info about the current app.
* @param {?Window=} win
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just need to change this into opt_win (the name)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😳

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doing that though seems to make it type check more modules which we haven't fixed yet O_O

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nvm, i ran the command wrong 💨

@jridgewell jridgewell closed this Jul 18, 2016
@jridgewell jridgewell reopened this Jul 18, 2016
@jridgewell jridgewell force-pushed the mode-opt_win branch 2 times, most recently from 5a18922 to 437545c Compare July 18, 2016 21:09
@jridgewell jridgewell merged commit 09970ae into ampproject:master Jul 18, 2016
@jridgewell jridgewell deleted the mode-opt_win branch July 18, 2016 22:14
ariangibson pushed a commit to Mixpo/amphtml that referenced this pull request Sep 7, 2016
* Allow passing optional window into getMode

* Cache mode on the window object

Instead of some magical private global.

* Fix tests

* Fix isLocalDev detection

* Tests

* Linting

* Stupid type checking

* Fix presubmit error

* Fix lingering tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants