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

Commit cf3d56c

Browse files
committed
refactor(toast): remove deprecated content() method and option and updateContent() method
BREAKING CHANGE: The deprecated `content()` and `updateContent()` methods have been removed. If you had: ```js $mdToast.show($mdToast.simple().content('This no longer works.')); ``` You will need to change to: ```js $mdToast.show($mdToast.simple().textContent('This works.')); ``` If you had: ```js $mdToast.updateContent('This no longer works.'); ``` You will need to change to: ```js $mdToast.updateTextContent('This works.'); ``` If you had: ```js $mdToast.show($mdToast.simple({parent: parent, content: 'This no longer works.', theme: 'some-theme', capsule: true})); ``` You will need to change to: ```js $mdToast.show($mdToast.simple({parent: parent, textContent: 'This works.', theme: 'some-theme', capsule: true})); ```
1 parent 4c75858 commit cf3d56c

File tree

2 files changed

+28
-38
lines changed

2 files changed

+28
-38
lines changed

src/components/toast/toast.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ function MdToastProvider($$interimElementProvider) {
336336
})
337337
.addPreset('simple', {
338338
argOption: 'textContent',
339-
methods: ['textContent', 'content', 'action', 'actionKey', 'actionHint', 'highlightAction',
339+
methods: ['textContent', 'action', 'actionKey', 'actionHint', 'highlightAction',
340340
'highlightClass', 'theme', 'parent', 'dismissHint'],
341341
options: /* @ngInject */ function($mdToast, $mdTheming) {
342342
return {
@@ -363,10 +363,7 @@ function MdToastProvider($$interimElementProvider) {
363363
};
364364
}
365365
})
366-
.addMethod('updateTextContent', updateTextContent)
367-
// updateContent is deprecated. Use updateTextContent instead.
368-
// TODO remove this in 1.2.
369-
.addMethod('updateContent', updateTextContent);
366+
.addMethod('updateTextContent', updateTextContent);
370367

371368
function updateTextContent(newContent) {
372369
activeToastContent = newContent;
@@ -466,9 +463,7 @@ function MdToastProvider($$interimElementProvider) {
466463
* @return {*}
467464
*/
468465
function onShow(scope, element, options) {
469-
// support deprecated #content method
470-
// TODO remove support for content in 1.2.
471-
activeToastContent = options.textContent || options.content;
466+
activeToastContent = options.textContent;
472467

473468
var isSmScreen = !$mdMedia('gt-sm');
474469

src/components/toast/toast.spec.js

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ describe('$mdToast service', function() {
1515
}));
1616

1717
function setup(options) {
18-
var promise;
19-
inject(function($mdToast, $material, $timeout) {
18+
var promise = null;
19+
inject(function($mdToast, $material) {
2020
options = options || {};
2121
promise = $mdToast.show(options);
2222
$material.flushOutstandingAnimations();
@@ -26,15 +26,15 @@ describe('$mdToast service', function() {
2626

2727
describe('simple()', function() {
2828

29-
hasConfigMethods(['content', 'action', 'capsule', 'highlightAction', 'theme', 'toastClass']);
29+
hasConfigMethods(['textContent', 'action', 'capsule', 'highlightAction', 'theme', 'toastClass']);
3030

3131
it('should have `._md` class indicator', inject(function($mdToast, $material) {
3232
var parent = angular.element('<div>');
3333

3434
$mdToast.show(
3535
$mdToast.simple({
3636
parent: parent,
37-
content: 'Do something',
37+
textContent: 'Do something',
3838
theme: 'some-theme',
3939
capsule: true
4040
}));
@@ -43,18 +43,18 @@ describe('$mdToast service', function() {
4343
expect(parent.find('md-toast').hasClass('_md')).toBe(true);
4444
}));
4545

46-
it('supports a basic toast', inject(function($mdToast, $rootScope, $timeout, $material, $browser) {
47-
var openAndclosed = false;
46+
it('supports a basic toast', inject(function($mdToast, $rootScope, $timeout, $material) {
47+
var openAndClosed = false;
4848
var parent = angular.element('<div>');
4949
$mdToast.show(
5050
$mdToast.simple({
5151
parent: parent,
52-
content: 'Do something',
52+
textContent: 'Do something',
5353
theme: 'some-theme',
5454
capsule: true
5555
})
5656
).then(function() {
57-
openAndclosed = true;
57+
openAndClosed = true;
5858
});
5959

6060
$material.flushOutstandingAnimations();
@@ -66,11 +66,10 @@ describe('$mdToast service', function() {
6666

6767
$material.flushInterimElement();
6868

69-
expect(openAndclosed).toBe(true);
69+
expect(openAndClosed).toBe(true);
7070
}));
7171

7272
it('supports dynamically updating the content', inject(function($mdToast, $rootScope, $rootElement) {
73-
var parent = angular.element('<div>');
7473
$mdToast.showSimple('Hello world');
7574
$rootScope.$digest();
7675
$mdToast.updateTextContent('Goodbye world');
@@ -83,7 +82,7 @@ describe('$mdToast service', function() {
8382
var parent = angular.element('<div>');
8483
$mdToast.show(
8584
$mdToast.simple({
86-
content: 'Do something',
85+
textContent: 'Do something',
8786
parent: parent
8887
})
8988
.action('Click me')
@@ -104,7 +103,7 @@ describe('$mdToast service', function() {
104103

105104
$mdToast.show(
106105
$mdToast.simple({
107-
content: 'Marked as read',
106+
textContent: 'Marked as read',
108107
parent: parent
109108
})
110109
.action('UNDO')
@@ -142,7 +141,7 @@ describe('$mdToast service', function() {
142141
it('displays correctly', inject(function($mdToast, $rootScope) {
143142
var parent = angular.element('<div>');
144143
var toast = $mdToast.simple({
145-
content: 'Do something',
144+
textContent: 'Do something',
146145
parent: parent
147146
}).action('Click me');
148147

@@ -160,7 +159,7 @@ describe('$mdToast service', function() {
160159
it('displays correctly with parent()', inject(function($mdToast, $rootScope) {
161160
var parent = angular.element('<div>');
162161
var toast = $mdToast.simple({
163-
content: 'Do something',
162+
textContent: 'Do something',
164163
})
165164
.parent(parent)
166165
.action('Click me');
@@ -334,7 +333,6 @@ describe('$mdToast service', function() {
334333
it('after duration', inject(function($timeout, $animate, $rootElement) {
335334
disableAnimations();
336335

337-
var parent = angular.element('<div>');
338336
var hideDelay = 1234;
339337
setup({
340338
template: '<md-toast />',
@@ -348,7 +346,7 @@ describe('$mdToast service', function() {
348346
it('and resolve with default `true`', inject(function($timeout, $material, $mdToast) {
349347
disableAnimations();
350348

351-
var hideDelay = 1234, result, fault;
349+
var result = null, fault = null;
352350
setup({
353351
template: '<md-toast />',
354352
hideDelay: 1234
@@ -361,15 +359,14 @@ describe('$mdToast service', function() {
361359

362360
$material.flushInterimElement();
363361

364-
expect(result).toBe(undefined);
365-
expect(angular.isUndefined(fault)).toBe(true);
366-
362+
expect(angular.isUndefined(result)).toBe(true);
363+
expect(fault).toBe(null);
367364
}));
368365

369366
it('and resolve with specified value', inject(function($timeout, $animate, $material, $mdToast) {
370367
disableAnimations();
371368

372-
var hideDelay = 1234, result, fault;
369+
var result = null, fault = null;
373370
setup({
374371
template: '<md-toast />',
375372
hideDelay: 1234
@@ -383,14 +380,13 @@ describe('$mdToast service', function() {
383380
$material.flushInterimElement();
384381

385382
expect(result).toBe("secret");
386-
expect(angular.isUndefined(fault)).toBe(true);
387-
383+
expect(fault).toBe(null);
388384
}));
389385

390386
it('and resolve `true` after timeout', inject(function($timeout, $material) {
391387
disableAnimations();
392388

393-
var hideDelay = 1234, result, fault;
389+
var result = null, fault = null;
394390
setup({
395391
template: '<md-toast />',
396392
hideDelay: 1234
@@ -401,17 +397,16 @@ describe('$mdToast service', function() {
401397

402398
$material.flushInterimElement();
403399

404-
expect(result).toBe(undefined);
405-
expect(angular.isUndefined(fault)).toBe(true);
406-
400+
expect(angular.isUndefined(result)).toBe(true);
401+
expect(fault).toBe(null);
407402
}));
408403

409-
it('and resolve `ok` with click on OK button', inject(function($mdToast, $rootScope, $timeout, $material, $browser) {
410-
var result, fault;
404+
it('and resolve `ok` with click on OK button', inject(function($mdToast, $rootScope, $timeout, $material) {
405+
var result = null, fault = null;
411406
var parent = angular.element('<div>');
412407
var toast = $mdToast.simple({
413408
parent: parent,
414-
content: 'Do something'
409+
textContent: 'Do something'
415410
}).action('Close with "ok" response');
416411

417412
$mdToast
@@ -428,7 +423,7 @@ describe('$mdToast service', function() {
428423
$material.flushInterimElement();
429424

430425
expect(result).toBe('ok');
431-
expect(angular.isUndefined(fault)).toBe(true);
426+
expect(fault).toBe(null);
432427
}));
433428
});
434429

0 commit comments

Comments
 (0)