chore(formating): clean code to be function() {

This commit is contained in:
Misko Hevery
2011-10-07 11:27:49 -07:00
committed by Igor Minar
parent 4f78fd692c
commit fd822bdaf9
107 changed files with 942 additions and 941 deletions

View File

@@ -40,8 +40,8 @@ All `inputType` widgets support:
<doc:example>
<doc:source>
<script>
angular.inputType('json', function(){
this.$parseView = function(){
angular.inputType('json', function() {
this.$parseView = function() {
try {
this.$modelValue = angular.fromJson(this.$viewValue);
if (this.$error.JSON) {
@@ -52,12 +52,12 @@ All `inputType` widgets support:
}
}
this.$parseModel = function(){
this.$parseModel = function() {
this.$viewValue = angular.toJson(this.$modelValue);
}
});
function Ctrl(){
function Ctrl() {
this.data = {
framework:'angular',
codenames:'supper-powers'
@@ -81,7 +81,7 @@ All `inputType` widgets support:
</div>
</doc:source>
<doc:scenario>
it('should invalidate on wrong input', function(){
it('should invalidate on wrong input', function() {
expect(element('form[name=myForm]').prop('className')).toMatch('ng-valid');
input('data').enter('{}');
expect(binding('data')).toEqual('data={\n }');

View File

@@ -9,7 +9,7 @@ detection, and preventing invalid form submission.
<doc:example>
<doc:source>
<script>
function UserForm(){
function UserForm() {
this.state = /^\w\w$/;
this.zip = /^\d\d\d\d\d$/;
this.master = {
@@ -28,11 +28,11 @@ detection, and preventing invalid form submission.
}
UserForm.prototype = {
cancel: function(){
cancel: function() {
this.form = angular.copy(this.master);
},
save: function(){
save: function() {
this.master = this.form;
this.cancel();
}
@@ -76,7 +76,7 @@ detection, and preventing invalid form submission.
</div>
</doc:source>
<doc:scenario>
it('should enable save button', function(){
it('should enable save button', function() {
expect(element(':button:contains(Save)').attr('disabled')).toBeTruthy();
input('form.name').enter('');
expect(element(':button:contains(Save)').attr('disabled')).toBeTruthy();
@@ -85,7 +85,7 @@ detection, and preventing invalid form submission.
element(':button:contains(Save)').click();
expect(element(':button:contains(Save)').attr('disabled')).toBeTruthy();
});
it('should enable cancel button', function(){
it('should enable cancel button', function() {
expect(element(':button:contains(Cancel)').attr('disabled')).toBeTruthy();
input('form.name').enter('change');
expect(element(':button:contains(Cancel)').attr('disabled')).toBeFalsy();

View File

@@ -56,7 +56,7 @@ The two partials are defined in the following URLs:
function WelcomeCntl($route){}
WelcomeCntl.prototype = {
greet: function(){
greet: function() {
alert("Hello " + this.person.name);
}
};
@@ -67,11 +67,11 @@ The two partials are defined in the following URLs:
this.cancel();
}
SettingsCntl.prototype = {
cancel: function(){
cancel: function() {
this.form = angular.copy(this.person);
},
save: function(){
save: function() {
angular.copy(this.form, this.person);
this.$location.path('/welcome');
}
@@ -89,7 +89,7 @@ The two partials are defined in the following URLs:
</div>
</doc:source>
<doc:scenario>
it('should navigate to URL', function(){
it('should navigate to URL', function() {
element('a:contains(Welcome)').click();
expect(element('ng\\:view').text()).toMatch(/Hello anonymous/);
element('a:contains(Settings)').click();

View File

@@ -11,7 +11,7 @@ allow a user to enter data.
<doc:example>
<doc:source>
<script>
function FormController(){
function FormController() {
this.user = {
name: 'John Smith',
address:{line1: '123 Main St.', city:'Anytown', state:'AA', zip:'12345'},
@@ -53,22 +53,22 @@ allow a user to enter data.
</doc:source>
<doc:scenario>
it('should show debug', function(){
it('should show debug', function() {
expect(binding('user')).toMatch(/John Smith/);
});
it('should add contact', function(){
it('should add contact', function() {
using('.example').element('a:contains(add)').click();
using('.example div:last').input('contact.value').enter('you@example.org');
expect(binding('user')).toMatch(/\(234\) 555\-1212/);
expect(binding('user')).toMatch(/you@example.org/);
});
it('should remove contact', function(){
it('should remove contact', function() {
using('.example').element('a:contains(X)').click();
expect(binding('user')).not().toMatch(/\(234\) 555\-1212/);
});
it('should validate zip', function(){
it('should validate zip', function() {
expect(using('.example').
element(':input[ng\\:model="user.address.zip"]').
prop('className')).not().toMatch(/ng-invalid/);
@@ -78,7 +78,7 @@ allow a user to enter data.
prop('className')).toMatch(/ng-invalid/);
});
it('should validate state', function(){
it('should validate state', function() {
expect(using('.example').element(':input[ng\\:model="user.address.state"]').prop('className'))
.not().toMatch(/ng-invalid/);
using('.example').input('user.address.state').enter('XXX');

View File

@@ -6,7 +6,7 @@
<doc:example>
<doc:source>
<script>
function HelloCntl(){
function HelloCntl() {
this.name = 'World';
}
</script>
@@ -17,7 +17,7 @@
</div>
</doc:source>
<doc:scenario>
it('should change the binding when user enters text', function(){
it('should change the binding when user enters text', function() {
expect(binding('name')).toEqual('World');
input('name').enter('angular');
expect(binding('name')).toEqual('angular');

View File

@@ -36,7 +36,7 @@ no connection between the controller and the view.
this.setUrl();
}
},
reset: function(){
reset: function() {
this.board = [
['', '', ''],
['', '', ''],
@@ -46,7 +46,7 @@ no connection between the controller and the view.
this.winner = '';
this.setUrl();
},
grade: function(){
grade: function() {
var b = this.board;
this.winner =
row(0) || row(1) || row(2) ||
@@ -57,7 +57,7 @@ no connection between the controller and the view.
function diagonal(i) { return same(b[0][1-i], b[1][1], b[2][1+i]);}
function same(a, b, c) { return (a==b && b==c) ? a : '';};
},
setUrl: function(){
setUrl: function() {
var rows = [];
angular.forEach(this.board, function(row){
rows.push(row.join(','));
@@ -91,7 +91,7 @@ no connection between the controller and the view.
</div>
</doc:source>
<doc:scenario>
it('should play a game', function(){
it('should play a game', function() {
piece(1, 1);
expect(binding('nextMove')).toEqual('O');
piece(3, 1);

View File

@@ -61,7 +61,7 @@ angular.widget('@my:watch', function(expression, compileElement) {
angular.widget('my:time', function(compileElement){
compileElement.css('display', 'block');
return function(linkElement){
function update(){
function update() {
linkElement.text('Current time is: ' + new Date());
setTimeout(update, 1000);
}

View File

@@ -41,7 +41,7 @@ the `Scope:$eval()` method.
1+2={{1+2}}
</doc:source>
<doc:scenario>
it('should calculate expression in binding', function(){
it('should calculate expression in binding', function() {
expect(binding('1+2')).toEqual('3');
});
</doc:scenario>
@@ -52,7 +52,7 @@ You can try evaluating different expressions here:
<doc:example>
<doc:source>
<script>
function Cntl2(){
function Cntl2() {
this.exprs = [];
this.expr = '3*10|currency';
}
@@ -70,7 +70,7 @@ You can try evaluating different expressions here:
</div>
</doc:source>
<doc:scenario>
it('should allow user expression testing', function(){
it('should allow user expression testing', function() {
element('.expressions :button').click();
var li = using('.expressions ul').repeater('li');
expect(li.count()).toBe(1);
@@ -105,7 +105,7 @@ the global state (a common source of subtle bugs).
</div>
</doc:source>
<doc:scenario>
it('should calculate expression in binding', function(){
it('should calculate expression in binding', function() {
var alertText;
this.addFutureAction('set mock', function($window, $document, done) {
$window.mockWindow = {
@@ -183,7 +183,7 @@ Extensions: You can further extend the expression vocabulary by adding new metho
</table>
</doc:source>
<doc:scenario>
it('should filter the list', function(){
it('should filter the list', function() {
var tr = using('table.example3').repeater('tr.ng-attr-widget');
expect(tr.count()).toBe(5);
input('searchText').enter('a');

View File

@@ -111,7 +111,7 @@ The following example demonstrates:
.ng-form {display: block;}
</style>
<script>
function UserFormCntl(){
function UserFormCntl() {
this.state = /^\w\w$/;
this.zip = /^\d\d\d\d\d$/;
this.master = {
@@ -127,11 +127,11 @@ The following example demonstrates:
}
UserFormCntl.prototype = {
cancel: function(){
cancel: function() {
this.form = angular.copy(this.master);
},
save: function(){
save: function() {
this.master = this.form;
this.cancel();
}
@@ -187,7 +187,7 @@ The following example demonstrates:
</div>
</doc:source>
<doc:scenario>
it('should enable save button', function(){
it('should enable save button', function() {
expect(element(':button:contains(Save)').attr('disabled')).toBeTruthy();
input('form.customer').enter('');
expect(element(':button:contains(Save)').attr('disabled')).toBeTruthy();
@@ -196,7 +196,7 @@ The following example demonstrates:
element(':button:contains(Save)').click();
expect(element(':button:contains(Save)').attr('disabled')).toBeTruthy();
});
it('should enable cancel button', function(){
it('should enable cancel button', function() {
expect(element(':button:contains(Cancel)').attr('disabled')).toBeTruthy();
input('form.customer').enter('change');
expect(element(':button:contains(Cancel)').attr('disabled')).toBeFalsy();
@@ -274,7 +274,7 @@ This example shows how to implement a custom HTML editor widget in Angular.
<doc:example>
<doc:source>
<script>
function EditorCntl(){
function EditorCntl() {
this.htmlContent = '<b>Hello</b> <i>World</i>!';
}
@@ -282,7 +282,7 @@ This example shows how to implement a custom HTML editor widget in Angular.
var self = this;
var htmlFilter = angular.filter('html');
this.$parseModel = function(){
this.$parseModel = function() {
// need to protect for script injection
try {
this.$viewValue = htmlFilter(
@@ -297,18 +297,18 @@ This example shows how to implement a custom HTML editor widget in Angular.
}
}
this.$render = function(){
this.$render = function() {
element.html(this.$viewValue);
}
element.bind('keyup', function(){
self.$apply(function(){
element.bind('keyup', function() {
self.$apply(function() {
self.$emit('$viewChange', element.html());
});
});
}
angular.directive('ng:html-editor-model', function(){
angular.directive('ng:html-editor-model', function() {
function linkFn($formFactory, element) {
var exp = element.attr('ng:html-editor-model'),
form = $formFactory.forElement(element),
@@ -321,7 +321,7 @@ This example shows how to implement a custom HTML editor widget in Angular.
controllerArgs: [element]});
// if the element is destroyed, then we need to
// notify the form.
element.bind('$destroy', function(){
element.bind('$destroy', function() {
widget.$destroy();
});
}
@@ -339,7 +339,7 @@ This example shows how to implement a custom HTML editor widget in Angular.
</form>
</doc:source>
<doc:scenario>
it('should enter invalid HTML', function(){
it('should enter invalid HTML', function() {
expect(element('form[name=editorForm]').prop('className')).toMatch(/ng-valid/);
input('htmlContent').enter('<');
expect(element('form[name=editorForm]').prop('className')).toMatch(/ng-invalid/);
@@ -358,7 +358,7 @@ validation.
<doc:example>
<doc:source>
<script>
function Ctrl(){
function Ctrl() {
this.input1 = '';
this.input2 = '';
this.input3 = 'A';
@@ -447,32 +447,32 @@ validation.
</doc:source>
<doc:scenario>
it('should exercise text', function(){
it('should exercise text', function() {
input('input1').enter('Carlos');
expect(binding('input1')).toEqual('"Carlos"');
});
it('should exercise textarea', function(){
it('should exercise textarea', function() {
input('input2').enter('Carlos');
expect(binding('input2')).toEqual('"Carlos"');
});
it('should exercise radio', function(){
it('should exercise radio', function() {
expect(binding('input3')).toEqual('"A"');
input('input3').select('B');
expect(binding('input3')).toEqual('"B"');
input('input3').select('A');
expect(binding('input3')).toEqual('"A"');
});
it('should exercise checkbox', function(){
it('should exercise checkbox', function() {
expect(binding('input4')).toEqual('false');
input('input4').check();
expect(binding('input4')).toEqual('true');
});
it('should exercise pulldown', function(){
it('should exercise pulldown', function() {
expect(binding('input5')).toEqual('"c"');
select('input5').option('d');
expect(binding('input5')).toEqual('"d"');
});
it('should exercise multiselect', function(){
it('should exercise multiselect', function() {
expect(binding('input6')).toEqual('[]');
select('input6').options('e');
expect(binding('input6')).toEqual('["e"]');

View File

@@ -3,7 +3,7 @@
@name Developer Guide: About MVC in Angular: Understanding the Controller Component
@description
In angular, a controller is a JavaScript function (type/class) that is used to augment instances of
In angular, a controller is a JavaScript function(type/class) that is used to augment instances of
angular {@link dev_guide.scopes Scope}, excluding the root scope. When you or angular create a new
child scope object via the {@link api/angular.scope.$new scope.$new} API , there is an
option to pass in a controller as a method argument. This will tell angular to associate the
@@ -128,7 +128,7 @@ starts with capital letter and ends with "Ctrl" or "Controller".
controller augments.
- Assigning a property to `this` creates or updates the model.
- Controller methods can be created through direct assignment to scope (the `chiliSpicy` method) or
as prototype methods of the controller constructor function (the `jalapenoSpicy` method)
as prototype methods of the controller constructor function(the `jalapenoSpicy` method)
- Both controller methods are available in the template (for the `body` element and and its
children).
@@ -227,7 +227,7 @@ Controller Test:
<pre>
describe('myController function', function() {
describe('myController', function(){
describe('myController', function() {
var ctrl;
beforeEach(function() {

View File

@@ -43,7 +43,7 @@ easier a web developer's life can if they're using angular:
<doc:example>
<doc:source>
<script>
function InvoiceCntl(){
function InvoiceCntl() {
this.qty = 1;
this.cost = 19.95;
}
@@ -66,7 +66,7 @@ easier a web developer's life can if they're using angular:
</doc:source>
<!--
<doc:scenario>
it('should show of angular binding', function(){
it('should show of angular binding', function() {
expect(binding('qty * cost')).toEqual('$19.95');
input('qty').enter('2');
input('cost').enter('5.00');

View File

@@ -10,7 +10,7 @@ that angular's DI will use to create the service object when it is needed.
The `angular.service` method accepts three parameters:
- `{string} name` - Name of the service.
- `{function()} factory` - Factory function (called just once by DI).
- `{function()} factory` - Factory function(called just once by DI).
- `{Object} config` - Configuration object with the following properties:
- `$inject` - {Array.<string>} - Array of service ids this service depends on. These services
will be passed as arguments into the factory function in the same order specified in the `$inject`

View File

@@ -59,7 +59,7 @@ myController.$inject = ['notify'];
</div>
</doc:source>
<doc:scenario>
it('should test service', function(){
it('should test service', function() {
expect(element(':input[ng\\:model="message"]').val()).toEqual('test');
});
</doc:scenario>

View File

@@ -36,7 +36,7 @@ text upper-case and assigns color.
return out;
});
function Ctrl(){
function Ctrl() {
this.greeting = 'hello';
}
</script>
@@ -50,7 +50,7 @@ text upper-case and assigns color.
</div>
</doc:source>
<doc:scenario>
it('should reverse greeting', function(){
it('should reverse greeting', function() {
expect(binding('greeting|reverse')).toEqual('olleh');
input('greeting').enter('ABC');
expect(binding('greeting|reverse')).toEqual('CBA');

View File

@@ -43,11 +43,11 @@ on a constructor permanently binds the call site to the type. For example lets s
trying to instantiate an `XHR` so that we can get some data from the server.
<pre>
function MyClass(){
this.doWork = function(){
function MyClass() {
this.doWork = function() {
var xhr = new XHR();
xhr.open(method, url, true);
xhr.onreadystatechange = function(){...}
xhr.onreadystatechange = function() {...}
xhr.send();
}
}
@@ -61,7 +61,7 @@ patching, that is a bad idea for many reasons, which is outside the scope of thi
The class above is hard to test since we have to resort to monkey patching:
<pre>
var oldXHR = XHR;
XHR = function MockXHR(){};
XHR = function MockXHR() {};
var myClass = new MyClass();
myClass.doWork();
// assert that MockXHR got called with the right arguments
@@ -73,8 +73,8 @@ XHR = oldXHR; // if you forget this bad things will happen
Another way to approach the problem is look for the service in a well known location.
<pre>
function MyClass(){
this.doWork = function(){
function MyClass() {
this.doWork = function() {
global.xhr({
method:'...',
url:'...',
@@ -94,7 +94,7 @@ State & Singletons}
The class above is hard to test since we have to change global state:
<pre>
var oldXHR = glabal.xhr;
glabal.xhr = function mockXHR(){};
glabal.xhr = function mockXHR() {};
var myClass = new MyClass();
myClass.doWork();
// assert that mockXHR got called with the right arguments
@@ -110,7 +110,7 @@ having the tests replace the services as needed.
<pre>
function MyClass() {
var serviceRegistry = ????;
this.doWork = function(){
this.doWork = function() {
var xhr = serviceRegistry.get('xhr');
xhr({
method:'...',
@@ -128,7 +128,7 @@ there is only one global variable to be reset).
The class above is hard to test since we have to change global state:
<pre>
var oldServiceLocator = glabal.serviceLocator;
glabal.serviceLocator.set('xhr', function mockXHR(){});
glabal.serviceLocator.set('xhr', function mockXHR() {});
var myClass = new MyClass();
myClass.doWork();
// assert that mockXHR got called with the right arguments
@@ -141,7 +141,7 @@ Lastly the dependency can be passed in.
<pre>
function MyClass(xhr) {
this.doWork = function(){
this.doWork = function() {
xhr({
method:'...',
url:'...',
@@ -174,13 +174,13 @@ for your application is mixed in with DOM manipulation, it will be hard to test
below:
<pre>
function PasswordController(){
function PasswordController() {
// get references to DOM elements
var msg = $('.ex1 span');
var input = $('.ex1 input');
var strength;
this.grade = function(){
this.grade = function() {
msg.removeClass(strength);
var pwd = input.val();
password.text(pwd);
@@ -219,9 +219,9 @@ In angular the controllers are strictly separated from the DOM manipulation logi
a much easier testability story as can be seen in this example:
<pre>
function PasswordCntrl(){
function PasswordCntrl() {
this.password = '';
this.grade = function(){
this.grade = function() {
var size = this.password.length;
if (size > 8) {
this.strength = 'strong';

View File

@@ -69,7 +69,7 @@ view.
## Model and Controller
The data __model__ (a simple array of phones in object literal notation) is instantiated within
the __controller__ function (`PhoneListCtrl`):
the __controller__ function(`PhoneListCtrl`):
__`app/js/controllers.js`:__
<pre>
@@ -91,7 +91,7 @@ providing context for our data model, the controller allows us to establish data
the model and the view. We connected the dots between the presentation, data, and logic components
as follows:
* The name of our controller function (in the JavaScript file `controllers.js`) matches the {@link
* The name of our controller function(in the JavaScript file `controllers.js`) matches the {@link
api/angular.directive.ng:controller ng:controller} directive in the `<body>` tag (`PhoneListCtrl`).
* The data is instantiated within the *scope* of our controller function; our template binding
points are located within the block bounded by the `<body ng:controller="PhoneListCtrl">` tag.

View File

@@ -114,7 +114,7 @@ __`test/unit/controllerSpec.js`:__
<pre>
describe('PhoneCat controllers', function() {
describe('PhoneListCtrl', function(){
describe('PhoneListCtrl', function() {
var scope, $browser, ctrl;
beforeEach(function() {

View File

@@ -129,7 +129,7 @@ __`test/unit/controllersSpec.js`:__
<pre>
describe('PhoneCat controllers', function() {
beforeEach(function(){
beforeEach(function() {
this.addMatchers({
toEqualData: function(expected) {
return angular.equals(this.actual, expected);