infinitered / rmq

RMQ - RubyMotionQuery
MIT License
307 stars 52 forks source link

replace children sugar #232

Open twerth opened 9 years ago

twerth commented 9 years ago

Jamon and I discussed this new feature, you can do this now with rmq, but this is symantically very nice:

    rmq(@my_view).replace_children do |view_q|
      @emails.each |email|
        view_q.append(UILabel, :email_address).data(email.url)
      end

      view_q.size_to_fit
    end

replace_children will simply remove all children, then return rmq(@my_view), which can be used with Jamon's new do syntax. So really replace children is just a nicer way to do rmq(@my_view).children.remove.back (assuming that works with remove).

What do you fellow contributors think?

jamonholmgren commented 9 years ago

This will help with some of the semantics in discussion over on RedPotion. https://github.com/infinitered/redpotion/issues/63

squidpunch commented 9 years ago

we have a few places that we replace all the views when something happens (like a user enters their weight, and we want to remove an empty state and show a current state, I could see this being a bit cleaner with something like this in place.

In my case its messy either way, I think - but this might be less messy :)