HenrikJoreteg/human-model — pull request #5 by latentflip (2013-09-14 17:31:26+00:00)
Title: Add custom datatypes [for discussion]

Hey,

So this is a modification I have made already. It's not perfect so I am just opening it for discussion.

One thing I have in my base backbone mods for float is being able to set datatypes. You have this in human model, but you can't customize the available datatypes. For example, in float I want to use moment for dates, and SimpleDecimal for monetary values. I can achieve this with this mod like this, in an initializer script:

It's not perfect (I don't like having to return the type, but it's working pretty nice for me.

```
HumanModel = require('human-model')
moment = require('moment')

HumanModel.dataTypes.decimal = {
set: (val) ->
{
type: 'decimal',
val: new SimpleDecimal(val)
}
}

HumanModel.dataTypes.date = {
set: (val) ->
{
type: 'date'
val: moment(val).toISOString()
}
get: (val) ->
moment(val)
}
```

Does it make sense what I am getting at?