# Firebase push new data

**URL:** <https://forums.fusetools.com/t/firebase-push-new-data/3185>\
**Category:** General\
**Created:** [July 28, 2017, 12:28am UTC](https://forums.fusetools.com/t/firebase-push-new-data/3185 "2017-07-28T00:28:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tom1](https://avatars.discourse-cdn.com/v4/letter/t/b487fb/32.png) [@Tom1](https://forums.fusetools.com/u/Tom1)\
**Post date:** [July 28, 2017, 12:28am UTC](https://forums.fusetools.com/t/firebase-push-new-data/3185/1 "2017-07-28T00:28:28Z")

</div>

Hey

Newbie here. Below is a js code fetching data from firebase. My question is how to reload the updated data from firebase when user tap reload button without exiting the app. I see when I exit app and open it again all the new data will be fetched. My initial thought was Observable watches any changes and push new data automatically. By reading docs, that’s not how Observable works. Any simple way to reload data without exiting app?  
Thank you

```auto
    <JavaScript>
                   var Observable = require("FuseJS/Observable");

                   var tag = Observable();
                   var dbData = Observable();

                   fetch('https://fusetags.firebaseio.com/tags.json', {
                   	method: 'GET',
                   	cache: 'default',
                   	headers: { "Content-type": "application/json"}
                   })
                       .then(function(result) {
                        if (result.status !== 200) {
                        console.log("Something went wrong :(");
                        return;}
                       	return result.json();
                     })
                        
                       .then(function(data) {
                       	var keys = Object.keys(data);
                        keys.forEach(function(key, index) {
                          if (index >= dbData.length) {
                             var value = data[key];
                             dbData.add(value);

                           }
                        })
                       });

    var reloadFunc = function ()
    {
    }

```

---

<div class="post-metadata">

**Author:** ![Uldis](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/uldis/32/657_2.png) [@Uldis](https://forums.fusetools.com/u/Uldis)\
**Post date:** [July 28, 2017, 6:37am UTC](https://forums.fusetools.com/t/firebase-push-new-data/3185/2 "2017-07-28T06:37:58Z")

</div>

You need to put the code that fetches the data inside of your `reload()` function, bind that function to a button click, and also call the function on app startup, like so:

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

    var tag = Observable();
    var dbData = Observable();

    function reload() {
        fetch('https://fusetags.firebaseio.com/tags.json', {
            method: 'GET',
            cache: 'default',
            headers: { "Content-type": "application/json"}
        }).then(function(result) {
            if (result.status !== 200) {
                console.log("Something went wrong :(");
                return;
            }
            return result.json();
        }).then(function(data) {
            console.log("got data");
            var keys = Object.keys(data);
            keys.forEach(function(key, index) {
                if (index >= dbData.length) {
                    var value = data[key];
                    dbData.add(value);
                }
            });
        });
    }

    reload();
    
    module.exports = {
        reload: reload,
        data: dbData
    };
    </JavaScript>
    <DockPanel>
        <Panel Dock="Top" Width="240" Height="56" Margin="4">
            <Clicked Handler="{reload}" />
            <Text Value="Reload" Alignment="Center" TextColor="#fff" />
            <Rectangle Color="#18f" CornerRadius="2" />
        </Panel>
    </DockPanel>
</App>

```

---

<div class="post-metadata">

**Author:** ![Tom1](https://avatars.discourse-cdn.com/v4/letter/t/b487fb/32.png) [@Tom1](https://forums.fusetools.com/u/Tom1)\
**Post date:** [July 29, 2017, 4:32pm UTC](https://forums.fusetools.com/t/firebase-push-new-data/3185/3 "2017-07-29T16:32:07Z")

</div>

> **Uldis wrote:**
> 
> You need to put the code that fetches the data inside of your `reload()` function, bind that function to a button click, and also call the function on app startup, like so:
> 
> ```auto
> <App>
> <JavaScript>
> var Observable = require("FuseJS/Observable");
> 
> var tag = Observable();
> var dbData = Observable();
> 
> function reload() {
> fetch('https://fusetags.firebaseio.com/tags.json', {
> method: 'GET',
> cache: 'default',
> headers: { "Content-type": "application/json"}
> }).then(function(result) {
> if (result.status !== 200) {
> console.log("Something went wrong :(");
> return;
> }
> return result.json();
> }).then(function(data) {
> console.log("got data");
> var keys = Object.keys(data);
> keys.forEach(function(key, index) {
> if (index >= dbData.length) {
> var value = data[key];
> dbData.add(value);
> }
> });
> });
> }
> 
> reload();
>     
> module.exports = {
> reload: reload,
> dbData: dbData
> };
> </JavaScript>
> <DockPanel>
> <Panel Dock="Top" Width="240" Height="56" Margin="4">
> <Clicked Handler="{reload}" />
> <Text Value="Reload" Alignment="Center" TextColor="#fff" />
> <Rectangle Color="#18f" CornerRadius="2" />
> </Panel>
> </DockPanel>
> 
> ```

 \> \> ``` Thanks for reply Uldis. But when I try to click reload button there seems no change on app even though I change data on firebase backend. Data change happens only after I close and rebuilt preview. If you look above code I used each tag to display data.

---

<div class="post-metadata">

**Author:** ![Uldis](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/uldis/32/657_2.png) [@Uldis](https://forums.fusetools.com/u/Uldis)\
**Post date:** [July 31, 2017, 9:47am UTC](https://forums.fusetools.com/t/firebase-push-new-data/3185/4 "2017-07-31T09:47:02Z")

</div>

Well if you only keep adding new data to an Observable list, you will likely find it at the bottom of the list generated by the `Each`. Consider reading more about [Observables](https://www.fusetools.com/docs/fusejs/observable-api), specifically `.replaceAll()`.
