diff options
| author | Misko Hevery | 2011-03-23 09:33:29 -0700 |
|---|---|---|
| committer | Vojta Jina | 2011-08-02 01:00:03 +0200 |
| commit | 8f0dcbab804180828d6859b1340c86cf161209fb (patch) | |
| tree | d13d47d47a1889cb7c96a87cecacd2e25307d51c /src/Compiler.js | |
| parent | 1f4b417184ce53af15474de065400f8a686430c5 (diff) | |
| download | angular.js-8f0dcbab804180828d6859b1340c86cf161209fb.tar.bz2 | |
feat(scope): new and improved scope implementation
- Speed improvements (about 4x on flush phase)
- Memory improvements (uses no function closures)
- Break $eval into $apply, $dispatch, $flush
- Introduced $watch and $observe
Breaks angular.equals() use === instead of ==
Breaks angular.scope() does not take parent as first argument
Breaks scope.$watch() takes scope as first argument
Breaks scope.$set(), scope.$get are removed
Breaks scope.$config is removed
Breaks $route.onChange callback has not "this" bounded
Diffstat (limited to 'src/Compiler.js')
| -rw-r--r-- | src/Compiler.js | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/src/Compiler.js b/src/Compiler.js index 730d175e..8512f0c3 100644 --- a/src/Compiler.js +++ b/src/Compiler.js @@ -29,15 +29,20 @@ Template.prototype = { inits[this.priority] = queue = []; } if (this.newScope) { - childScope = createScope(scope); - scope.$onEval(childScope.$eval); + childScope = isFunction(this.newScope) ? scope.$new(this.newScope(scope)) : scope.$new(); element.data($$scope, childScope); } + // TODO(misko): refactor this!!! + // Why are inits even here? forEach(this.inits, function(fn) { queue.push(function() { - childScope.$tryEval(function(){ - return childScope.$service.invoke(childScope, fn, [element]); - }, element); + childScope.$eval(function(){ + try { + return childScope.$service.invoke(childScope, fn, [element]); + } catch (e) { + childScope.$service('$exceptionHandler')(e); + } + }); }); }); var i, @@ -218,7 +223,6 @@ Compiler.prototype = { scope.$element = element; (cloneConnectFn||noop)(element, scope); template.attach(element, scope); - scope.$eval(); return scope; }; }, @@ -228,6 +232,7 @@ Compiler.prototype = { * @workInProgress * @ngdoc directive * @name angular.directive.ng:eval-order + * @deprecated * * @description * Normally the view is updated from top to bottom. This usually is @@ -244,9 +249,9 @@ Compiler.prototype = { * @example <doc:example> <doc:source> - <div>TOTAL: without ng:eval-order {{ items.$sum('total') | currency }}</div> - <div ng:eval-order='LAST'>TOTAL: with ng:eval-order {{ items.$sum('total') | currency }}</div> - <table ng:init="items=[{qty:1, cost:9.99, desc:'gadget'}]"> + <div>TOTAL: without ng:eval-order {{ total | currency }}</div> + <div ng:eval-order='LAST'>TOTAL: with ng:eval-order {{ total | currency }}</div> + <table ng:init="items=[{qty:1, cost:9.99, desc:'gadget'}];total=0;"> <tr> <td>QTY</td> <td>Description</td> @@ -258,22 +263,22 @@ Compiler.prototype = { <td><input name="item.qty"/></td> <td><input name="item.desc"/></td> <td><input name="item.cost"/></td> - <td>{{item.total = item.qty * item.cost | currency}}</td> + <td>{{item.qty * item.cost | currency}}</td> <td><a href="" ng:click="items.$remove(item)">X</a></td> </tr> <tr> <td colspan="3"><a href="" ng:click="items.$add()">add</a></td> - <td>{{ items.$sum('total') | currency }}</td> + <td>{{ total = items.$sum('qty*cost') | currency }}</td> </tr> </table> </doc:source> <doc:scenario> it('should check ng:format', function(){ - expect(using('.doc-example-live div:first').binding("items.$sum('total')")).toBe('$9.99'); - expect(using('.doc-example-live div:last').binding("items.$sum('total')")).toBe('$9.99'); + expect(using('.doc-example-live div:first').binding("total")).toBe('$0.00'); + expect(using('.doc-example-live div:last').binding("total")).toBe('$9.99'); input('item.qty').enter('2'); - expect(using('.doc-example-live div:first').binding("items.$sum('total')")).toBe('$9.99'); - expect(using('.doc-example-live div:last').binding("items.$sum('total')")).toBe('$19.98'); + expect(using('.doc-example-live div:first').binding("total")).toBe('$9.99'); + expect(using('.doc-example-live div:last').binding("total")).toBe('$19.98'); }); </doc:scenario> </doc:example> |
