Simplify the data control flow around job.plan()

This commit is contained in:
Michael Lange
2018-08-23 15:40:42 -07:00
parent e8db71a065
commit 85aaa53fd5
2 changed files with 8 additions and 5 deletions

View File

@@ -77,15 +77,19 @@ export default Watchable.extend({
},
plan(job) {
const url = addToPath(this.urlForFindRecord(job.get('id'), 'job'), '/plan');
const jobId = job.get('id');
const store = this.get('store');
const url = addToPath(this.urlForFindRecord(jobId, 'job'), '/plan');
return this.ajax(url, 'POST', {
data: {
Job: job.get('_newDefinitionJSON'),
Diff: true,
},
}).then(json => {
json.ID = job.get('id');
this.get('store').pushPayload('job-plan', { jobPlans: [json] });
json.ID = jobId;
store.pushPayload('job-plan', { jobPlans: [json] });
return store.peekRecord('job-plan', jobId);
});
},

View File

@@ -55,8 +55,7 @@ export default Component.extend({
}
try {
yield this.get('job').plan();
const plan = this.get('store').peekRecord('job-plan', this.get('job.id'));
const plan = yield this.get('job').plan();
this.set('planOutput', plan);
} catch (err) {
const error = messageFromAdapterError(err) || 'Could not plan job';