Skip to content

Commit b9e8581

Browse files
committed
refactor(value): don't assign directly to the constructor
BREAKING CHANGE: use return value from constructor Before: class MyValue extends Value @constructor = 'Hello' After: class MyValue extends Value constructor: -> return 'Hello'
1 parent 3620e03 commit b9e8581

File tree

3 files changed

+35
-32
lines changed

3 files changed

+35
-32
lines changed

README.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -634,16 +634,17 @@ angular.module('app').service('greetingService', ['$log',
634634
### Value
635635
```coffee
636636
class People extends Value
637-
@constructor = [
638-
{
639-
name: 'Luke Skywalker'
640-
age: 26
641-
}
642-
{
643-
name: 'Han Solo'
644-
age: 35
645-
}
646-
]
637+
constructor: ->
638+
return [
639+
{
640+
name: 'Luke Skywalker'
641+
age: 26
642+
}
643+
{
644+
name: 'Han Solo'
645+
age: 35
646+
}
647+
]
647648
```
648649

649650
equivalent to

lib/moduleOptions.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module.exports = (formatOptions, options) ->
1515
provider: "angular.module('{{appName}}').{{moduleType|lowerCase}} '#{formatOptions.provider.prefix}{{className|#{formatOptions.provider.format}}}#{formatOptions.provider.suffix}', [{{parameters}}]"
1616
run: "angular.module('{{appName}}').{{moduleType|lowerCase}} [{{parameters}}]"
1717
service: "angular.module('{{appName}}').{{moduleType|lowerCase}} '#{formatOptions.service.prefix}{{className|#{formatOptions.service.format}}}#{formatOptions.service.suffix}', [{{parameters}}]"
18-
value: "angular.module('{{appName}}').{{moduleType|lowerCase}} '#{formatOptions.value.prefix}{{className|#{formatOptions.value.format}}}#{formatOptions.value.suffix}', {{parameters}}.constructor"
18+
value: "angular.module('{{appName}}').{{moduleType|lowerCase}} '#{formatOptions.value.prefix}{{className|#{formatOptions.value.format}}}#{formatOptions.value.suffix}', {{className}}()"
1919
prefix: ''
2020

2121
merged = extend true, moduleOptions, options

test/ng-classify.spec.coffee

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -387,34 +387,36 @@ describe 'ng-classify', ->
387387
it 'should compile a Value', ->
388388
input = '''
389389
class People extends Value
390-
@constructor = [
391-
{
392-
name: 'Luke Skywalker'
393-
age: 26
394-
}
395-
{
396-
name: 'Han Solo'
397-
age: 35
398-
}
399-
]
390+
constructor: ->
391+
return [
392+
{
393+
name: 'Luke Skywalker'
394+
age: 26
395+
}
396+
{
397+
name: 'Han Solo'
398+
age: 35
399+
}
400+
]
400401
'''
401402

402403
result = ngClassify input
403404

404405
expectation = '''
405406
class People
406-
@constructor = [
407-
{
408-
name: 'Luke Skywalker'
409-
age: 26
410-
}
411-
{
412-
name: 'Han Solo'
413-
age: 35
414-
}
415-
]
407+
constructor: ->
408+
return [
409+
{
410+
name: 'Luke Skywalker'
411+
age: 26
412+
}
413+
{
414+
name: 'Han Solo'
415+
age: 35
416+
}
417+
]
416418
417-
angular.module('app').value 'people', People.constructor
419+
angular.module('app').value 'people', People()
418420
'''
419421

420422
expect(result).toEqual(expectation)

0 commit comments

Comments
 (0)