# Observable not working with function map

**URL:** <https://forums.fusetools.com/t/observable-not-working-with-function-map/4109>\
**Category:** Bug Reports\
**Created:** [March 6, 2016, 5:53pm UTC](https://forums.fusetools.com/t/observable-not-working-with-function-map/4109 "2016-03-06T17:53:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nico.ronconi](https://avatars.discourse-cdn.com/v4/letter/n/ecd19e/32.png) [@nico.ronconi](https://forums.fusetools.com/u/nico.ronconi)\
**Post date:** [March 6, 2016, 5:53pm UTC](https://forums.fusetools.com/t/observable-not-working-with-function-map/4109/1 "2016-03-06T17:53:55Z")

</div>

Hi guys,

I’m stuck with Observable objects.

I’m making a simple registration page like this:

```auto
<DockPanel ux:Class="Registration">
    <JavaScript File="registration.js" />
    <StatusBarBackground Dock="Top" />
        <ScrollView>
            <TextInput Value="{name}" PlaceholderText="Insert Your Fist Name"/>
            <Button Height="50" Text="Register" Clicked="{Register}">
        </ScrollView>
</DockPanel>

```

This is my Javascript File:

```auto
var Observable = require('FuseJS/Observable');

var name = Observable("");

var isName = name.map(function(name){
    return name != "";
});

function Register(){
    debug_log(isName.value);
}

module.exports = {
    Register: Register,
    name: name
};

```

With the variable isName i check in real time if the variable name is not null.

But it doesn’t work in that way.

I see that this code works when i export the variable isName and if i ONLY USE IT in my ux file (for example if i use `<Text Value="{isName}" />`)

It doens’t works untill i use that variable in my ux file…

Why? D:

Thanks for the help! 🙂

---

<div class="post-metadata">

**Author:** ![Anders\_Lassen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/anders_lassen/32/522_2.png) [@Anders\_Lassen](https://forums.fusetools.com/u/Anders_Lassen)\
**Post date:** [March 6, 2016, 8:15pm UTC](https://forums.fusetools.com/t/observable-not-working-with-function-map/4109/2 "2016-03-06T20:15:50Z")

</div>

Hi!

Observables don’t compute until they are used (subscribed to) by someone. This happens when you use them in the UI. This is a common pattern with observables to avoid memory leaks when parts of the UI become unused.

You can also subscribe to your observables in javascript, like this:

```auto
isName.addSubscriber(function() {
    debug_log(isName.value);
});

```

---

<div class="post-metadata">

**Author:** ![nico.ronconi](https://avatars.discourse-cdn.com/v4/letter/n/ecd19e/32.png) [@nico.ronconi](https://forums.fusetools.com/u/nico.ronconi)\
**Post date:** [March 6, 2016, 9:25pm UTC](https://forums.fusetools.com/t/observable-not-working-with-function-map/4109/3 "2016-03-06T21:25:08Z")

</div>

Gotcha!

It helped me a lot.

Thanks! 🙂

---

<div class="post-metadata">

**Author:** ![LuisRodriguezLD](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/luisrodriguezld/32/616_2.png) [@LuisRodriguezLD](https://forums.fusetools.com/u/LuisRodriguezLD)\
**Post date:** [June 3, 2016, 6:29pm UTC](https://forums.fusetools.com/t/observable-not-working-with-function-map/4109/4 "2016-06-03T18:29:15Z")

</div>

I did not know this. Thank you so much!

Quick question. How would I suscribe to my observables (as you mentioned)

> You can also subscribe to your observables in javascript, like this:
> 
> ```uno
> isName.addSubscriber(function() {
> debug_log(isName.value);
> });
> 
> ```

in the following example? I want to print fullName.value to the console

```ux
<App>
    <Panel>
        <JavaScript>
            var Observable = require("FuseJS/Observable");

            var firstName = Observable('John');
            var lastName = Observable('Doe');

            var fullName = Observable(function() {
                return firstName.value + ' ' + lastName.value;
            })

            console.log(fullName.value);
        </JavaScript>

    </Panel>
</App>

```
