Skip to content

Commit f039cfc

Browse files
committed
You can now reference the $scope with this.$
1 parent cd1a921 commit f039cfc

File tree

6 files changed

+39
-21
lines changed

6 files changed

+39
-21
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,7 @@ app.classy.options.controller = {
2929
addFnsToScope: false
3030
};
3131
```
32-
* ... or at the class level using the `__options` property
32+
* ... or at the class level using the `__options` property
33+
34+
## 0.4.1 (27/Apr/2014)
35+
* Added shortcut for `this.$scope`. You can now reference the $scope with `this.$`, although `this.$scope` still works fine

angular-classy.coffee

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
###
2-
Angular Classy 0.4
2+
Angular Classy 0.4.1
33
Dave Jeffery, @DaveJ
44
License: MIT
55
###
@@ -13,6 +13,8 @@ defaults =
1313
addFnsToScope: true
1414
watchObject: true
1515
_scopeName: '$scope'
16+
_scopeShortcut: true
17+
_scopeShortcutName: '$'
1618
_watchKeywords:
1719
objectEquality: ['{object}', '{deep}']
1820
collection: ['{collection}', '{shallow}']
@@ -83,6 +85,7 @@ classFns =
8385
bindDependencies: (parent, args) ->
8486
injectObject = parent.__classyControllerInjectObject
8587
injectObjectMode = !!injectObject
88+
options = parent.constructor::__options
8689

8790
# Takes the `$inject` dependencies and assigns a class-wide (`@`) variable to each one.
8891
for key, i in parent.constructor.$inject
@@ -91,6 +94,10 @@ classFns =
9194
else
9295
parent[key] = args[i]
9396

97+
if key is options._scopeName and options._scopeShortcut
98+
# Add a shortcut to the $scope (by default `this.$`)
99+
parent[options._scopeShortcutName] = parent[key]
100+
94101
registerWatchers: (parent) ->
95102
# Iterates over the watch object and creates the appropriate `$scope.$watch` listener
96103
$scope = parent[parent.constructor::__options._scopeName]

angular-classy.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
/*
3-
Angular Classy 0.4
3+
Angular Classy 0.4.1
44
Dave Jeffery, @DaveJ
55
License: MIT
66
*/
@@ -19,6 +19,8 @@ License: MIT
1919
addFnsToScope: true,
2020
watchObject: true,
2121
_scopeName: '$scope',
22+
_scopeShortcut: true,
23+
_scopeShortcutName: '$',
2224
_watchKeywords: {
2325
objectEquality: ['{object}', '{deep}'],
2426
collection: ['{collection}', '{shallow}']
@@ -106,17 +108,23 @@ License: MIT
106108
return _results;
107109
},
108110
bindDependencies: function(parent, args) {
109-
var i, injectName, injectObject, injectObjectMode, key, _i, _len, _ref, _results;
111+
var i, injectName, injectObject, injectObjectMode, key, options, _i, _len, _ref, _results;
110112
injectObject = parent.__classyControllerInjectObject;
111113
injectObjectMode = !!injectObject;
114+
options = parent.constructor.prototype.__options;
112115
_ref = parent.constructor.$inject;
113116
_results = [];
114117
for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
115118
key = _ref[i];
116119
if (injectObjectMode && (injectName = injectObject[key]) && injectName !== '.') {
117120
_results.push(parent[injectName] = args[i]);
118121
} else {
119-
_results.push(parent[key] = args[i]);
122+
parent[key] = args[i];
123+
if (key === options._scopeName && options._scopeShortcut) {
124+
_results.push(parent[options._scopeShortcutName] = parent[key]);
125+
} else {
126+
_results.push(void 0);
127+
}
120128
}
121129
}
122130
return _results;

angular-classy.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bower.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "angular-classy",
33
"main": "angular-classy.js",
4-
"version": "0.4.0",
4+
"version": "0.4.1",
55
"homepage": "https://github.com/davej/angular-classy",
66
"authors": [
77
"Dave Jeffery <[email protected]>"
@@ -17,7 +17,7 @@
1717
],
1818
"license": "MIT",
1919
"dependencies": {
20-
"angular": "~1.2"
20+
"angular": "^1.2"
2121
},
2222
"ignore": [
2323
"**/.*",

examples/todomvc/js/controllers/todoCtrl.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@ todomvc.classy.controller({
1212
inject: ['$scope', '$location', 'todoStorage', 'filterFilter'],
1313

1414
init: function() {
15-
this.todos = this.$scope.todos = this.todoStorage.get();
15+
this.todos = this.$.todos = this.todoStorage.get();
1616

1717
this.$scope.newTodo = '';
18-
this.$scope.editedTodo = null;
18+
this.$.editedTodo = null;
1919

2020
if (this.$location.path() === '') {
2121
this.$location.path('/');
2222
}
23-
this.$scope.location = this.$location;
23+
this.$.location = this.$location;
2424
},
2525

2626
watch: {
2727
'location.path()': function(path) {
28-
this.$scope.statusFilter = (path === '/active') ?
28+
this.$.statusFilter = (path === '/active') ?
2929
{ completed: false } : (path === '/completed') ?
3030
{ completed: true } : null;
3131
},
@@ -34,16 +34,16 @@ todomvc.classy.controller({
3434

3535

3636
_onTodoChange: function (newValue, oldValue) {
37-
this.$scope.remainingCount = this.filterFilter(this.todos, { completed: false }).length;
38-
this.$scope.completedCount = this.todos.length - this.$scope.remainingCount;
39-
this.$scope.allChecked = !this.$scope.remainingCount;
37+
this.$.remainingCount = this.filterFilter(this.todos, { completed: false }).length;
38+
this.$.completedCount = this.todos.length - this.$scope.remainingCount;
39+
this.$.allChecked = !this.$.remainingCount;
4040
if (newValue !== oldValue) { // This prevents unneeded calls to the local storage
4141
this.todoStorage.put(this.todos);
4242
}
4343
},
4444

4545
addTodo: function () {
46-
var newTodo = this.$scope.newTodo.trim();
46+
var newTodo = this.$.newTodo.trim();
4747
if (!newTodo.length) {
4848
return;
4949
}
@@ -53,21 +53,21 @@ todomvc.classy.controller({
5353
completed: false
5454
});
5555

56-
this.$scope.newTodo = '';
56+
this.$.newTodo = '';
5757
},
5858

5959
editTodo: function (todo) {
60-
this.$scope.editedTodo = todo;
60+
this.$.editedTodo = todo;
6161
// Clone the original todo to restore it on demand.
62-
this.$scope.originalTodo = angular.extend({}, todo);
62+
this.$.originalTodo = angular.extend({}, todo);
6363
},
6464

6565
doneEditing: function (todo) {
66-
this.$scope.editedTodo = null;
66+
this.$.editedTodo = null;
6767
todo.title = todo.title.trim();
6868

6969
if (!todo.title) {
70-
this.$scope.removeTodo(todo);
70+
this.$.removeTodo(todo);
7171
}
7272
},
7373

0 commit comments

Comments
 (0)