Skip to content

Commit

Permalink
some minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
runspired committed Aug 10, 2022
1 parent 9fd5064 commit df39ecf
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 23 deletions.
19 changes: 8 additions & 11 deletions packages/store/addon/-private/caches/identifier-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ export class IdentifierCache {
lids: Object.create(null) as IdentifierMap,
types: Object.create(null) as TypeMap,
};
private _generate: GenerationMethod;
private _update: UpdateMethod;
private _forget: ForgetMethod;
private _reset: ResetMethod;
private _merge: MergeMethod;
declare _generate: GenerationMethod;
declare _update: UpdateMethod;
declare _forget: ForgetMethod;
declare _reset: ResetMethod;
declare _merge: MergeMethod;

constructor() {
// we cache the user configuredGenerationMethod at init because it must
Expand Down Expand Up @@ -156,12 +156,9 @@ export class IdentifierCache {
* @method _getRecordIdentifier
* @private
*/
private _getRecordIdentifier(resource: ResourceIdentifierObject, shouldGenerate: true): StableRecordIdentifier;
private _getRecordIdentifier(
resource: ResourceIdentifierObject,
shouldGenerate: false
): StableRecordIdentifier | undefined;
private _getRecordIdentifier(
_getRecordIdentifier(resource: ResourceIdentifierObject, shouldGenerate: true): StableRecordIdentifier;
_getRecordIdentifier(resource: ResourceIdentifierObject, shouldGenerate: false): StableRecordIdentifier | undefined;
_getRecordIdentifier(
resource: ResourceIdentifierObject,
shouldGenerate: boolean = false
): StableRecordIdentifier | undefined {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ import type Store from '../store-service';
@extends Reference
*/
export default class RecordReference {
declare store: Store;
// unsubscribe token given to us by the notification manager
#token!: Object;
#identifier: StableRecordIdentifier;

@tracked _ref = 0;

constructor(public store: Store, identifier: StableRecordIdentifier) {
constructor(store: Store, identifier: StableRecordIdentifier) {
this.store = store;
this.#identifier = identifier;
this.#token = store._notificationManager.subscribe(
identifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@ function mapFromHash<T>(hash: Dict<T>): Map<string, T> {

// Mimics the static apis of DSModel
export default class ShimModelClass implements ModelSchema {
// TODO Maybe expose the class here?
constructor(private __store: Store, public modelName: string) {}
declare __store: Store;
declare modelName: string;
constructor(store: Store, modelName: string) {
this.__store = store;
this.modelName = modelName;
}

get fields(): Map<string, 'attribute' | 'belongsTo' | 'hasMany'> {
let attrs = this.__store.getSchemaDefinitionService().attributesDefinitionFor({ type: this.modelName });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ export function unsubscribe(token: UnsubscribeToken) {
Currently only support a single callback per identifier
*/
export default class NotificationManager {
constructor(private store: Store) {}
declare store: Store;
constructor(store: Store) {
this.store = store;
}

subscribe(identifier: StableRecordIdentifier, callback: NotificationCallback): UnsubscribeToken {
assert(`Expected to receive a stable Identifier to subscribe to`, isStableIdentifier(identifier));
Expand Down
4 changes: 3 additions & 1 deletion packages/store/addon/-private/network/fetch-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,10 @@ export default class FetchManager {
declare _pendingSave: PendingSaveItem[];
// fetches pending in the runloop, waiting to be coalesced
declare _pendingFetch: Map<string, PendingFetchItem[]>;
declare _store: Store;

constructor(private _store: Store) {
constructor(store: Store) {
this._store = store;
// used to keep track of all the find requests that need to be coalesced
this._pendingFetch = new Map();
this._pendingSave = [];
Expand Down
23 changes: 16 additions & 7 deletions packages/store/addon/-private/network/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,19 @@ function schemaIsDSModel(schema: ModelSchema | DSModelSchema): schema is DSModel
@public
*/
export default class Snapshot implements Snapshot {
private __attributes: Dict<unknown> | null = null;
private _belongsToRelationships: Dict<Snapshot> = Object.create(null);
private _belongsToIds: Dict<RecordId> = Object.create(null);
private _hasManyRelationships: Dict<Snapshot[]> = Object.create(null);
private _hasManyIds: Dict<RecordId[]> = Object.create(null);
declare __attributes: Dict<unknown> | null;
declare _belongsToRelationships: Dict<Snapshot>;
declare _belongsToIds: Dict<RecordId>;
declare _hasManyRelationships: Dict<Snapshot[]>;
declare _hasManyIds: Dict<RecordId[]>;
declare _changedAttributes: ChangedAttributesHash;

declare identifier: StableRecordIdentifier;
declare modelName: string;
declare id: string | null;
declare include?: unknown;
declare adapterOptions?: Dict<unknown>;
declare _store: Store;

/**
* @method constructor
Expand All @@ -56,8 +57,16 @@ export default class Snapshot implements Snapshot {
* @param identifier
* @param _store
*/
constructor(options: FindOptions, identifier: StableRecordIdentifier, private _store: Store) {
const hasRecord = !!_store._instanceCache.peek({ identifier, bucket: 'record' });
constructor(options: FindOptions, identifier: StableRecordIdentifier, store: Store) {
this._store = store;

this.__attributes = null;
this._belongsToRelationships = Object.create(null);
this._belongsToIds = Object.create(null);
this._hasManyRelationships = Object.create(null);
this._hasManyIds = Object.create(null);

const hasRecord = !!store._instanceCache.peek({ identifier, bucket: 'record' });
this.modelName = identifier.type;

/**
Expand Down

0 comments on commit df39ecf

Please sign in to comment.