Skip to content

Commit 2f714c9

Browse files
committed
get it building/typechecking again
1 parent 02e0546 commit 2f714c9

File tree

10 files changed

+42
-314
lines changed

10 files changed

+42
-314
lines changed

packages/schema-record/src/-private/fields/compute.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import type { Future } from '@ember-data/request';
22
import type Store from '@ember-data/store';
33
import type { StoreRequestInput } from '@ember-data/store';
4-
import { defineSignal, RelatedCollection as ManyArray } from '@ember-data/store/-private';
5-
import { getSignal, peekSignal } from '@ember-data/tracking/-private';
4+
import {
5+
consumeInternalSignal,
6+
defineSignal,
7+
getOrCreateInternalSignal,
8+
RelatedCollection as ManyArray,
9+
withSignalStore,
10+
} from '@ember-data/store/-private';
611
import { DEBUG } from '@warp-drive/build-config/env';
712
import type { StableRecordIdentifier } from '@warp-drive/core-types';
813
import { getOrSetGlobal } from '@warp-drive/core-types/-private';
@@ -40,14 +45,10 @@ export const ManagedObjectMap = getOrSetGlobal(
4045
);
4146

4247
export function computeLocal(record: typeof Proxy<SchemaRecord>, field: LocalField, prop: string): unknown {
43-
let signal = peekSignal(record, prop);
44-
45-
if (!signal) {
46-
signal = getSignal(record, prop, false);
47-
signal.lastValue = field.options?.defaultValue ?? null;
48-
}
49-
50-
return signal.lastValue;
48+
const signals = withSignalStore(record);
49+
const signal = getOrCreateInternalSignal(signals, record, prop, field.options?.defaultValue ?? null);
50+
consumeInternalSignal(signal);
51+
return signal.value;
5152
}
5253

5354
export function peekManagedArray(record: SchemaRecord, field: FieldSchema): ManyArray | ManagedArray | undefined {

packages/schema-record/src/-private/fields/managed-object.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
consumeInternalSignal,
33
entangleSignal,
44
notifyInternalSignal,
5+
OBJECT_SIGNAL,
56
type WarpDriveSignal,
67
withSignalStore,
78
} from '@ember-data/store/-private';
@@ -14,7 +15,7 @@ import type { ObjectField, SchemaObjectField } from '@warp-drive/core-types/sche
1415

1516
import type { SchemaRecord } from '../record';
1617
import type { SchemaService } from '../schema';
17-
import { Editable, EmbeddedPath, Legacy, MUTATE, OBJECT_SIGNAL, Parent, SOURCE } from '../symbols';
18+
import { Editable, EmbeddedPath, Legacy, MUTATE, Parent, SOURCE } from '../symbols';
1819

