refactor(scope): separate controller from scope

Controller is standalone object, created using "new" operator, not messed up with scope anymore.
Instead, related scope is injected as $scope.

See design proposal: https://docs.google.com/document/pub?id=1SsgVj17ec6tnZEX3ugsvg0rVVR11wTso5Md-RdEmC0k

Closes #321
Closes #425

Breaks controller methods are not exported to scope automatically
Breaks Scope#$new() does not take controller as argument anymore
This commit is contained in:
Vojta Jina
2011-11-29 21:51:59 -08:00
parent f5343c9fd3
commit 992c790f07
34 changed files with 481 additions and 520 deletions

View File

@@ -51,14 +51,14 @@ You can try evaluating different expressions here:
<doc:example>
<doc:source>
<script>
function Cntl2() {
this.exprs = [];
this.expr = '3*10|currency';
this.addExp = function(expr) {
function Cntl2($scope) {
$scope.exprs = [];
$scope.expr = '3*10|currency';
$scope.addExp = function(expr) {
this.exprs.push(expr);
};
this.removeExp = function(contact) {
$scope.removeExp = function(contact) {
for ( var i = 0, ii = this.exprs.length; i < ii; i++) {
if (contact === this.exprs[i]) {
this.exprs.splice(i, 1);
@@ -101,10 +101,10 @@ the global state (a common source of subtle bugs).
<doc:example>
<doc:source>
<script>
function Cntl1($window){
this.name = 'World';
function Cntl1($window, $scope){
$scope.name = 'World';
this.greet = function() {
$scope.greet = function() {
($window.mockWindow || $window).alert('Hello ' + this.name);
}
}