Abstract and simplify route

This commit is contained in:
Vit Brunner
2014-12-22 09:37:59 +01:00
parent 656cfe1a58
commit 0123403929
2 changed files with 10 additions and 18 deletions
+6 -1
View File
@@ -29,9 +29,14 @@ angular.module("sideBySide").service "route", ['$location', ($location) ->
return key + ":" + val.join(',')
value
@get = () ->
(property + ':' + getValue(value) \
for property, value of @params when value)
.join('/')
@update = (key, value) ->
@params[key] = value
$location.path (property + ':' + getValue(value) for property, value of @params).join('/')
$location.path @get()
@
]
+4 -17
View File
@@ -21,32 +21,19 @@ test "has app url", () ->
test "gets parameters", () ->
setup()
deepEqual route.params, {
'asdf': 'zxcv'
'qwerty': 'asdf'
'base': ''
}
equal route.get(), 'asdf:zxcv/qwerty:asdf'
test "updates parameters", () ->
setup()
route.update('asdf', 'hjkl')
deepEqual route.params, {
'asdf': 'hjkl'
'qwerty': 'asdf'
'base': ''
}
equal route.get(), 'asdf:hjkl/qwerty:asdf'
test "adds parameter", () ->
setup()
route.update('new', 'one')
deepEqual route.params, {
'asdf': 'zxcv'
'qwerty': 'asdf'
'base': ''
'new': 'one'
}
equal route.get(), 'asdf:zxcv/qwerty:asdf/new:one'
test "gets arrays", () ->
test "processes arrays from url", () ->
setup('http://example.com', '/display:Language:Czech,English', '')
deepEqual route.params, {