Skip to content

Commit

Permalink
chore: refactor promiseRecord (#6161)
Browse files Browse the repository at this point in the history
* chore: refactor promiseRecord

* cleanup
  • Loading branch information
runspired authored Jul 11, 2019
1 parent 2cc4c60 commit 3186276
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
10 changes: 1 addition & 9 deletions packages/store/addon/-private/system/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,14 @@ import edBackburner from './backburner';
import { RECORD_DATA_ERRORS, RECORD_DATA_STATE } from '@ember-data/canary-features';
import { Record } from '../ts-interfaces/record';

import promiseRecord from '../utils/promise-record';
const badIdFormatAssertion = '`id` passed to `findRecord()` has to be non-empty string or number';
const emberRun = emberRunLoop.backburner;

const { ENV } = Ember;

let globalClientIdCounter = 1;

//Get the materialized model from the internalModel/promise that returns
//an internal model and return it in a promiseObject. Useful for returning
//from find methods
function promiseRecord(internalModelPromise, label) {
let toReturn = internalModelPromise.then(internalModel => internalModel.getRecord());

return promiseObject(toReturn, label);
}

// Implementors Note:
//
// The variables in this file are consistently named according to the following
Expand Down
24 changes: 24 additions & 0 deletions packages/store/addon/-private/utils/promise-record.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import InternalModel from '../system/model/internal-model';
import { promiseObject } from '../system/promise-proxies';
import { Record } from '../ts-interfaces/record';

// shim type until we can properly type
// these proxies
export type PromiseProxy<T> = Promise<T>;

/**
* Get the materialized model from the internalModel/promise
* that returns an internal model and return it in a promiseObject.
*
* Useful for returning from find methods
*
* @internal
*/
export default function promiseRecord(
internalModelPromise: Promise<InternalModel>,
label: string
): PromiseProxy<Record> {
let toReturn = internalModelPromise.then(internalModel => internalModel.getRecord());

return promiseObject(toReturn, label);
}

0 comments on commit 3186276

Please sign in to comment.