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

Skip to content

Commit b0e0c05

Browse files
committed
New and improved Scope.
- Speed improvements (about 4x on flush phase) - Memory improvements (uses no function closures) - Break $eval into $apply, $dispatch, $flush - Introduced $watch and $observe
1 parent 4bcc6b8 commit b0e0c05

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1981
-1471
lines changed

docs/cookbook.mvc.ngdoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ no connection between the controller and the view.
6363
});
6464
this.$location.hashSearch.board = rows.join(';') + '/' + this.nextMove;
6565
},
66-
readUrl: function(value) {
66+
readUrl: function(scope, value) {
6767
if (value) {
6868
value = value.split('/');
6969
this.nextMove = value[1];

docs/src/templates/docs.css

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,3 +300,17 @@ img.right {
300300
h1, h2, h3, h4, h5 {
301301
clear: both;
302302
}
303+
304+
.table {
305+
border-collapse: collapse;
306+
}
307+
308+
.table th:FIRST-CHILD {
309+
text-align: right;
310+
}
311+
312+
.table th,
313+
.table td {
314+
border: 1px solid black;
315+
padding: .5em 1em;
316+
}

docs/src/templates/docs.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ function DocsController($location, $browser, $window) {
99
$location.hashPath = '!angular';
1010
}
1111

12-
this.$watch('$location.hashPath', function(hashPath) {
12+
this.$watch('$location.hashPath', function(scope, hashPath) {
1313
if (hashPath.match(/^!/)) {
14-
this.partialId = hashPath.substring(1);
15-
this.partialTitle = (angular.Array.filter(NG_PAGES, {id:this.partialId})[0]||{}).name;
14+
scope.partialId = hashPath.substring(1);
15+
scope.partialTitle = (angular.Array.filter(NG_PAGES, {id:scope.partialId})[0]||{}).name;
1616
}
17-
});
17+
})();
1818

1919
this.getUrl = function(page){
2020
return '#!' + page.id;

perf/MiscPerf.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
describe('perf misc', function(){
2+
it('operation speeds', function(){
3+
perf(
4+
function typeByTypeof(){ return typeof noop == 'function'; }, // WINNER
5+
function typeByProperty() { return noop.apply && noop.call; },
6+
function typeByConstructor() { return noop.constructor == Function; }
7+
);
8+
});
9+
10+
it('property access', function(){
11+
var name = 'value';
12+
var none = 'x';
13+
var scope = {};
14+
perf(
15+
function direct(){ return scope.value; }, // WINNER
16+
function byName() { return scope[name]; },
17+
function undefinedDirect(){ return scope.x; },
18+
function undefiendByName() { return scope[none]; }
19+
);
20+
});
21+
});

src/Angular.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ if ('i' !== 'I'.toLowerCase()) {
5252
function fromCharCode(code) { return String.fromCharCode(code); }
5353

5454

55-
var $$element = '$element',
55+
var _undefined = undefined,
56+
_null = null,
5657
$$update = '$update',
5758
$$scope = '$scope',
5859
$$validate = '$validate',
@@ -62,7 +63,6 @@ var $$element = '$element',
6263
$console = 'console',
6364
$date = 'date',
6465
$display = 'display',
65-
$element = 'element',
6666
$function = 'function',
6767
$length = 'length',
6868
$name = 'name',
@@ -663,8 +663,8 @@ function copy(source, destination){
663663
* @description
664664
* Determines if two objects or value are equivalent.
665665
*
666-
* To be equivalent, they must pass `==` comparison or be of the same type and have all their
667-
* properties pass `==` comparison. During property comparision properties of `function` type and
666+
* To be equivalent, they must pass `===` comparison or be of the same type and have all their
667+
* properties pass `===` comparison. During property comparision properties of `function` type and
668668
* properties with name starting with `$` are ignored.
669669
*
670670
* Supports values types, arrays and objects.
@@ -704,7 +704,7 @@ function copy(source, destination){
704704
* </doc:example>
705705
*/
706706
function equals(o1, o2) {
707-
if (o1 == o2) return true;
707+
if (o1 === o2) return true;
708708
if (o1 === null || o2 === null) return false;
709709
var t1 = typeof o1, t2 = typeof o2, length, key, keySet;
710710
if (t1 == t2 && t1 == 'object') {
@@ -1067,13 +1067,14 @@ function angularInit(config, document){
10671067

10681068
if (autobind) {
10691069
var element = isString(autobind) ? document.getElementById(autobind) : document,
1070-
scope = compile(element)(createScope({'$config':config})),
1070+
scope = compile(element)(createScope()),
10711071
$browser = scope.$service('$browser');
10721072

10731073
if (config.css)
10741074
$browser.addCss(config.base_url + config.css);
10751075
else if(msie<8)
10761076
$browser.addJs(config.base_url + config.ie_compat, config.ie_compat_id);
1077+
scope.$apply();
10771078
}
10781079
}
10791080

@@ -1130,5 +1131,5 @@ function assertArg(arg, name, reason) {
11301131
}
11311132

11321133
function assertArgFn(arg, name) {
1133-
assertArg(isFunction(arg, name, 'not a function'));
1134-
}
1134+
assertArg(isFunction(arg), name, 'not a function, got ' + (typeof arg));
1135+
};

src/Compiler.js

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,20 @@ Template.prototype = {
2727
inits[this.priority] = queue = [];
2828
}
2929
if (this.newScope) {
30-
childScope = createScope(scope);
31-
scope.$onEval(childScope.$eval);
30+
childScope = isFunction(this.newScope) ? scope.$new(this.newScope(scope)) : scope.$new();
3231
element.data($$scope, childScope);
3332
}
33+
// TODO: refactor this!!!
34+
// Why are inits even here?
3435
forEach(this.inits, function(fn) {
3536
queue.push(function() {
36-
childScope.$tryEval(function(){
37-
return childScope.$service.invoke(childScope, fn, [element]);
38-
}, element);
37+
childScope.$eval(function(){
38+
try {
39+
return childScope.$service.invoke(childScope, fn, [element]);
40+
} catch (e) {
41+
childScope.$service('$exceptionHandler')(e);
42+
}
43+
});
3944
});
4045
});
4146
var i,
@@ -184,7 +189,9 @@ Compiler.prototype = {
184189
scope.$element = element;
185190
(cloneConnectFn||noop)(element, scope);
186191
template.attach(element, scope);
187-
scope.$eval();
192+
// TODO: should this be here?
193+
// NO, since we get into infinity loop with ng:repeat
194+
// scope.$service('$updateView')();
188195
return scope;
189196
};
190197
},
@@ -194,6 +201,7 @@ Compiler.prototype = {
194201
* @workInProgress
195202
* @ngdoc directive
196203
* @name angular.directive.ng:eval-order
204+
* @deprecated
197205
*
198206
* @description
199207
* Normally the view is updated from top to bottom. This usually is
@@ -210,8 +218,8 @@ Compiler.prototype = {
210218
* @example
211219
<doc:example>
212220
<doc:source>
213-
<div>TOTAL: without ng:eval-order {{ items.$sum('total') | currency }}</div>
214-
<div ng:eval-order='LAST'>TOTAL: with ng:eval-order {{ items.$sum('total') | currency }}</div>
221+
<div>TOTAL: without ng:eval-order {{ total | currency }}</div>
222+
<div ng:eval-order='LAST'>TOTAL: with ng:eval-order {{ total | currency }}</div>
215223
<table ng:init="items=[{qty:1, cost:9.99, desc:'gadget'}]">
216224
<tr>
217225
<td>QTY</td>
@@ -224,22 +232,22 @@ Compiler.prototype = {
224232
<td><input name="item.qty"/></td>
225233
<td><input name="item.desc"/></td>
226234
<td><input name="item.cost"/></td>
227-
<td>{{item.total = item.qty * item.cost | currency}}</td>
235+
<td>{{item.qty * item.cost | currency}}</td>
228236
<td><a href="" ng:click="items.$remove(item)">X</a></td>
229237
</tr>
230238
<tr>
231239
<td colspan="3"><a href="" ng:click="items.$add()">add</a></td>
232-
<td>{{ items.$sum('total') | currency }}</td>
240+
<td>{{ total = items.$sum('qty*cost') | currency }}</td>
233241
</tr>
234242
</table>
235243
</doc:source>
236244
<doc:scenario>
237245
it('should check ng:format', function(){
238-
expect(using('.doc-example-live div:first').binding("items.$sum('total')")).toBe('$9.99');
239-
expect(using('.doc-example-live div:last').binding("items.$sum('total')")).toBe('$9.99');
246+
expect(using('.doc-example-live div:first').binding("total")).toBe('$');
247+
expect(using('.doc-example-live div:last').binding("total")).toBe('$9.99');
240248
input('item.qty').enter('2');
241-
expect(using('.doc-example-live div:first').binding("items.$sum('total')")).toBe('$9.99');
242-
expect(using('.doc-example-live div:last').binding("items.$sum('total')")).toBe('$19.98');
249+
expect(using('.doc-example-live div:first').binding("total")).toBe('$9.99');
250+
expect(using('.doc-example-live div:last').binding("total")).toBe('$19.98');
243251
});
244252
</doc:scenario>
245253
</doc:example>

src/JSON.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ function toJsonArray(buf, obj, pretty, stack) {
114114
sep = true;
115115
}
116116
buf.push("]");
117+
} else if (isElement(obj)) {
118+
buf.push('DOM_ELEMENT');
117119
} else if (isDate(obj)) {
118120
buf.push(angular.String.quoteUnicode(angular.Date.toString(obj)));
119121
} else {

0 commit comments

Comments
 (0)