marcelpinto / RxFlux

RxFlux is a small framework in order to follow Flux design pattern with RxJava functionalities
Apache License 2.0
326 stars 38 forks source link

About onRxViewRegistered()&onRxViewUnRegistered() #8

Closed adffice closed 8 years ago

adffice commented 8 years ago

hi, how and when use onRxViewRegistered() & onRxViewUnRegistered()? can you provide some sample code. thank you very much.

marcelpinto commented 8 years ago

Hi,

This two methods are called after the activity has been attached or detached to the dispatcher, so you can use this to register fragments or view to it.

An example will be when you have a fragment attached to an activity that need to get the events of the dispatcher to. On that case you will call dispatcher.registerRxStore(yourFragment);

Then you must implement RxViewDispatcher on your fragment and you will get the store events.

But I think I may refactor this part since is not really clear. If you come with sth better let me know.

adffice commented 8 years ago

Thanks for your reply! I think it should put this interfaceRxViewDispatch split into two interfaces:

public interface RxViewDispatch {
  /**
   * All the stores will call this event so the view can react and request the needed data
   */
  void onRxStoreChanged(RxStoreChange change);
  void onRxError(RxError error);
}

and

public interface RxStoresRegister {
    void onRxStoresRegister();
    void onRxStoresUnRegister();
}
nitrico commented 8 years ago

Hi @skimarxall

I cannot see these methods being called anywhere. Is it because the library is not finished, maybe a mistake or am I missing something?

Apart from that, it is a great library :+1: Thank you :)

Damonzh commented 8 years ago

@nitrico These interface methods are called during the lifecycle of Activity or Fragment, you can find them in RxFlux.java. To get store events, you must implement the RxViewDispatche in which these callback methods are declared.

nitrico commented 8 years ago

Yes, some of them, but not these two (onRxViewRegistered and onRxViewUnRegistered) :/

marcelpinto commented 8 years ago

@nitrico you are right they are missing on the RxFlux flow, it's odd that I forgot to add them, but I wanted to rethink a bit this interface like @adffice said.

I am just a bit short in time. Next week probably I will have some time to make that change

nitrico commented 8 years ago

@skimarxall ok, thanks! If you're going to check it next week, you might also check that Store's are not being registered and unregistered on onActivityResumed and onActivityPaused (should they? I think so), only registered on onActivityCreated.

Is it ok for you if I publish a fork of this library written in Kotlin with several modifications I'm working on? If you wanna discuss them, you can find my email on my profile :)

marcelpinto commented 8 years ago

Please feel free to port it to Kotlin. Just mention this library on the description and add the open source licences of this library in your repo too.

I took a look and I did only the registration of stores on create since the stores are normally singletons and should be register at the beginning and keep register in case of background task, but, I'm agree that in some case you may want to have a store instance just for an activity, but I still think that the store should keep registered until the activity is destroied. I'll push the updates next week and we can discuss it on the PR.

On Fri, 25 Mar 2016, 07:02 Miguel Ángel Moreno, notifications@github.com wrote:

@skimarxall https://github.com/skimarxall ok, thanks! If you're going to check it next week, you might also check that Store's are not being registered and unregistered on onActivityResumed and onActivityPaused (should they? I think so), only registered on onActivityCreated.

Is it ok for you if I publish a fork of this library written in Kotlin with several modifications I'm working on? If you wanna discuss them, you can find my email on my profile :)

— You are receiving this because you were mentioned.

Reply to this email directly or view it on GitHub https://github.com/skimarxall/RxFlux/issues/8#issuecomment-201156669

marcelpinto commented 8 years ago

https://github.com/skimarxall/RxFlux/pull/10