Skip to content

Instantly share code, notes, and snippets.

@kellysutton
Last active August 29, 2015 14:25
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 kellysutton/97e715bca80ccb911010 to your computer and use it in GitHub Desktop.
Save kellysutton/97e715bca80ccb911010 to your computer and use it in GitHub Desktop.
cleanup.js
import Ember from 'ember';
const { computed, on } = Ember;
// Our Higher Order Function, as before
let has = field => computed.notEmpty(field);
// The Component UI fields as before.
const UI_FIELDS = ['userName', 'password'];
// Pre-generate an object with the properties and computed
// properties that we need.
var processedAttrs = {};
UI_FIELDS.forEach( (field) => {
processedAttrs[field] = '';
processedAttrs[`has${field.capitalize()}`] = has(field);
});
// Create a Component just as you normally would.
let LoginComponent = Ember.Component.extend({
// Your usual Ember component stuff in here as needed
debugOutput: on('init', function(){
console.log('hasPassword=', this.get('hasPassword'));
console.log('hasUserName=', this.get('hasUserName'));
})
});
// Export the component with an extra extension of our pre
// generated attributes and computed properties.
export default LoginComponent.extend(processedAttrs);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment