From 1aa02eb42a7dd86b00e137ff3b628b087be38f75 Mon Sep 17 00:00:00 2001 From: Benaiah Mischenko Date: Mon, 20 Mar 2017 12:28:04 -0700 Subject: [PATCH] Refactor readUnpublishedBranchFile with resolvePromiseProperties --- src/backends/github/API.js | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/src/backends/github/API.js b/src/backends/github/API.js index 5bf5a0d9..b856ea3e 100644 --- a/src/backends/github/API.js +++ b/src/backends/github/API.js @@ -1,7 +1,7 @@ import LocalForage from "localforage"; import { Base64 } from "js-base64"; import _ from "lodash"; -import { filterPromises } from "../../lib/promiseHelper"; +import { filterPromises, resolvePromiseProperties } from "../../lib/promiseHelper"; import AssetProxy from "../../valueObjects/AssetProxy"; import { SIMPLE, EDITORIAL_WORKFLOW, status } from "../../constants/publishModes"; import { APIError, EditorialWorkflowError } from "../../valueObjects/errors"; @@ -159,24 +159,18 @@ export default class API { } readUnpublishedBranchFile(contentKey) { - let metaData, fileData; - const unpublishedPromise = this.retrieveMetadata(contentKey) - .then((data) => { - metaData = data; - if (data.objects.entry.path) { - return this.readFile(data.objects.entry.path, null, data.branch); - } - return Promise.reject(null); + const metaDataPromise = this.retrieveMetadata(contentKey) + .then(data => (data.objects.entry.path ? data : Promise.reject(null))); + return resolvePromiseProperties({ + metaData: metaDataPromise, + fileData: metaDataPromise.then( + data => this.readFile(data.objects.entry.path, null, data.branch)), + isModification: metaDataPromise.then( + data => this.isUnpublishedEntryModification(data.objects.entry.path, this.branch)), }) - .then((file) => { - fileData = file; - return this.isUnpublishedEntryModification(metaData.objects.entry.path); - }) - .then(isModification => ({ metaData, fileData, isModification })) .catch(() => { throw new EditorialWorkflowError('content is not under editorial workflow', true); }); - return unpublishedPromise; } isUnpublishedEntryModification(path, branch) {