mirror of
https://github.com/wassname/side-by-side.git
synced 2026-09-11 12:44:22 +08:00
Abstract and simplify route
This commit is contained in:
@@ -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()
|
||||
|
||||
@
|
||||
]
|
||||
|
||||
@@ -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, {
|
||||
|
||||
Reference in New Issue
Block a user