Skip to content

Instantly share code, notes, and snippets.

@lancejpollard
Created November 22, 2012 04:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lancejpollard/ef874fd122d4b66ef354 to your computer and use it in GitHub Desktop.
Save lancejpollard/ef874fd122d4b66ef354 to your computer and use it in GitHub Desktop.
Tower Param/Serializer API Ideas
// 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