Created
May 22, 2014 16:12
-
-
Save rlivsey/b6c15ff3acf361cf344c to your computer and use it in GitHub Desktop.
date query params
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
IndexController = Ember.Controller.extend | |
queryParams: ["date"] | |
date: ((k,v) -> v || moment()).property() | |
`export default IndexController` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
IndexRoute = Ember.Route.extend | |
queryParams: | |
date: | |
replace: true | |
serializeQueryParam: (value, urlKey, defaultValueType) -> | |
return @_super(value, urlKey, defaultValueType) unless value && urlKey == "date" | |
# value is not a moment at this point for some reason, but coerces fine | |
moment(value).format("YYYY-MM") | |
deserializeQueryParam: (value, urlKey, defaultValueType) -> | |
return @_super(value, urlKey, defaultValueType) unless urlKey == "date" | |
date = moment(value, "YYYY-MM") | |
date = moment() unless date.isValid() | |
date | |
`export default IndexRoute` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment