-
Notifications
You must be signed in to change notification settings - Fork 190
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
Emitted values are nested too deep in domStreams #61
Comments
.map( (payload, event) ) |
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 export default {
name: "parent",
methods: {
onChildChange(value) {
// do something with value
},
},
components: {
ChildComponent,
},
}; But as soon as you use {
event: {
// …
msg: "…", // the value passed from the ChildComponent
// …
},
data: { /* … */ }
} I understand that the first layer of nesting is there so you can add 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 🙏 |
The outputs of Above them all you can directly convert the method |
Thanks, @regou. Your tip on 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.) |
Imagine a
<parent>
component that contains a<child>
component.The
ChildComponent
emits a"change"
event, passing avalue
:In the
ParentComponent
we use a stream to listen to those"change"
events from theChildComponent
.Notice that the
value
emitted by theChildComponent
is nested two layers deep, meaning I have to.map(payload => payload.event.msg)
to retrieve it. This feels unnecessarily complicated.Is there some way to simplify this? What feels cleaner to me is one of the following in the parent component.
.map((payload, event) => event.msg)
.map((payload, value) => value)
.map((value, payload) => value)
Is there some way to cleanly achieve this for all vue-rx stream bindings? Am I approaching this the wrong way?
The text was updated successfully, but these errors were encountered: