Skip to content

Add feature eventToObservable #45

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

Merged
merged 5 commits into from
Jun 13, 2017
Merged

Conversation

regou
Copy link
Collaborator

@regou regou commented Jun 5, 2017

Convert vm.$on to observable

@yyx990803
Copy link
Member

yyx990803 commented Jun 6, 2017

I think per #44 , it would be ideal that v-stream, when used on a component, would listen for the custom event stream instead using this new method. (similar to v-on)

It can be done by checking the presence of vnode.componentInstance in v-stream's bind hook. If an instance is present, then the directive is being used on a custom component, and the resulting stream should be constructed differently.

@regou
Copy link
Collaborator Author

regou commented Jun 6, 2017

I've realized that this Pr is irrelevant to issue #44 yesterday then i deleted the github reference, but the ref mark is still there.
Sorry about the confusion.

#44 is about v-stream directive
This Pr is about converting vm.$on
v-on -> v-stream
vm.$on -> vm.$eventToObservable (maybe vm.$stream?)

@regou
Copy link
Collaborator Author

regou commented Jun 6, 2017

About #44 , I tried but vnode.componentInstance in bind callback aways gets undefined https://github.com/vuejs/vue-rx/blob/master/src/directives/stream.js#L5
@yyx990803

@yyx990803
Copy link
Member

yyx990803 commented Jun 7, 2017

@regou yeah, it will be undefined if it's used on a normal element e.g. <button>. It will only be defined when v-stream is used on a custom component, e.g. <my-button v-stream="...">. So we need something like:

bind (el, binding, vnode) {
  // ...
  if (vnode.componentInstance) {
    // bind using vnode.componentInstance.$eventToObservable
  } else {
    // bind using Rx.fromEvent()
  }
}

@regou
Copy link
Collaborator Author

regou commented Jun 9, 2017

Job done 💯
But @yyx990803 , please beware :
911879a
These 3 deleted lines are not actually working.
unsub can only unsubscribe subscriptions ( return of .subscribe() call )
Better add a FAQ section on Readme about how to auto unsub #41

  • vm.$subscribeTo
  • subscriptions
  • .takeUntil(vm.$eventToObservable('hook:beforeDestroy'))

@yyx990803 yyx990803 merged commit 2a3768b into vuejs:master Jun 13, 2017
@yyx990803
Copy link
Member

Excellent job! Thanks for the great contributions you've made to this project, I've added you as a collaborator :)

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

Successfully merging this pull request may close these issues.

3 participants