-
-
Save lancejpollard/ef874fd122d4b66ef354 to your computer and use it in GitHub Desktop.
Tower Param/Serializer API Ideas
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
// transform|parse|format|serialize, which one? | |
App.serialize('array').to(function(string) { | |
return string.split(','); | |
}).from(function(array) { | |
return array.join(','); | |
}); | |
App.serialize('array', { | |
to: function(string) { | |
return string.split(','); | |
}, | |
from: function(array) { | |
return array.join(','); | |
} | |
}); | |
App.serialize('url', { | |
to: function() { | |
}, | |
from: function() { | |
} | |
}).serialize('phone', { | |
to: function(string) { | |
string.replace(/asdf/, ...); | |
} | |
}); | |
App.type('phone', { | |
to: function() { | |
}, | |
from: function() { | |
}, | |
// the reason you might not want to do this is b/c there | |
// could be multiple types of validations for a phone, so keep | |
// serializers and validators separate | |
validate: function(value) { | |
return !!this.to(value).match(/x/); | |
} | |
}); | |
App.param('digits', 'phone'); | |
App.param('tags', 'array'); | |
App.param('tags', {type: 'array'}).validate('in', ['ruby', 'javascript']); | |
App.param('tags', {type: 'array'}).validate(function(req) { | |
if (req.isAdmin) return true; // maybe be able to search by different things based on role | |
return ['ruby', 'javascript']; | |
}); | |
App.Router = Tower.Router.extend({ | |
route: '/', | |
action: function() { | |
}, | |
posts: Tower.Route.extend({ | |
route: '/posts', | |
index: Tower.Route.extend({ | |
route: '/', | |
tags: Tower.param('tags'), | |
title: App.Post.field('title') // maybe? | |
}) | |
}) | |
}); | |
router.get('params') // bindable ember object | |
router.get('url') // bindable ember object | |
// 1. serialization | |
// 2. param/field | |
// 3. validation |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment