New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add more computed macros #2219

Merged
merged 1 commit into from Mar 26, 2013

Conversation

Projects
None yet
5 participants
@tchak
Member

tchak commented Mar 5, 2013

  • empty
  • notEmpty
  • not
  • bool
  • match
  • equal
  • gt
  • gte
  • lt
  • lte
@tchak

This comment has been minimized.

Show comment
Hide comment
@tchak

tchak Mar 5, 2013

Member

@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.

Member

tchak commented Mar 5, 2013

@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.

@stefanpenner

This comment has been minimized.

Show comment
Hide comment
@stefanpenner

stefanpenner Mar 5, 2013

Member

@tchak ember recent changed its empty -> isEmpty should the macro follow this pattern?

Member

stefanpenner commented Mar 5, 2013

@tchak ember recent changed its empty -> isEmpty should the macro follow this pattern?

@tchak

This comment has been minimized.

Show comment
Hide comment
@tchak

tchak Mar 5, 2013

Member

@stefanpenner I would prefer not to...

Member

tchak commented Mar 5, 2013

@stefanpenner I would prefer not to...

@stefanpenner

This comment has been minimized.

Show comment
Hide comment
@stefanpenner

stefanpenner Mar 5, 2013

Member

we already have: not empty bool

we may want or and any
or: returns the first truthy value
any: returns true if any value is truth, else false

Member

stefanpenner commented Mar 5, 2013

we already have: not empty bool

we may want or and any
or: returns the first truthy value
any: returns true if any value is truth, else false

@stefanpenner

This comment has been minimized.

Show comment
Hide comment
@stefanpenner

stefanpenner Mar 5, 2013

Member

and would be useful

Member

stefanpenner commented Mar 5, 2013

and would be useful

@tchak

This comment has been minimized.

Show comment
Hide comment
@tchak

tchak Mar 5, 2013

Member

or any and should take an arbitrary number of keys ?

Member

tchak commented Mar 5, 2013

or any and should take an arbitrary number of keys ?

@stefanpenner

This comment has been minimized.

Show comment
Hide comment
@stefanpenner
Member

stefanpenner commented Mar 5, 2013

yup

@stefanpenner

This comment has been minimized.

Show comment
Hide comment
@stefanpenner

stefanpenner Mar 5, 2013

Member
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)
Member

stefanpenner commented Mar 5, 2013

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)
@tchak

This comment has been minimized.

Show comment
Hide comment
@tchak

tchak Mar 5, 2013

Member

I am confused on the difference between or and any ? one of them should return the value where the other one juste a boolean?

Member

tchak commented Mar 5, 2013

I am confused on the difference between or and any ? one of them should return the value where the other one juste a boolean?

@stefanpenner

This comment has been minimized.

Show comment
Hide comment
@stefanpenner
Member

stefanpenner commented Mar 5, 2013

@tchak yup

@devinus

This comment has been minimized.

Show comment
Hide comment
@devinus

devinus Mar 7, 2013

Member

All of this seems...so familiar...

Member

devinus commented Mar 7, 2013

All of this seems...so familiar...

@stefanpenner

This comment has been minimized.

Show comment
Hide comment
@stefanpenner
Member

stefanpenner commented Mar 7, 2013

@devinus of what?

@devinus

This comment has been minimized.

Show comment
Hide comment
@devinus

devinus Mar 7, 2013

Member

@stefanpenner Last time this came up.

Member

devinus commented Mar 7, 2013

@stefanpenner Last time this came up.

@devinus

This comment has been minimized.

Show comment
Hide comment
@devinus

devinus Mar 7, 2013

Member

And the time before that.

Member

devinus commented Mar 7, 2013

And the time before that.

@devinus

This comment has been minimized.

Show comment
Hide comment
@devinus

devinus Mar 7, 2013

Member

Also when it came up in SproutCore.

Member

devinus commented Mar 7, 2013

Also when it came up in SproutCore.

@devinus

This comment has been minimized.

Show comment
Hide comment
@devinus

devinus Mar 7, 2013

Member

For the record, I love having common CP macros like this already available to me.

Member

devinus commented Mar 7, 2013

For the record, I love having common CP macros like this already available to me.

@chrisoverzero

This comment has been minimized.

Show comment
Hide comment
@chrisoverzero

chrisoverzero Mar 23, 2013

I also think that having these available would be useful. I was surprised to learn that computed properties can't be (for example) logically &&ed together:

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.

chrisoverzero commented Mar 23, 2013

I also think that having these available would be useful. I was surprised to learn that computed properties can't be (for example) logically &&ed together:

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.

@stefanpenner

This comment has been minimized.

Show comment
Hide comment
@stefanpenner

stefanpenner Mar 24, 2013

Member

@chrisoverzero

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.

Member

stefanpenner commented Mar 24, 2013

@chrisoverzero

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.

@stefanpenner

This comment has been minimized.

Show comment
Hide comment
@stefanpenner

stefanpenner Mar 24, 2013

Member

@tchak if you can add some tests for the new computed macro's I will merge these in.

Member

stefanpenner commented Mar 24, 2013

@tchak if you can add some tests for the new computed macro's I will merge these in.

@tchak

This comment has been minimized.

Show comment
Hide comment
@tchak

tchak Mar 25, 2013

Member

@stefanpenner added some tests

Member

tchak commented Mar 25, 2013

@stefanpenner added some tests

stefanpenner added a commit that referenced this pull request Mar 26, 2013

@stefanpenner stefanpenner merged commit 2f07ae3 into emberjs:master Mar 26, 2013

1 check passed

default The Travis build passed
Details
@stefanpenner

This comment has been minimized.

Show comment
Hide comment
@stefanpenner

stefanpenner Mar 26, 2013

Member

BOOOM

Member

stefanpenner commented Mar 26, 2013

BOOOM

@karlguillotte

This comment has been minimized.

Show comment
Hide comment
@karlguillotte

karlguillotte Mar 26, 2013

Contributor

Thank you @stefanpenner and @tchak. That is a nice addition to the API.

Contributor

karlguillotte commented Mar 26, 2013

Thank you @stefanpenner and @tchak. That is a nice addition to the API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment