Navigation

    MagicMirror Forum

    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • Donate
    • Discord
    MagicMirror² v2.15.0 is available! For more information about this release, check out this topic.

    Synchronous requests [solved]

    Development
    2
    14
    5050
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • paviro
      paviro Admin last edited by paviro

      I am just working on some changes in my Wunderlist module and have a problem caused by not knowing JavaScript enough…

      One instance of my module can display multiple Wunderlist lists. In order for that to work I have to do one requests for every list to the Wunderlist API.

       request({url: "https://a.wunderlist.com/api/v1/tasks?list_id=" + id, method: "GET", headers: {"X-Access-Token": this.config.accessToken,"X-Client-ID": this.config.clientID}}, function(error, response, body) {
            if (!error && response.statusCode == 200) {
            ....
            callback(tasks);
       }
      });
      

      My problem is I can’t think of a way to combine the todos from all those requests into a single array and then after all todos are received send them to the interface.

      1 Reply Last reply Reply Quote 0
      • MichMich
        MichMich Admin last edited by

        Take a look at how I did this with the newsfeed.

        There is a Fetcher object that gets instantiated for every newsfeed. As soon as this feed receives new data it stores it in an instance variable and calls a function of the node_helper (see line 52 of the node helper).

        That function then retrieves the the values of all the Fetchers’ instance variables and combines the data. It then sends the socket notification with the combined data.

        1 Reply Last reply Reply Quote 0
        • paviro
          paviro Admin last edited by

          I won’t pretend I completely understand what you did there 😅
          Is it okay if I copy that code, I managed to modify it in a way that seems to work 🙂

          MichMich 1 Reply Last reply Reply Quote 0
          • MichMich
            MichMich Admin @paviro last edited by

            @paviro Yeah, but try to understand what I did. Thats the best way to learn. Let me know what you don’t understand. I’ll explain.

            1 Reply Last reply Reply Quote 0
            • paviro
              paviro Admin last edited by

              I do not quite understand how the itemsReceivedCallbackworks 😕

              1 Reply Last reply Reply Quote 0
              • paviro
                paviro Admin last edited by

                Does work great now! The only problem is sometimes a list is empty on a refresh even tough it should not be 😕

                { inbox: [],
                  'ViRO Entertainment': 
                   [ 'Todo1',
                     'Todo2',
                     'Todo3' ]
                 }
                
                1 Reply Last reply Reply Quote 0
                • MichMich
                  MichMich Admin last edited by

                  I’m on my phone now, so not really able to explain the callbacks. Will do that later.

                  Regarding the empty lists: try debugging by putting some log statements on places where You receive and send data.

                  1 Reply Last reply Reply Quote 0
                  • paviro
                    paviro Admin last edited by

                    It is not the socket connection. The fetcher sometimes returns an empty list 😕

                    MichMich 1 Reply Last reply Reply Quote 0
                    • MichMich
                      MichMich Admin @paviro last edited by

                      @paviro try debugging the Fetchet on the same way. 😉

                      1 Reply Last reply Reply Quote 0
                      • paviro
                        paviro Admin last edited by paviro

                        I am on it but I can’t find the problem… 😖
                        When broadcastItems is fired and therefore fetcher.onReceive triggered the lists are populated. But once broadcastTodos() collects the tasks by looping over the fetchers some lists appear to be empty. Any chance you could have a look?

                        1 Reply Last reply Reply Quote 0
                        • 1
                        • 2
                        • 1 / 2
                        • First post
                          Last post
                        Enjoying MagicMirror? Please consider a donation!
                        MagicMirror created by Michael Teeuw.
                        Forum managed by Paul-Vincent Roll and Rodrigo Ramírez Norambuena.
                        This forum is using NodeBB as its core | Contributors
                        Contact | Privacy Policy