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

Added convenience callback block after append, build, etc, and find_or_append() (with tests) #227

Merged
merged 3 commits into from Mar 28, 2015

Conversation

Projects
None yet
4 participants
@jamonholmgren
Member

jamonholmgren commented Mar 20, 2015

We find ourselves doing a lot of .tap do |view| when we're doing layout:

append(UIView, :wrapper).tap do |wrapper|
  wrapper.append(UIView, :something).tap do |something|
    something.append(UILabel, :label).data("Hi!")
  end
end

This lets you do:

append UIView, :wrapper do |wrapper|
  wrapper.append UIView, :something do |something|
    something.append(UILabel, :label).data("Hi!")
  end
end

Specs passing locally.

Also added find_or_append and find_or_append! which do what you think they do.

rmq(self.view).find_or_append(UIView, :my_view) # added only if it isn't already in `self.view` somewhere.
@@ -132,7 +132,7 @@ def init_popup_section
def init_validation_section
# let's lay this out using the grid!
rmq.append(UIView, :validation_section).tap do |q|
rmq.append(UIView, :validation_section) do |q|

This comment has been minimized.

@jamonholmgren

jamonholmgren Mar 20, 2015

Member

Figured I'd try using the new syntax in a couple random places in the tests, to make sure it works in real world situations. I have more direct tests below.

@jamonholmgren

jamonholmgren Mar 20, 2015

Member

Figured I'd try using the new syntax in a couple random places in the tests, to make sure it works in real world situations. I have more direct tests below.

@@ -63,11 +62,14 @@ def add_subview(view_or_constant, opts={})
new_view.rmq_appended if appended
if self.stylesheet
apply_style_to_view(new_view, style) if style
apply_style_to_view(new_view, opts[:style]) if opts[:style]

This comment has been minimized.

@jamonholmgren

jamonholmgren Mar 20, 2015

Member

This was the only place the style above was used, so I just cleaned it up a tiny bit.

@jamonholmgren

jamonholmgren Mar 20, 2015

Member

This was the only place the style above was used, so I just cleaned it up a tiny bit.

view = RMQ.create_with_array_and_selectors(subviews_added, selectors, @context, self)
opts[:block].call view if opts[:block]
opts[:raw_block].call view.get if opts[:raw_block]
view

This comment has been minimized.

@jamonholmgren

jamonholmgren Mar 20, 2015

Member

This is the main place that changed. Note the raw_block: vs block: above (raw is for the bang methods).

@jamonholmgren

jamonholmgren Mar 20, 2015

Member

This is the main place that changed. Note the raw_block: vs block: above (raw is for the bang methods).

@GantMan

This comment has been minimized.

Show comment
Hide comment
@GantMan

GantMan Mar 21, 2015

Member

I love this! I could use this in a ton of places. @twerth what you thinking?

Member

GantMan commented Mar 21, 2015

I love this! I could use this in a ton of places. @twerth what you thinking?

@jamonholmgren jamonholmgren changed the title from Added convenience callback block after append, build, etc (with tests) to Added convenience callback block after append, build, etc, and find_or_append() (with tests) Mar 21, 2015

@twerth

This comment has been minimized.

Show comment
Hide comment
@twerth

twerth Mar 26, 2015

Member

I like this idea, Jamon and I went over it. I do want to review the changes to add_subview before merging this.

Member

twerth commented Mar 26, 2015

I like this idea, Jamon and I went over it. I do want to review the changes to add_subview before merging this.

twerth added a commit that referenced this pull request Mar 28, 2015

Merge pull request #227 from jamonholmgren/append-block
Added convenience callback block after append, build, etc, and find_or_append() (with tests)

@twerth twerth merged commit b682fa7 into infinitered:master Mar 28, 2015

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
@GantMan

This comment has been minimized.

Show comment
Hide comment
@GantMan

GantMan Mar 28, 2015

Member

I can't wait to change a lot of code to use this!

Member

GantMan commented Mar 28, 2015

I can't wait to change a lot of code to use this!

@jamonholmgren

This comment has been minimized.

Show comment
Hide comment
@jamonholmgren

jamonholmgren Mar 29, 2015

Member

👍 Looking forward to it as well.

Member

jamonholmgren commented Mar 29, 2015

👍 Looking forward to it as well.

@squidpunch

This comment has been minimized.

Show comment
Hide comment
@squidpunch

squidpunch Mar 30, 2015

Contributor

there are a number of places I check if something was there and only append if not - so really looking forward to find_or_append

and loving the "it just works" for chaining appends, rather than needing to tap, awesome!

Contributor

squidpunch commented Mar 30, 2015

there are a number of places I check if something was there and only append if not - so really looking forward to find_or_append

and loving the "it just works" for chaining appends, rather than needing to tap, awesome!

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