Created
November 30, 2016 20:40
-
-
Save featherart/b56b8c4750a060c97242a375e52d0edb to your computer and use it in GitHub Desktop.
composable helpers
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
import Ember from 'ember'; | |
import joinWith from '../utils/join-with'; | |
export default Ember.Controller.extend({ | |
firstName: 'Jim', | |
lastName: 'Bob', | |
fullName(): joinWith('', 'firstName', 'lastName') | |
}); | |
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
{ | |
"version": "0.10.6", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "2.9.0", | |
"ember-data": "2.9.0", | |
"ember-template-compiler": "2.9.0", | |
"ember-testing": "2.9.0" | |
}, | |
"addons": {} | |
} |
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
import Ember from 'ember'; | |
const { computed, get } = Ember; | |
export default function joinWith(separator, ...dependentKeys) { | |
return computed(...dependentKeys, function() { | |
return dependentKeys | |
.map((keyName) => get(this, keyName)) | |
.join(separator); | |
}); | |
} | |
export default joinWith2(separator, ...dependentKeys) { | |
return computed(firstKey, secondKey, function() { | |
return firstKey + ' ' + secondKey; | |
}); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment