Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
feat(toast): add mdToast#showSimple shortcut method
Browse files Browse the repository at this point in the history
closes #833
  • Loading branch information
rschmukler committed Jan 7, 2015
1 parent 002d8bf commit dd960c6
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/components/toast/toast.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,24 @@ function MdToastDirective() {
* app.controller('MyController', function($scope, $mdToast) {
* $scope.openToast = function($event) {
* $mdToast.show($mdToast.simple().content('Hello!'));
* // Could also do $mdtoast.showSimple('Hello');

This comment has been minimized.

Copy link
@kai23

kai23 Jan 29, 2015

typo : should be $mdToast

* };
* });
* </hljs>
*/

/**
* @ngdoc method
* @name $mdToast#showSimple
*
* @description
* Convenience method which builds and shows a simple toast.
*
* @returns {promise} A promise that can be resolved with `$mdToast.hide()` or
* rejected with `$mdToast.cancel()`.
*
*/

/**
* @ngdoc method
* @name $mdToast#simple
Expand Down
11 changes: 11 additions & 0 deletions src/core/services/interimElement/interimElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ function InterimElementProvider() {
optionsFactory: definition.options,
argOption: definition.argOption
};
if (definition.argOption) {

This comment has been minimized.

Copy link
@gkalpak

gkalpak Jan 7, 2015

Member

Do I miss something or is this an empty block that does nothing ?

}
return provider;
}

Expand Down Expand Up @@ -147,6 +149,15 @@ function InterimElementProvider() {
};
});

// Create shortcut method for one-linear methods
if (definition.argOption) {
var methodName = 'show' + name.charAt(0).toUpperCase() + name.slice(1);
publicService[methodName] = function(arg) {
var config = publicService[name](arg);
return publicService.show(config);
};
}

// eg $mdDialog.alert() will return a new alert preset
publicService[name] = function(arg) {
// If argOption is supplied, eg `argOption: 'content'`, then we assume
Expand Down
22 changes: 22 additions & 0 deletions src/core/services/interimElement/interimElement.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,28 @@ describe('$$interimElement service', function() {
});
});

it('should create a shortcut show method with arg options', function() {
var shown = false;
createInterimProvider('interimTest')
.addPreset('banana', {
argOption: 'color',
methods: ['color'],
options: function() {
return {
onShow: function(scope, el, opts) {
shown = true;
expect(opts.color).toBe('yellow');
}
};
}
});
inject(function(interimTest, $rootScope) {
interimTest.showBanana('yellow');
$rootScope.$apply();
expect(shown).toBe(true);
});
});

it('should show with proper options', function() {
createInterimProvider('interimTest')
.setDefaults({
Expand Down

0 comments on commit dd960c6

Please sign in to comment.