Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ad3b811

Browse files
committed
fixes, examples and tests for angular.Object.* docs
1 parent d3f7bd6 commit ad3b811

File tree

2 files changed

+46
-22
lines changed

2 files changed

+46
-22
lines changed

src/Angular.js

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,6 @@ function map(obj, iterator, context) {
469469

470470

471471
/**
472-
* @workInProgress
473472
* @ngdoc function
474473
* @name angular.Object.size
475474
* @function
@@ -481,14 +480,20 @@ function map(obj, iterator, context) {
481480
* {@link angular.Object} for more info.
482481
*
483482
* @param {Object|Array} obj Object or array to inspect.
484-
* @returns {number} The size of `obj` or `0` if `obj` is not an object or array.
483+
* @returns {number} The size of `obj` or `0` if `obj` is neither an object or an array.
485484
*
486485
* @example
487486
* Number of items in array: {{ [1,2].$size() }}<br/>
488487
* Number of items in object: {{ {a:1, b:2, c:3}.$size() }}<br/>
488+
*
489+
* @scenario
490+
it('should print correct sizes for an array and an object', function() {
491+
expect(binding('[1,2].$size()')).toBe('2');
492+
expect(binding('{a:1, b:2, c:3}.$size()')).toBe('3');
493+
});
489494
*/
490495
function size(obj) {
491-
var size = 0;
496+
var size = 0, key;
492497
if (obj) {
493498
if (isNumber(obj.length)) {
494499
return obj.length;
@@ -526,22 +531,21 @@ function isLeafNode (node) {
526531
}
527532

528533
/**
529-
* @workInProgress
530534
* @ngdoc function
531535
* @name angular.Object.copy
532536
* @function
533537
*
534538
* @description
535539
* Creates a deep copy of `source`.
536540
*
541+
* If `source` is an object or an array, all of its members will be copied into the `destination`
542+
* object.
543+
*
537544
* If `destination` is not provided and `source` is an object or an array, a copy is created &
538545
* returned, otherwise the `source` is returned.
539546
*
540547
* If `destination` is provided, all of its properties will be deleted.
541548
*
542-
* If `source` is an object or an array, all of its members will be copied into the `destination`
543-
* object.
544-
*
545549
* Note: this function is used to augment the Object type in angular expressions. See
546550
* {@link angular.Object} for more info.
547551
*
@@ -556,10 +560,22 @@ function isLeafNode (node) {
556560
<button ng:click="form = master.$copy()">copy</button>
557561
<hr/>
558562
559-
Master is <span ng:hide="master.$equals(form)">NOT</span> same as form.
563+
The master object is <span ng:hide="master.$equals(form)">NOT</span> equal to the form object.
560564
561565
<pre>master={{master}}</pre>
562566
<pre>form={{form}}</pre>
567+
568+
* @scenario
569+
it('should print that initialy the form object is NOT equal to master', function() {
570+
expect(element('.doc-example input[name=master.salutation]').val()).toBe('Hello');
571+
expect(element('.doc-example input[name=master.name]').val()).toBe('world');
572+
expect(element('.doc-example span').css('display')).toBe('inline');
573+
});
574+
575+
it('should make form and master equal when the copy button is clicked', function() {
576+
element('.doc-example button').click();
577+
expect(element('.doc-example span').css('display')).toBe('none');
578+
});
563579
*/
564580
function copy(source, destination){
565581
if (!destination) {
@@ -595,7 +611,6 @@ function copy(source, destination){
595611

596612

597613
/**
598-
* @workInProgress
599614
* @ngdoc function
600615
* @name angular.Object.equals
601616
* @function
@@ -604,13 +619,11 @@ function copy(source, destination){
604619
* Determines if two objects or value are equivalent.
605620
*
606621
* To be equivalent, they must pass `==` comparison or be of the same type and have all their
607-
* properties pass `==` comparison.
622+
* properties pass `==` comparison. During property comparision properties of `function` type and
623+
* properties with name starting with `$` are ignored.
608624
*
609625
* Supports values types, arrays and objects.
610626
*
611-
* For objects `function` properties and properties that start with `$` are not considered during
612-
* comparisons.
613-
*
614627
* Note: this function is used to augment the Object type in angular expressions. See
615628
* {@link angular.Object} for more info.
616629
*
@@ -619,15 +632,27 @@ function copy(source, destination){
619632
* @returns {boolean} True if arguments are equal.
620633
*
621634
* @example
622-
Salutation: <input type="text" name="master.salutation" value="Hello" /><br/>
623-
Name: <input type="text" name="master.name" value="world"/><br/>
624-
<button ng:click="form = master.$copy()">copy</button>
635+
Salutation: <input type="text" name="greeting.salutation" value="Hello" /><br/>
636+
Name: <input type="text" name="greeting.name" value="world"/><br/>
625637
<hr/>
626638
627-
Master is <span ng:hide="master.$equals(form)">NOT</span> same as form.
639+
The <code>greeting</code> object is
640+
<span ng:hide="greeting.$equals({salutation:'Hello', name:'world'})">NOT</span> equal to
641+
<code>{salutation:'Hello', name:'world'}</code>.
628642
629-
<pre>master={{master}}</pre>
630-
<pre>form={{form}}</pre>
643+
<pre>greeting={{greeting}}</pre>
644+
645+
@scenario
646+
it('should print that initialy greeting is equal to the hardcoded value object', function() {
647+
expect(element('.doc-example input[name=greeting.salutation]').val()).toBe('Hello');
648+
expect(element('.doc-example input[name=greeting.name]').val()).toBe('world');
649+
expect(element('.doc-example span').css('display')).toBe('none');
650+
});
651+
652+
it('should say that the objects are not equal when the form is modified', function() {
653+
input('greeting.name').enter('kitty');
654+
expect(element('.doc-example span').css('display')).toBe('inline');
655+
});
631656
*/
632657
function equals(o1, o2) {
633658
if (o1 == o2) return true;

src/apis.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@ var angularGlobal = {
1313

1414

1515
/**
16-
* @workInProgress
1716
* @ngdoc overview
1817
* @name angular.Object
1918
* @function
2019
*
2120
* @description
22-
* angular.Object is a namespace for utility functions for manipulation with JavaScript objects.
21+
* `angular.Object` is a namespace for utility functions for manipulation with JavaScript objects.
2322
*
2423
* These functions are exposed in two ways:
2524
*
@@ -45,7 +44,7 @@ var angularObject = {
4544
* @name angular.Array
4645
*
4746
* @description
48-
* angular.Array is a namespace for utility functions for manipulation of JavaScript `Array`
47+
* `angular.Array` is a namespace for utility functions for manipulation of JavaScript `Array`
4948
* objects.
5049
*
5150
* These functions are exposed in two ways:

0 commit comments

Comments
 (0)