Skip to content
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

Will you consider integrating reactive property? #15

Closed
singno opened this issue Jun 16, 2017 · 3 comments
Closed

Will you consider integrating reactive property? #15

singno opened this issue Jun 16, 2017 · 3 comments

Comments

@singno
Copy link

singno commented Jun 16, 2017

For example:

observe(observable) { (e) in
    cb();
}

cb();

But with reactive property I can code like this:

observable.subscribe { (e) in
    cb();
}
@joostvandijk
Copy link
Contributor

joostvandijk commented Jun 16, 2017

Hi @singno,

Do you mean that subscribing with a reactive library invokes the given closure immediately on subscribing? Or are you talking about the difference in syntax?

The first is because we felt it was more logical to not invoke the closure immediately, but only after an event is published. Hanson's 'bind' functions do invoke the closure inmediately.

The different syntax is because we wanted the instance that made the observation to own the observation. Therefore, all 'observe' and 'bind' functions are instance methods (they're called on 'self'). That way, the observing instance can keep a reference to its observations, and automatically stop and release them when the observing instance is released.

@singno
Copy link
Author

singno commented Jun 16, 2017

I mean the first one.

I know "bind" invokes immediately, but i don't know how to bind property with method. I want the observable to be reactive like RxSwift's "behaviour subject" .

Seems the syntax would be like:

bind(observable, to: self) {
      controller, value in
      controller.method(value);
}

It seems verbose.But anyway, it is an awesome lightweight library.

@joostvandijk
Copy link
Contributor

The 'bind' function with a closure was indeed designed to invoke a method like in your example. So that would be the way to do it. However, you can always add an extension with your own 'subscribe' method that behaves the way that best suits you.

Thanks for using Hanson!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants