add more computed macros#2219
Conversation
|
@stefanpenner let me know if you think some are useless and if some are missing. I will add tests once we decided on the list of macros to add. |
|
@tchak ember recent changed its empty -> isEmpty should the macro follow this pattern? |
|
@stefanpenner I would prefer not to... |
|
|
|
|
|
yup |
Em.computed.and = (dependentKeys)->
dependentKeys = Ember.makeArray(dependentKeys)
computed = (->
properties = @getProperties.apply(@, dependentKeys)
for name, value of properties
return false unless value
true
)
computed.property.apply(computed, dependentKeys)
Em.computed.or = (dependentKeys)->
dependentKeys = Ember.makeArray(dependentKeys)
computed = (->
properties = @getProperties.apply(@, dependentKeys)
for name, value of properties
return true if value
false
)
computed.property.apply(computed, dependentKeys)
Em.computed.map = (properties)->
computed = (->
for property, value of @getProperties(properties)
if Ember.empty(value)
null
else
value
)
computed.property.apply(computed, properties)
|
|
I am confused on the difference between |
|
@tchak yup |
|
All of this seems...so familiar... |
|
@devinus of what? |
|
@stefanpenner Last time this came up. |
|
And the time before that. |
|
Also when it came up in SproutCore. |
|
For the record, I love having common CP macros like this already available to me. |
|
I also think that having these available would be useful. I was surprised to learn that computed properties can't be (for example) logically showSummary: Ember.computed.bool('context.summary') && Ember.computed.bool('parentView.onIndex')Having a clear, best alternative to what appears to be a sensible operation would be helpful. |
|
current possible: hasSummary: Ember.computed.bool('context.summary')
parentViewHasOnIndex: Ember.computed.bool('parentView.onInded')
showSummary: Ember.computed.and('hasSummary', 'parentViewHasOnIndex')But you present an interesting idea. What if CP's where more more chainable. hasSummary = Ember.computed.bool('context.summary')
parentViewHasOnIndex = Ember.computed.bool('parentView.onInded')
showSummary: hasSummary.and(parentViewHasOnIndex)It would be interesting to explore. |
|
@tchak if you can add some tests for the new computed macro's I will merge these in. |
|
@stefanpenner added some tests |
|
BOOOM |
|
Thank you @stefanpenner and @tchak. That is a nice addition to the API. |
emptynotEmptynotboolmatchequalgtgteltlte