From 23bf81e10941a776a79049c020ccbf821c18782a Mon Sep 17 00:00:00 2001 From: Bradley Hilton Date: Mon, 19 Feb 2018 14:37:22 -0600 Subject: [PATCH] ROcket.Chat Apps manage pages, use one promise to ensure no race condition. Add a readme explaining a few terms --- packages/rocketchat-apps/README.md | 11 ++++++ .../rocketchat-apps/client/admin/appLogs.js | 26 +++++--------- .../rocketchat-apps/client/admin/appManage.js | 35 +++++++------------ 3 files changed, 33 insertions(+), 39 deletions(-) create mode 100644 packages/rocketchat-apps/README.md diff --git a/packages/rocketchat-apps/README.md b/packages/rocketchat-apps/README.md new file mode 100644 index 00000000000..65b130d4c5d --- /dev/null +++ b/packages/rocketchat-apps/README.md @@ -0,0 +1,11 @@ +# Rocket.Chat Apps +Finally! :smile: + +## What is an "Orchestrator"? +An orchestrator is the file/class which is responsible for orchestrating (starting up) everything which is required of the system to get up and going. There are two of these. One for the server and one for the client. + +## What is a "Bridge"? +A bridge is a file/class which is responsible for bridging the Rocket.Chat system's data and the App system's data. They are implementations of the interfaces inside of the Rocket.Chat Apps-engine project `src/server/bridges`. They allow the two systems to talk to each other (hince the name bridge, as they "bridge the gap"). + +## What is a "Converter"? +A converter does what the name implies, it handles converting from one system's data type into the other's. diff --git a/packages/rocketchat-apps/client/admin/appLogs.js b/packages/rocketchat-apps/client/admin/appLogs.js index 0b9f7330c3d..4aeeb7e7a02 100644 --- a/packages/rocketchat-apps/client/admin/appLogs.js +++ b/packages/rocketchat-apps/client/admin/appLogs.js @@ -9,26 +9,18 @@ Template.appLogs.onCreated(function() { this.logs = new ReactiveVar([]); const id = this.id.get(); - const got = { info: false, logs: false }; - RocketChat.API.get(`apps/${ id }`).then((result) => { - instance.app.set(result.app); + Promise.all([ + RocketChat.API.get(`apps/${ id }`), + RocketChat.API.get(`apps/${ id }/logs`), + ]).then((results) => { - got.info = true; - if (got.info && got.logs) { - this.ready.set(true); - } - }); - - RocketChat.API.get(`apps/${ id }/logs`).then((result) => { - console.log('logs result:', result); + instance.app.set(results[0].app); + instance.logs.set(results[1].logs); - instance.logs.set(result.logs); - - got.logs = true; - if (got.info && got.logs) { - this.ready.set(true); - } + this.ready.set(true); + }).catch(() => { + //TODO: error handling }); }); diff --git a/packages/rocketchat-apps/client/admin/appManage.js b/packages/rocketchat-apps/client/admin/appManage.js index 57f93639571..0de121a2b82 100644 --- a/packages/rocketchat-apps/client/admin/appManage.js +++ b/packages/rocketchat-apps/client/admin/appManage.js @@ -10,32 +10,23 @@ Template.appManage.onCreated(function() { this.settings = new ReactiveVar({}); const id = this.id.get(); - const got = { info: false, settings: false }; - RocketChat.API.get(`apps/${ id }`).then((result) => { - instance.app.set(result.app); - console.log(result.app); + Promise.all([ + RocketChat.API.get(`apps/${ id }`), + RocketChat.API.get(`apps/${ id }/settings`), + ]).then((results) => { + instance.app.set(results[0].app); - got.info = true; - if (got.info && got.settings) { - this.ready.set(true); - } - }); - - RocketChat.API.get(`apps/${ id }/settings`).then((result) => { - Object.keys(result.settings).forEach((k) => { - result.settings[k].i18nPlaceholder = result.settings[k].i18nPlaceholder || ' '; - result.settings[k].value = result.settings[k].value || result.settings[k].packageValue; - result.settings[k].oldValue = result.settings[k].value; + Object.keys(results[1].settings).forEach((k) => { + results[1].settings[k].i18nPlaceholder = results[1].settings[k].i18nPlaceholder || ' '; + results[1].settings[k].value = results[1].settings[k].value || results[1].settings[k].packageValue; + results[1].settings[k].oldValue = results[1].settings[k].value; }); - instance.settings.set(result.settings); - console.log(instance.settings.get()); - - got.settings = true; - if (got.info && got.settings) { - this.ready.set(true); - } + instance.settings.set(results[1].settings); + this.ready.set(true); + }).catch(() => { + //TODO: error handling }); });