Concatenating Observable values?

Hej fuse,
Another noob Observable question, I’m afraid. I’m getting my head around using Observables better, but have been stuck on this for a little while. I’m trying to concatenate the values of several observables, but the concatenation doesn’t seem to update in the UX (I can get it to in console?).

Here if we change the Obs1 to say, 12, the {concat} doesn’t update. I’ve tried a lot of variations such as wrapping the entire concat as a variable, and trying to log out the values but can’t seem to find the solution. Any help muchly appreciated :slight_smile:

<App>
  <JavaScript>
  var Observable = require("FuseJS/Observable");
  var Obs1 = Observable(1);
  var Obs2 = Observable(2);
  var concat = Obs1.value + Obs2.value;
  
    Obs1.onValueChanged(module, function(item) {
      var concat = Obs1.value + Obs2.value;
    });
    module.exports =  {
      Obs1: Obs1,
      Obs2: Obs2,
      concat: concat
    };
  </JavaScript>
  <ClientPanel>
    <StackPanel>
  <TextView Value="{Obs1}" />
  <TextView Value="{Obs2}" />
  <TextView Value="{concat}" />

</StackPanel>
</ClientPanel>
</App>

That’s because concat is not an Observable itself. You should look at https://www.fusetools.com/docs/fusejs/observable-api#observable-functions

Juani Serra wrote:

That’s because concat is not an Observable itself. You should look at https://www.fusetools.com/docs/fusejs/observable-api#observable-functions

Thanks so much dude.

You shouldn’t forget about other beautiful Observable methods, such as combine and combineLatest.

The latter could be especially helpful in this particular case:

var Obs1 = Observable(1);
var Obs2 = Observable(2);
var concat = Obs1.combineLatest(Obs2, function(val1, val2) {
    return val1 + "" + val2;
});