{"action":"created","issue":{"url":"https://api.github.com/repos/adonisjs/adonis-framework/issues/39","labels_url":"https://api.github.com/repos/adonisjs/adonis-framework/issues/39/labels{/name}","comments_url":"https://api.github.com/repos/adonisjs/adonis-framework/issues/39/comments","events_url":"https://api.github.com/repos/adonisjs/adonis-framework/issues/39/events","html_url":"https://github.com/adonisjs/adonis-framework/issues/39","id":124216175,"number":39,"title":"What is the preferred way to handle views, based on async data","user":{"login":"gearsdigital","id":965069,"avatar_url":"https://avatars.githubusercontent.com/u/965069?v=3","gravatar_id":"","url":"https://api.github.com/users/gearsdigital","html_url":"https://github.com/gearsdigital","followers_url":"https://api.github.com/users/gearsdigital/followers","following_url":"https://api.github.com/users/gearsdigital/following{/other_user}","gists_url":"https://api.github.com/users/gearsdigital/gists{/gist_id}","starred_url":"https://api.github.com/users/gearsdigital/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gearsdigital/subscriptions","organizations_url":"https://api.github.com/users/gearsdigital/orgs","repos_url":"https://api.github.com/users/gearsdigital/repos","events_url":"https://api.github.com/users/gearsdigital/events{/privacy}","received_events_url":"https://api.github.com/users/gearsdigital/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-12-29T14:09:50Z","updated_at":"2015-12-29T18:17:04Z","closed_at":null,"body":"What is the preferred way to handle views, based on async data? I have a method which returns an promise which gets resolved with the queried data.\r\n\r\n\r\n```js\r\n// CalendarController.js\r\n* index(request, response) {\r\n    let promise = this.calendarService.loadEvents(access_token);\r\n    promise.then(function(response){\r\n    // how to push data to the view here?\r\n    });\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/adonisjs/adonis-framework/issues/comments/167847088","html_url":"https://github.com/adonisjs/adonis-framework/issues/39#issuecomment-167847088","issue_url":"https://api.github.com/repos/adonisjs/adonis-framework/issues/39","id":167847088,"user":{"login":"gearsdigital","id":965069,"avatar_url":"https://avatars.githubusercontent.com/u/965069?v=3","gravatar_id":"","url":"https://api.github.com/users/gearsdigital","html_url":"https://github.com/gearsdigital","followers_url":"https://api.github.com/users/gearsdigital/followers","following_url":"https://api.github.com/users/gearsdigital/following{/other_user}","gists_url":"https://api.github.com/users/gearsdigital/gists{/gist_id}","starred_url":"https://api.github.com/users/gearsdigital/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gearsdigital/subscriptions","organizations_url":"https://api.github.com/users/gearsdigital/orgs","repos_url":"https://api.github.com/users/gearsdigital/repos","events_url":"https://api.github.com/users/gearsdigital/events{/privacy}","received_events_url":"https://api.github.com/users/gearsdigital/received_events","type":"User","site_admin":false},"created_at":"2015-12-29T18:17:04Z","updated_at":"2015-12-29T18:17:04Z","body":"Damn, you're right. I copied and tested the wrong code, i switched the branch. Sorry!\r\nHere we go:\r\n\r\n```js\r\n  * index(request, response) {\r\n    const tokens = yield Database.from('admin').first('access_token');\r\n    const calendarResponse = yield this.calendarService.loadEvents(tokens.access_token);\r\n    const view = response.view(calendarResponse);\r\n    response.send(view);\r\n  }\r\n\r\nloadEvents(tokens) {\r\n    let parsed_tokens = JSON.parse(tokens);\r\n    let auth = this.oauth2Client;\r\n    var calendar = google.calendar('v3');\r\n    auth.credentials = parsed_tokens;\r\n\r\n    return new Promise(function (resolve, reject) {\r\n      calendar.events.list({\r\n        auth: auth,\r\n        calendarId: 'primary',\r\n        timeMin: (new Date()).toISOString(),\r\n        maxResults: 10,\r\n        singleEvents: true,\r\n        orderBy: 'startTime'\r\n      }, function (err, response) {\r\n        if (err) {\r\n          console.log('The API returned an error: ' + err);\r\n          reject(err);\r\n          return;\r\n        }\r\n        resolve(response.items);\r\n      });\r\n    });\r\n  }\r\n```\r\n\r\nErrors are gone, view renders with `{}`.\r\n"}}