Last active
October 27, 2015 10:00
-
-
Save OrKoN/44aa98356747fb5ed0a7 to your computer and use it in GitHub Desktop.
Post Demo
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
import Ember from 'ember'; | |
import { formatDate, formatPhone } from '../format-macros'; | |
export default Ember.Controller.extend({ | |
localeService: Ember.inject.service('locale'), | |
formattedPhone: formatPhone('model.phone'), | |
formattedDate: formatDate('model.date', 'L') | |
}); |
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
import Ember from 'ember'; | |
export default Ember.Route.extend({ | |
model() { | |
return { | |
phone: '555-555-555', | |
date: new Date() | |
}; | |
} | |
}); |
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
import Ember from 'ember'; | |
import { formatPhone as formatPhoneFunc, formatDate as formatDateFunc } from './format-utils'; | |
let { get, computed } = Ember; | |
export var formatPhone = function(valueKey) { | |
debugger; | |
let deps = [ 'localeService.locale', valueKey]; | |
return computed(...deps, function() { | |
let locale = get(this, 'localeService.locale'); | |
return formatPhoneFunc(get(this, valueKey), locale); | |
}); | |
} | |
export var formatDate = function(valueKey, format) { | |
let deps = [ 'localeService.locale', valueKey]; | |
return computed(...deps, function() { | |
let locale = get(this, 'localeService.locale'); | |
return formatDateFunc(get(this, valueKey), format, locale); | |
}); | |
} |
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
export var formatPhone = function(value, locale) { | |
debugger; | |
return locale + ':' + value; | |
} | |
export var formatDate = function(value, format, locale) { | |
return locale + ':' + value + ' in ' + format; | |
} |
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
import { observer } from 'Ember'; | |
export default Ember.Helper.extend({ | |
localeService: Ember.inject.service('locale'), | |
onLocaleChange: observer('localeService.locale', function() { | |
this.recompute(); | |
}), | |
compute(value, format) { | |
return this.get('localeService').formatDate(value, format); | |
} | |
}); |
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
import { observer } from 'Ember'; | |
export default Ember.Helper.extend({ | |
localeService: Ember.inject.service('locale'), | |
onLocaleChange: observer('localeService.locale', function() { | |
this.recompute(); | |
}), | |
compute(value) { | |
return this.get('localeService').formatPhone(data); | |
} | |
}); |
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
import Ember from 'ember'; | |
import { formatPhone, formatDate } from '../format-utils'; | |
export default Ember.Service.extend({ | |
locale: 'en', | |
setLocale(locale) { | |
this.set('locale', locale); | |
}, | |
formatPhone(value) { | |
return formatPhone(value, this.get('locale')); | |
}, | |
formatDate(value, format) { | |
return formatDate(value, format, this.get('locale')); | |
} | |
}); |
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
{ | |
"version": "0.4.14", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "2.1.0", | |
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.1.0/ember-data.js", | |
"ember-template-compiler": "2.1.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment