Comments (12)
@maple-leaf that's a valid issue! I think it's still possible to somehow hook up the template (and especially template-only variables like v-for iterators) with an observable source.
Maybe something like this? (rough idea)
<ul>
<li v-for="item in list" @click="$toStream('itemClicks', item)"></li>
</ul>
subscriptions () {
return {
itemClicks: this.$fromStream('itemClicks').do(item => console.log(item))
}
}
from vue-rx.
Hi Evan, just back from rehearsal and glad I looked at your changes before completing my reply. Looking at the changes to the vue-rx plugin and examples I'm already impressed! Really like how you defined fromDOMEvent on the prototype, no need to wrap any RxJS operator there. It is also better for supporting alternate stream libraries 👍
The one thing that would be useful in some use cases is allowing more than one event type to be specified in the args, maybe something like fromDOMEvent('selector', ['click', 'pointermove', 'etc']). Then the stream of event types could be further filtered by RxJS or alt library operators.
Oh yeah, I added a pointer-event there because they are awesome and there was just a robust implementation of them in Vue made here: https://benjaminlistwon.com/blog/strategies-for-extending-vue
Initially I had been thinking of a directive approach that would look like this <div id="canvas" v-stream:event-type="method-name">
. However, your fromDOMEvent solution is better 💯
I think the new subscriptions option is going to become very useful. It's already doing all the intent and model aspects that Cyclejs likes to do and there can be so much more. I'll keep exploring and applying use cases to subscriptions and let you know how that goes. I'll start with these constructs: https://egghead.io/courses/rxjs-subjects-and-multicasting-operators :-)
from vue-rx.
Depending on the outcome of issue #33 maybe this issue can be closed?
from vue-rx.
Sorry for missing your issue - I think I just didn't quite understand what you wanted at first glance. Do you have an example of what your desired usage would be like?
from vue-rx.
About this , I think there is a downside of fromDOMEvent
. That's take a look of this code:
<ul><li v-for="item in list" @click="doSomeThing(item)"></li></ul>
Normally, just normal doSomeThing
function should be ok, but if we want do some debounce
or some async
, Rx.js way would be best way here. How to deal with this with fromDOMEvent
?
from vue-rx.
Having event sources from both fromDOMEvent in the subscription option and the template itself would cover pretty well all use cases. Stream and reactive loving devs will be in heaven!
from vue-rx.
How about do the stream transforming with a modifier?
<ul>
<li v-for="item in list" @click.event-stream="itemClicks(item)"></li>
</ul>
And the modifier will create a event-stream called 'itemClicks' in $eventStream
. And we can use it like this:
this.$eventStream.itemClicks.subscribe(item => console.log(item));
this.$eventStream.itemClicks.subscribe(({ item, rest } => console.log(item, rest));
This will not going to break current @click
usage, you just need a modifier if stream desired and remove it while stream is overhead.
And all event stream is in $eventStream
, vue-rx can easily unsubscribe
them when needed.
from vue-rx.
Have two alternatives here, the first still binding stream handling to the subscriptions option, while the later allowing the subscribe to happen anywhere. Both techniques are useful.
from vue-rx.
Hey, @zoomclub
I dont't think $fromDOMEvent(selector,event)
is good enough either.
@yyx990803 , I build a directive v-ob:click="click$"
, but the sourcecode are not elegant (view-model dirty hack). Any help?
from vue-rx.
@regou Nice, just a few points.
• It would be useful to be able to chain event types together to capture them all in the observable, like v-ob:mouseover.mousemove.mouseup="myMice$".
• Why not call the directive v-stream, reflecting that it is also useful with any stream library? Maybe the abbreviated form could also be $ instead of the usual @.
• Noticed the subscribe is now in mounted and not in it's own subscription object. Seems okay to use observables and make subscriptions anywhere 👍
from vue-rx.
- Keep it simple, users can just
Observable.merge
them - ok
- This is the main issue: directive's
bind
happens after component'screated
lifecycal, but subscription defined increate
(See sourcecode mixin), which means unable to accessvm.myMice$
insubscriptions
from vue-rx.
To celebrate the resolution of this issue and the release of vue-rx 3.0 I'm closing this issue 🍾
from vue-rx.
Related Issues (20)
- v-stream data is not being updated in componentInstance HOT 2
- Can't use `subscriptions` as an object. HOT 2
- [help wanted] using vue-rx in component package/plugin HOT 3
- vue renderes before observable HOT 1
- $fromDOMEvent 问题
- Vue Composition API and vue-rx HOT 12
- Created hook called multiple times HOT 4
- How do we use this library with vue3 alpha 8? HOT 2
- help me. $watchAsObservable How to execute directly once the page is loaded HOT 1
- Why have a $subscribeTo ? HOT 1
- Typings error for $observables
- How to use vue-rx with vue 3.x ? HOT 2
- using $watchAsObservable, and using throw new Error() watch not work HOT 1
- Is there any support for Vue 3? HOT 1
- Update to Rx.js 7 and adding Typescript? HOT 2
- Cannot resolve dependency in newer npm version HOT 2
- Publish v6.3.0 in npm
- How to init vuerx to vue3 HOT 3
- Remove Vue installation from the readme
- How to solve vue-rx incompatiblity with Vue3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vue-rx.