Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

No browser globals 2 #10886

Closed
wants to merge 12 commits into from
Closed

Conversation

graingert
Copy link
Contributor

use injectable $window and $document instead.

  • This removes the private provider $$mdMetaProvider because it used to access document before it was available. Meta headers can only be changed via the $$mdMeta service.
  • This updates and deprecates $mdThemingProvider.enableBrowserColor() to queue up color changes and dispatch them in the actual service when $$mdMeta is available.
  • This adds support for defining panel presets with an injectable function for the case where you want to
    define a preset that sets attachTo: angular.element($document[0].body) inside a config function.
  • This replaces all alert() calls with $mdDialog.show($mdDialog.alert()...); calls

This depends on eslint to find the misuse of global variables: #10824

What are $window and $document?

According to the AngularJS documentation: https://docs.angularjs.org/api/ng/service/$window

A reference to the browser's window object. While window is globally available in JavaScript, it causes testability problems, because it is a global variable. In AngularJS we always refer to it through the $window service, so it may be overridden, removed or mocked for testing.

$document is similar

Why is this needed?

  • Before $window, window and document, $document were being used interchangeably, this PR ensures consistency.
  • using an injectable $window and $document allows ...

@googlebot googlebot added the cla: yes PR author has signed Google's CLA: https://opensource.google.com/docs/cla/ label Sep 5, 2017
@graingert
Copy link
Contributor Author

This is a temporary PR while waiting for #10826 to re-open

you can't inject $document into a Provider

it's private and only used in theming to set browser color.

Updated $mdThemingProvider.enableBrowserColor() to queue up color
changes and dispatch them in the actual service.
relay on per application state.
Angular code should not use global state, it should be managed by
providers.

expose isDisabled() etc on $mdTheming
remove theme disabling logic from md-themes-disabled directive
  (it has no effect after generateAllThemes is run, because that's the
   only location that reads themeConfig.disableTheming)
check $document for md-themes-disabled in generateAllThemes.
@graingert
Copy link
Contributor Author

closing in favor of #10826

@graingert graingert closed this Nov 20, 2017
@graingert graingert deleted the no-browser-globals-2 branch November 20, 2017 10:35
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes PR author has signed Google's CLA: https://opensource.google.com/docs/cla/
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants