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

Invalid observable found - what am I missing?! #20

Closed
kristianmandrup opened this issue Nov 9, 2016 · 3 comments
Closed

Invalid observable found - what am I missing?! #20

kristianmandrup opened this issue Nov 9, 2016 · 3 comments

Comments

@kristianmandrup
Copy link

kristianmandrup commented Nov 9, 2016

Hi guys,

I've been trying to add a subscription/observable to my component using the guide in the Readme.

  subscriptions () {
    // declaratively map to another property with Rx operators
    return {
      aPlusOne: this.$watchAsObservable('prompt.choices')
        .subscribe(({ newValue, oldValue }) => console.log('choices', newValue, oldValue))
    }
  },

However I get this error in my dev tools console. No clue as to why it is invalid. What are the rules, what am I missing. Not entirely clear from the docs. Do I need to pre-define it somewhere?

vue.common.js?4eb4:2643 [Vue warn]: Invalid Observable found in subscriptions option with key "aPlusOne". 
(found in component <prompt-checkbox> at /Users/kristianmandrup/repos/vue-projs/app-generator/app/src/components/Prompt/Checkbox.vue)

I'm trying to react to updates on a set of checkboxes in order to save those values in my store so other components can reflect on it... However I can't seem to find a way to do it.
Maybe using simple watch? I tried without luck using on-change handlers, but they only pass true|false on, so I have no idea which checkbox the changed value is coming from :O

    <md-checkbox 
      v-for="choice in prompt.choices" 
      :name="prompt.name"
      :id="prompt.name"
      @input="updateChoice"
      @change="updateChoice($event)" 
      class="md-primary" 
      v-model="choice.value">{{ choice.label }}</md-checkbox>

I always receive simply true or false in my updateChoice(e) method :(
Is watch the way to go!? or computed properties? Doesn't seem right, coz then I would have to watch/react to the entire object iterated and bound to by the checkboxes.

Please advice :) Thanks!

@yyx990803
Copy link
Member

When you call .subscribe(), the returned value is no longer an Observable but a Subscription. To produce side effects while retaining the original Observable, use .do instead of .subscribe.

@kristianmandrup
Copy link
Author

Thanks :) Please improve the docs a little to make it more clear.

@yyx990803
Copy link
Member

This is an Rx usage issue and has nothing to do with vue-rx docs. We can't help you learn Rx here.

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