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

@@ -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';