Skip to content

Instantly share code, notes, and snippets.

@featherart
Created November 30, 2016 20:40
Show Gist options
  • Save featherart/b56b8c4750a060c97242a375e52d0edb to your computer and use it in GitHub Desktop.
Save featherart/b56b8c4750a060c97242a375e52d0edb to your computer and use it in GitHub Desktop.
composable helpers
import Ember from 'ember';
import joinWith from '../utils/join-with';
export default Ember.Controller.extend({
firstName: 'Jim',
lastName: 'Bob',
fullName(): joinWith('', 'firstName', 'lastName')
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
{
"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": {}
}
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