-
Notifications
You must be signed in to change notification settings - Fork 3.4k
fix(all): remove all direct use of browser globals #10826
Conversation
da46b1f
to
0857fdb
Compare
c1939ec
to
2d0bfea
Compare
1f158f9
to
dbe7650
Compare
@jelbourn @tinayuangao I rebased this on master just now. |
db24910
to
fe7f6e4
Compare
@mgol in reply to your comment #10824 (comment) this builds on #10824 if you merge that, those unrelated commits will disappear |
That is indeed how I've split the PRs. |
@ThomasBurleson @EladBezalel any chance of a review here? |
@graingert: it looks like there are lots of other commits in this PR. Can you fix this? |
@graingert: I know, but I think the PR's will not get pulled before they are cleaned up... |
@Frank3K these PRs are clean. They just depend on each other. |
@graingert - This PR will not be accepted because the scope of the changes are too broad. |
@ThomasBurleson can you have a look at #10824 when that's merged it will automatically unbroarden this pr |
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.
58 failing tests
4e4befd
to
d88aab9
Compare
@Splaktar well I've rebased it |
@Splaktar ok so all the tests pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made it about halfway through reviewing this. Many of the changes are harmless, but there are a number of cases where issues pop up.
In those cases, I observed exceptions in the demos that need to be resolved.
Please address the issues that I called out, manually re-test all demos that had either a demo change or component change, and then let me know and I'll review again.
@@ -18,7 +18,7 @@ | |||
</md-item-template> | |||
<md-not-found> | |||
No states matching "{{ctrl.searchText}}" were found. | |||
<a ng-click="ctrl.newState(ctrl.searchText)">Create a new one!</a> | |||
<md-button ng-click="ctrl.newState(ctrl.searchText, $event)">Create a new one!</md-button> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$mdDialog.show( | ||
$mdDialog | ||
.alert() | ||
.title('state creation failed.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's completely remove the concept of a link or button in the md-not-found
, and thus this newState()
function for this demo.
} | ||
|
||
return function($document, $q, $window) { | ||
if (prom) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does prom
stand for? Perhaps this can be renamed to be more clear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
promise
var self = this; | ||
var pendingSearch, cancelSearch = angular.noop; | ||
var lastSearch; | ||
|
||
self.allContacts = loadContacts(); | ||
loader($document, $q, $window).then(function (CryptoJS) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This throws:
TypeError: Cannot read property 'then' of undefined
at DemoCtrl (docs-demo-scripts.js:589)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Urgh, probably a missing return
@@ -400,7 +403,7 @@ function ConfigurationItem(url, viewBoxSize) { | |||
*/ | |||
|
|||
/* @ngInject */ | |||
function MdIconService(config, $templateRequest, $q, $log, $mdUtil, $sce) { | |||
function mdIconService(config, $templateRequest, $q, $log, $mdUtil, $sce, $window) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did the casing of the name need to change here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably a rebase error
this.selected.favoriteDessert = dessert; | ||
this._mdPanelRef && this._mdPanelRef.close().then(function() { | ||
angular.element(document.querySelector('.demo-menu-open-button')).focus(); | ||
angular.element($document[0].querySelector('.demo-menu-open-button')).focus(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This throws
TypeError: Cannot read property '0' of undefined
at docs-demo-scripts.js:2220
@@ -6,7 +6,7 @@ angular.module('panelAnimationsDemo', ['ngMaterial']) | |||
.controller('DialogCtrl', DialogCtrl); | |||
|
|||
|
|||
function AnimationCtrl($mdPanel) { | |||
function AnimationCtrl($mdPanel, $document) { | |||
this._mdPanel = $mdPanel; | |||
this.openFrom = 'button'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opening the dialog throws
TypeError: Cannot read property '0' of undefined
at AnimationCtrl.showDialog (docs-demo-scripts.js:2440)
@@ -1204,12 +1204,19 @@ MdPanelService.prototype.open = function(preset, config) { | |||
* @returns {!Object} The preset configuration object. | |||
*/ | |||
MdPanelService.prototype._getPresetByName = function(preset) { | |||
if (!this._presets[preset]) { | |||
var $injector = this._$injector; | |||
var v = this._presets[preset]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does v
stand for? Can you please give this a more meaningful name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's an arbitrary value because I didn't know what it was for.
Maybe the preset -> presetName and v -> preset?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds good. It is much more clear.
.alert() | ||
.title('Action') | ||
.textContent('submit') | ||
.event($event) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This throws
TypeError: $mdDialog.alert(...).title(...).textContent(...).event is not a function
at m.$scope.submit (docs-demo-scripts.js:2746)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm probably not understanding how $mdDialog works here, would be good for an angular material dev to take a look, please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's .targetEvent($event)
* Change the selected date in the calendar (ngModel value has already been changed). | ||
* @param {Date} date | ||
*/ | ||
CalendarMonthCtrl.prototype.changeSelectedDate = function(date) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where did this come from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I probably resurrected this by accident in a rebase
The |
@Splaktar can you take over this PR and make those changes? I'm not using AngularJS anymore so don't have much time to work on this |
OK, I'll look into creating a new PR, which I'll need you to post in to grant approval to use your commits. I probably won't have time to do this real soon. Thank you for getting a start here though. |
@Splaktar I've enabled edits to this PR from maintainers, so you should be able to push to this branch |
Thank you for all of the work on this effort. Unfortunately, this has been determined to be too risky to try to get merged at this point. |
use injectable $window and $document instead.
document
before it was available. Meta headers can only be changed via the $$mdMeta service.define a preset that sets
attachTo: angular.element($document[0].body)
inside a config function.$mdDialog.show($mdDialog.alert()...);
callsThis 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
$document is similar
Why is this needed?