Created
September 25, 2018 22:16
-
-
Save vasilionjea/1b4d97947a83abee828958015dd89c68 to your computer and use it in GitHub Desktop.
Computed Property for "wrapped items"
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'; | |
export default Ember.Controller.extend({ | |
canCreate: true, | |
hasMax: true, | |
items: [ | |
{ isEnabled: true, name: 'duplicate'}, | |
{ isEnabled: true, name: 'edit'}, | |
], | |
renderedItems: Ember.computed('items.[]', 'canCreate', 'hasMax', function() { | |
const { items, canCreate, hasMax } = this.getProperties('items', 'canCreate', 'hasMax'); | |
return items.map(item => { | |
const canNotDuplicate = item.name === 'duplicate' && hasMax; | |
const canNotEdit = item.name === 'edit' && !canCreate; | |
const wrappedItem = Object.assign({ | |
isDisabled: (!item.isEnabled || canNotDuplicate || canNotEdit) | |
}, item); | |
return wrappedItem; | |
}); | |
}), | |
}); |
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
body { | |
margin: 12px 16px; | |
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; | |
font-size: 12pt; | |
} | |
ul, li { | |
margin: 0; | |
padding: 0; | |
list-style: none; | |
} | |
li { | |
display: flex; | |
align-items: center; | |
justify-content: space-between; | |
padding: 1rem; | |
border: 1px solid #c8c8c8; | |
margin-bottom: .5rem; | |
} |
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.15.0", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js", | |
"ember": "3.2.2", | |
"ember-template-compiler": "3.2.2", | |
"ember-testing": "3.2.2" | |
}, | |
"addons": { | |
"ember-data": "3.2.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment