Conditional Observables?

I am trying to get the example for conditional observables to work below:

fruits = Observable(
    { name: 'Apple' , color: 'red'    },
    { name: 'Lemon' , color: 'yellow' },
    { name: 'Pear'  , color: 'green'  },
    { name: 'Banana', color: 'yellow' });

goodFruits = fruits.where({color: 'yellow'});

console.log('Good fruits from object: ' + JSON.stringify(goodFruits));

goodFruits = fruits.where(function(e){
    return e.color === 'yellow';

console.log('Good fruits from function: ' + JSON.stringify(goodFruits));

But the output from the monitor is:

LOG: Good fruits from object: {"_subscribers":[],"_isLeaf":false,"_values":[]}
LOG: Good fruits from function: {"_subscribers":[],"_isLeaf":false,"_values":[]}

I was expecting something to be in the values for the resulting observable. Is this a bug?


This is not a bug, this is expected behavior.

Observables are not like arrays. Observables don’t calculate their values until something subscribes to them. You subscribe by making it part of your module.exports or adding an .onValueChanged listener.

That was a great explanation thank you Anders. I was not thinking about Observables in the right way even though I have been working with them for a while now. Thank you!