jamonholmgren / ProMotion

ProMotion is a RubyMotion gem that makes iPhone development less like Objective-C and more like Ruby.
MIT License
1.26k stars 148 forks source link

Screens - subscribe to events #7

Closed jamonholmgren closed 11 years ago

jamonholmgren commented 11 years ago

Let's add an abstraction to NSNotification (perhaps as a separate gem that integrates with ProMotion).

Example:

class SomeScreen < ProMotion::Screen
  def will_appear
    subscribe_to :an_event, action: :handle_an_event
  end
  def handle_an_event
    # handle it
  end
end

# some other class
  broadcast :an_event
silasjmatson commented 11 years ago

We may not want to do it in the will_appear, as we would register the observer multiple times.

class SomeScreen < ProMotion::Screen

  listen_for :an_event, action: :handle_an_event

  def handle_an_event(args={})
    # handle it
  end
end

Perhaps like this?

jamonholmgren commented 11 years ago

You may want to make the listener conditional though. We can make it a hash which would only register it once even if called multiple times.

jamonholmgren commented 11 years ago

listen_for sounds better than subscribe_to -- good idea.

macfanatic commented 11 years ago

I would rather see smaller items like this left to the other two big frameworks, BubbleWrap & SugarCube, both of which already have this implementation.

On Dec 17, 2012, at 2:08 PM, Jamon Holmgren notifications@github.com wrote:

You may want to make the listener conditional though. We can make it a hash which would only register it once even if called multiple times.

— Reply to this email directly or view it on GitHub.

jamonholmgren commented 11 years ago

Good point. We definitely want ProMotion to tie in well with both of those frameworks. We'll look into their implementations and close this if they work well enough.

jamonholmgren commented 11 years ago

I like Sugarcube's implementation, but we won't force either on the user. I'll close this. Good suggestion, @macfanatic.