Skip to content

Commit 09b8b33

Browse files
committed
Allow shorthand setting of options across all plugins. Closes #42.
1 parent 00c5204 commit 09b8b33

File tree

5 files changed

+37
-15
lines changed

5 files changed

+37
-15
lines changed

angular-classy.coffee

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ availablePlugins = {}
1212
alreadyRegisteredModules = {};
1313

1414
getActiveClassyPlugins = (name, origModule) ->
15+
# TODO: Write a test to ensure that this method gets called the correct amount of times
1516
obj = {}
1617
alreadyRegisteredModules[name] = true
1718
do getNextRequires = (name) ->
@@ -62,7 +63,7 @@ angular.module = (name, reqs, configFn) ->
6263
if name is 'classy.core' then availablePlugins[name] = {}
6364

6465
activeClassyPlugins = getActiveClassyPlugins(name, module)
65-
66+
6667
if activeClassyPlugins['classy.core']
6768
module.classy =
6869
plugin:
@@ -115,11 +116,16 @@ classFns =
115116
classObj.__options
116117
)
117118

119+
shorthandOptions = {}
120+
for optionName, option of options
121+
if !angular.isObject(option)
122+
shorthandOptions[optionName] = option
123+
118124
classConstructor::__plugins = {}
119125
for pluginName, plugin of module.classy.activePlugins
120126
classConstructor::__plugins[pluginName] = angular.copy(plugin)
121127
classConstructor::__plugins[pluginName].classyOptions = options
122-
classConstructor::__plugins[pluginName].options = options[plugin.name] or {}
128+
classConstructor::__plugins[pluginName].options = angular.extend(options[plugin.name] or {}, shorthandOptions);
123129

124130
pluginDo 'preInitBefore', [classConstructor, classObj, module]
125131
pluginDo 'preInit', [classConstructor, classObj, module]
@@ -176,6 +182,7 @@ classFns =
176182
return
177183

178184
angular.module('classy.core', [])
185+
179186
angular.module('classy.bindData', ['classy.core']).classy.plugin.controller
180187
# Based on @wuxiaoying's classy-initScope plugin
181188
localInject: ['$parse']

angular-classy.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,20 +143,27 @@ License: MIT
143143
classFns = {
144144
localInject: ['$q'],
145145
preInit: function(classConstructor, classObj, module) {
146-
var key, options, plugin, pluginName, value, _ref;
146+
var key, option, optionName, options, plugin, pluginName, shorthandOptions, value, _ref;
147147
for (key in classObj) {
148148
if (!__hasProp.call(classObj, key)) continue;
149149
value = classObj[key];
150150
classConstructor.prototype[key] = value;
151151
}
152152
options = copyAndExtendDeep({}, module.__classyDefaults, module.classy.options.controller, classObj.__options);
153+
shorthandOptions = {};
154+
for (optionName in options) {
155+
option = options[optionName];
156+
if (!angular.isObject(option)) {
157+
shorthandOptions[optionName] = option;
158+
}
159+
}
153160
classConstructor.prototype.__plugins = {};
154161
_ref = module.classy.activePlugins;
155162
for (pluginName in _ref) {
156163
plugin = _ref[pluginName];
157164
classConstructor.prototype.__plugins[pluginName] = angular.copy(plugin);
158165
classConstructor.prototype.__plugins[pluginName].classyOptions = options;
159-
classConstructor.prototype.__plugins[pluginName].options = options[plugin.name] || {};
166+
classConstructor.prototype.__plugins[pluginName].options = angular.extend(options[plugin.name] || {}, shorthandOptions);
160167
}
161168
pluginDo('preInitBefore', [classConstructor, classObj, module]);
162169
pluginDo('preInit', [classConstructor, classObj, module]);

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.

examples/todomvc/js/controllers/todoCtrl-asController.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ todomvc.classy.controller({
1212
name: 'TodoAsControllerCtrl',
1313
inject: ['$scope', '$location', 'todoStorage'],
1414
__options: {
15-
'bindData': {
16-
addToScope: false
17-
},
18-
'bindMethods': {
19-
addToScope: false
20-
}
15+
addToScope: false // shorthand for commented out code below
16+
17+
// 'bindData': {
18+
// addToScope: false
19+
// },
20+
// 'bindMethods': {
21+
// addToScope: false
22+
// }
2123
},
2224

2325
data: function() {
@@ -26,7 +28,7 @@ todomvc.classy.controller({
2628
newTodo: '',
2729
editedTodo: null,
2830
location: this.$location
29-
}
31+
};
3032
},
3133

3234
init: function() {

src/core.coffee

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ availablePlugins = {}
1212
alreadyRegisteredModules = {};
1313

1414
getActiveClassyPlugins = (name, origModule) ->
15+
# TODO: Write a test to ensure that this method gets called the correct amount of times
1516
obj = {}
1617
alreadyRegisteredModules[name] = true
1718
do getNextRequires = (name) ->
@@ -62,7 +63,7 @@ angular.module = (name, reqs, configFn) ->
6263
if name is 'classy.core' then availablePlugins[name] = {}
6364

6465
activeClassyPlugins = getActiveClassyPlugins(name, module)
65-
66+
6667
if activeClassyPlugins['classy.core']
6768
module.classy =
6869
plugin:
@@ -115,11 +116,16 @@ classFns =
115116
classObj.__options
116117
)
117118

119+
shorthandOptions = {}
120+
for optionName, option of options
121+
if !angular.isObject(option)
122+
shorthandOptions[optionName] = option
123+
118124
classConstructor::__plugins = {}
119125
for pluginName, plugin of module.classy.activePlugins
120126
classConstructor::__plugins[pluginName] = angular.copy(plugin)
121127
classConstructor::__plugins[pluginName].classyOptions = options
122-
classConstructor::__plugins[pluginName].options = options[plugin.name] or {}
128+
classConstructor::__plugins[pluginName].options = angular.extend(options[plugin.name] or {}, shorthandOptions);
123129

124130
pluginDo 'preInitBefore', [classConstructor, classObj, module]
125131
pluginDo 'preInit', [classConstructor, classObj, module]
@@ -175,4 +181,4 @@ classFns =
175181
pluginDo 'postInitAfter', [klass, deps, module]
176182
return
177183

178-
angular.module('classy.core', [])
184+
angular.module('classy.core', [])

0 commit comments

Comments
 (0)