]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | Ext.define('KitchenSink.view.binding.TwoWayFormulaModel', {\r |
2 | extend: 'Ext.app.ViewModel',\r | |
3 | alias: 'viewmodel.binding-twowayformula',\r | |
4 | \r | |
5 | formulas: {\r | |
6 | // The calls to correctFloat here are to preserve the stability\r | |
7 | // of the values, we don't want precision rounding to cause the\r | |
8 | // viewmodel to think the data is different.\r | |
9 | celcius: {\r | |
10 | get: function(get) {\r | |
11 | return Ext.Number.correctFloat(get('kelvin') - 273.15);\r | |
12 | },\r | |
13 | set: function(v) {\r | |
14 | this.set('kelvin', Ext.Number.correctFloat(v + 273.15));\r | |
15 | }\r | |
16 | },\r | |
17 | fahrenheit: {\r | |
18 | get: function(get) {\r | |
19 | return Ext.Number.correctFloat(get('celcius') * 1.8 + 32);\r | |
20 | },\r | |
21 | set: function(v) {\r | |
22 | this.set('celcius', Ext.Number.correctFloat((v - 32) / 1.8));\r | |
23 | }\r | |
24 | }\r | |
25 | },\r | |
26 | \r | |
27 | data: {\r | |
28 | kelvin: 300.1\r | |
29 | }\r | |
30 | }); |