1920
export function notifyObject(obj: ManagedObject) {
2021
notifyInternalSignal(obj[OBJECT_SIGNAL]);

packages/schema-record/src/-private/record.ts

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ import type { RelatedCollection as ManyArray } from '@ember-data/store/-private'
77
import {
88
ARRAY_SIGNAL,
99
entangleSignal,
10+
getOrCreateInternalSignal,
1011
notifyInternalSignal,
12+
OBJECT_SIGNAL,
1113
recordIdentifierFor,
1214
setRecordIdentifier,
1315
withSignalStore,
1416
} from '@ember-data/store/-private';
15-
import { getSignal, invalidateSignal, type Signal, Signals } from '@ember-data/tracking/-private';
1617
import { DEBUG } from '@warp-drive/build-config/env';
1718
import { assert } from '@warp-drive/build-config/macros';
1819
import type { StableRecordIdentifier } from '@warp-drive/core-types';
@@ -47,18 +48,7 @@ const getLegacySupport = macroCondition(dependencySatisfies('@ember-data/model',
4748

4849
export { Editable, Legacy, Checkout } from './symbols';
4950
const IgnoredGlobalFields = new Set<string>(['length', 'nodeType', 'then', 'setInterval', 'document', STRUCTURED]);
50-
const symbolList = [
51-
Destroy,
52-
RecordStore,
53-
Identifier,
54-
Editable,
55-
Parent,
56-
Checkout,
57-
Legacy,
58-
Signals,
59-
EmbeddedPath,
60-
EmbeddedType,
61-
];
51+
const symbolList = [Destroy, RecordStore, Identifier, Editable, Parent, Checkout, Legacy, EmbeddedPath, EmbeddedType];
6252
const RecordSymbols = new Set(symbolList);
6353

6454
type RecordSymbol = (typeof symbolList)[number];
@@ -89,7 +79,6 @@ export class SchemaRecord {
8979
declare [EmbeddedPath]: string[] | null;
9080
declare [Editable]: boolean;
9181
declare [Legacy]: boolean;
92-
declare [Signals]: Map<string, Signal>;
9382
declare [Symbol.toStringTag]: `SchemaRecord<${string}>`;
9483
declare ___notifications: object;
9584

@@ -306,10 +295,7 @@ export class SchemaRecord {
306295
// TODO pass actual cache value not {}
307296
return schema.hashFn(field)({}, field.options ?? null, field.name ?? null);
308297
case '@local': {
309-
// FIXME the signal is the local storage, don't need the double entangle
310-
const lastValue = computeLocal(receiver, field, prop as string);
311-
entangleSignal(signals, receiver, prop as string, null);
312-
return lastValue;
298+
return computeLocal(receiver, field, prop as string);
313299
}
314300
case 'field':
315301
entangleSignal(signals, receiver, field.name, null);
@@ -439,10 +425,15 @@ export class SchemaRecord {
439425
return true;
440426
}
441427
case '@local': {
442-
const signal = getSignal(receiver, prop as string, true);
443-
if (signal.lastValue !== value) {
444-
signal.lastValue = value;
445-
invalidateSignal(signal);
428+
const signal = getOrCreateInternalSignal(
429+
signals,
430+
receiver,
431+
prop as string | symbol,
432+
field.options?.defaultValue ?? null
433+
);
434+
if (signal.value !== value) {
435+
signal.value = value;
436+
notifyInternalSignal(signal);
446437
}
447438
return true;
448439
}
@@ -615,7 +606,7 @@ export class SchemaRecord {
615606
if (identityField.name && identityField.kind === '@id') {
616607
const signal = signals.get('@identity');
617608
if (signal) {
618-
invalidateSignal(signal);
609+
notifyInternalSignal(signal);
619610
}
620611
}
621612
break;
@@ -645,7 +636,7 @@ export class SchemaRecord {
645636
// console.log(`Notification for ${key} on ${identifier.type}`, self);
646637
const signal = signals.get(key);
647638
if (signal) {
648-
invalidateSignal(signal);
639+
notifyInternalSignal(signal);
649640
}
650641
const field = fields.get(key);
651642
if (field?.kind === 'array' || field?.kind === 'schema-array') {
@@ -656,16 +647,14 @@ export class SchemaRecord {
656647
ARRAY_SIGNAL in peeked
657648
);
658649
const arrSignal = peeked[ARRAY_SIGNAL];
659-
arrSignal.isStale = true;
660-
invalidateSignal(arrSignal);
650+
notifyInternalSignal(arrSignal);
661651
}
662652
}
663653
if (field?.kind === 'object') {
664654
const peeked = peekManagedObject(self, field);
665655
if (peeked) {
666656
const objSignal = peeked[OBJECT_SIGNAL];
667-
objSignal.isStale = true;
668-
invalidateSignal(objSignal);
657+
notifyInternalSignal(objSignal);
669658
}
670659
}
671660
}
@@ -685,7 +674,7 @@ export class SchemaRecord {
685674
// console.log(`Notification for ${key} on ${identifier.type}`, self);
686675
const signal = signals.get(key);
687676
if (signal) {
688-
invalidateSignal(signal);
677+
notifyInternalSignal(signal);
689678
}
690679
// FIXME
691680
} else if (field.kind === 'resource') {
@@ -721,7 +710,7 @@ export class SchemaRecord {
721710
if (field.options.async) {
722711
const signal = signals.get(key);
723712
if (signal) {
724-
invalidateSignal(signal);
713+
notifyInternalSignal(signal);
725714
}
726715
}
727716
}

packages/schema-record/src/-private/schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ function makeCachedDerivation<R, T, FM extends ObjectValue | null>(
170170
derivation: Derivation<R, T, FM>
171171
): Derivation<R, T, FM> {
172172
const memoizedDerivation = (record: R, options: FM, prop: string): T => {
173-
const signals = withSignalStore(record);
173+
const signals = withSignalStore(record as object);
174174
let signal = signals.get(prop);
175175
if (!signal) {
176176
signal = createMemo(() => {

packages/store/src/-private.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,5 @@ export {
8181
withSignalStore,
8282
notifyInternalSignal,
8383
consumeInternalSignal,
84+
getOrCreateInternalSignal,
8485
} from './-private/new-core-tmp/reactivity/internal';

packages/store/src/-private/record-arrays/identifier-array.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,9 @@ export class IdentifierArray<T = unknown> {
182182
_updatingPromise: Promise<IdentifierArray<T>> | null = null;
183183
readonly identifier: StableDocumentIdentifier | null;
184184

185-
[IS_COLLECTION] = true;
185+
declare [IS_COLLECTION]: boolean;
186186
declare [ARRAY_SIGNAL]: WarpDriveSignal;
187-
[SOURCE]: StableRecordIdentifier[];
187+
declare [SOURCE]: StableRecordIdentifier[];
188188

189189
declare links: Links | PaginationLinks | null;
190190
declare meta: Record<string, unknown> | null;
@@ -225,6 +225,7 @@ export class IdentifierArray<T = unknown> {
225225
this._manager = options.manager;
226226
this.identifier = options.identifier || null;
227227
this[SOURCE] = options.identifiers;
228+
this[IS_COLLECTION] = true;
228229

229230
// TODO this likely should be entangled on the proxy/receiver not this class
230231
// FIXME before we entangled legacy array signals on the proxy too
@@ -264,6 +265,10 @@ export class IdentifierArray<T = unknown> {
264265
return identifier && store._instanceCache.getRecord(identifier);
265266
}
266267

268+
if (prop === ARRAY_SIGNAL) {
269+
return _SIGNAL;
270+
}
271+
267272
if (prop === 'meta') return consumeInternalSignal(_SIGNAL), PrivateState.meta;
268273
if (prop === 'links') return consumeInternalSignal(_SIGNAL), PrivateState.links;
269274
if (prop === '[]') return consumeInternalSignal(_SIGNAL), receiver;
@@ -324,7 +329,7 @@ export class IdentifierArray<T = unknown> {
324329
}
325330

326331
if (isSelfProp(self, prop)) {
327-
if (prop === ARRAY_SIGNAL || prop === SOURCE) {
332+
if (prop === SOURCE) {
328333
return self[prop];
329334
}
330335

0 commit comments

Comments
 (0)