Comments (4)
.map( (payload, event) )
It’s not about vue-rx, The emmiting value from Observable has to be a non-splittable singular.
The payload contains raw event Object and data from ‘v-stream’ directive
from vue-rx.
That's a good point.
After giving this some more thought, what still seems to bother me is that the value I'm trying to pass along is getting trapped inside two layers. At worst, I feel like it should be one layer.
If I simply listen to the ChildComponent
's "change"
event using standard even listeners (@change="onChildChange"
), then value
passed from the child component comes straight through as the first parameter in the handler, no nesting.
export default {
name: "parent",
methods: {
onChildChange(value) {
// do something with value
},
},
components: {
ChildComponent,
},
};
But as soon as you use vue-rx
streams, two layers of nesting are added:
{
event: {
// …
msg: "…", // the value passed from the ChildComponent
// …
},
data: { /* … */ }
}
I understand that the first layer of nesting is there so you can add data
parameters. But the second layer feels inconsistent with the fact that the standard event listener doesn't work this way.
This feels like what it should be doing:
export default {
name: "parent",
domStreams: ["changeEvents"],
subscriptions() {
this.changeEvents
- .map(payload => payload.event.msg)
+ .map(payload => payload.event) // where `event` is the value passed from `ChildComponent`
.subscribe(value => {
// do something with value
});
},
components: {
ChildComponent,
},
};
Or, if I don't pass any data parameters at all, I would actually prefer the following:
export default {
name: "parent",
domStreams: ["changeEvents"],
subscriptions() {
this.changeEvents
- .map(payload => payload.event.msg)
.subscribe(value => { // just pass along what the `ChildComponent` emitted
// do something with value
});
},
components: {
ChildComponent,
},
};
Is there a good reason both layers need to be there?
Cheers 🙏
from vue-rx.
The outputs of this.changeEvents
should be consistence in all circumstances, don't you think?
And instead of .map
you may use .pluck('event','msg')
Above them all you can directly convert the method onChildChange(value)
to observable by $createObservableMethod('onChildChange'). This api is for some child components that use callbacks.
from vue-rx.
Thanks, @regou. Your tip on $createObservableMethod()
helped me find something thats seems to work as expected. It was a variant on the counter-function example:
export default {
name: "parent",
observableMethods: ["childChange"],
subscriptions() {
this.childChange$.subscribe(value => {
// do something with value
});
},
components: {
ChildComponent,
},
};
This solves my problem. Thank you. 🙏
(It would still be great to see an example showing the full context of a child component publishing an observable stream and the parent component subscribing to it. I still don't know The Right Way to do that.)
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.