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

Commit b328882

Browse files
ThomasBurlesonjelbourn
authored andcommitted
fix(theming): fix read-only .configuration() (#9389)
1 parent 1d46315 commit b328882

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

src/core/services/theming/theming.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,10 +328,15 @@ function ThemingProvider($mdColorPalette, $$mdMetaProvider) {
328328
extendPalette: extendPalette,
329329
theme: registerTheme,
330330

331+
/**
332+
* return a read-only clone of the current theme configuration
333+
*/
331334
configuration : function() {
332-
// return a read-only clone of the current configuration
333-
var locals = { defaultTheme : defaultTheme, alwaysWatchTheme : alwaysWatchTheme };
334-
return angular.extend( { }, config, locals );
335+
return angular.extend( { }, themeConfig, {
336+
defaultTheme : defaultTheme,
337+
alwaysWatchTheme : alwaysWatchTheme,
338+
registeredStyles : [].concat(themeConfig.registeredStyles)
339+
});
335340
},
336341

337342
/**

src/core/services/theming/theming.spec.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,44 @@ describe('$mdThemingProvider', function() {
402402
expect(angular.element(document.getElementsByName(name)[0]).attr('content')).toBe(content);
403403
});
404404
})
405+
406+
describe('configuration', function () {
407+
beforeEach(function () {
408+
module('material.core', function($mdThemingProvider) {
409+
themingProvider = $mdThemingProvider;
410+
});
411+
startAngular();
412+
});
413+
414+
it('should have access to read-only configuration', function () {
415+
var config = themingProvider.configuration();
416+
417+
expect(config.disableTheming).toBe(false);
418+
expect(config.generateOnDemand).toBe(false);
419+
expect(config.registeredStyles.length).toBe(0);
420+
expect(config.nonce).toBe(null);
421+
expect(config.alwaysWatchTheme).toBe(false);
422+
423+
// Change local copies
424+
config.disableTheming = true;
425+
config.generateOnDemand = true;
426+
config.registeredStyles.push("Something");
427+
config.nonce = 'myNonce';
428+
config.alwaysWatchTheme = true;
429+
430+
var config2 = themingProvider.configuration();
431+
432+
// Confirm master versions are not altered
433+
expect(config2.disableTheming).toBe(false);
434+
expect(config2.generateOnDemand).toBe(false);
435+
expect(config2.registeredStyles.length).toBe(0);
436+
expect(config2.nonce).toBe(null);
437+
expect(config2.alwaysWatchTheme).toBe(false);
438+
439+
});
440+
441+
442+
})
405443
});
406444

407445
describe('$mdThemeProvider with custom styles', function() {

0 commit comments

Comments
 (0)