Created
April 29, 2014 21:14
-
-
Save rmosolgo/88139e743bc0f74f5a35 to your computer and use it in GitHub Desktop.
Batman.js calcuated properties over collections
This file contains hidden or 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
| class App.Sale extends Batman.Model | |
| @hasMany 'sale_items' | |
| @accessor 'total_price', -> | |
| memo = 0 | |
| # adds 'sale_items' and each item as a source | |
| @get('sale_items').forEach (item) -> | |
| memo += item.get('subtotal') | |
| memo | |
| class App.SaleItem extends Batman.Model | |
| # adds quantity and price as sources | |
| @accessor 'subtotal', -> @get('quantity') * @get('price') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment