MCPcopy Index your code
hub / github.com/angular/angular / SnapshotResource

Class SnapshotResource

packages/core/src/resource/from_snapshots.ts:25–53  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23}
24
25class SnapshotResource<T> implements Resource<T> {
26 constructor(readonly snapshot: Signal<ResourceSnapshot<T>>) {}
27
28 private get state(): ResourceSnapshot<T> {
29 return this.snapshot();
30 }
31
32 readonly value = computed(() => {
33 if (this.state.status === 'error') {
34 throw new ResourceValueError(this.state.error);
35 }
36 return this.state.value;
37 });
38 readonly status = computed(() => this.state.status);
39 readonly error = computed(() => (this.state.status === 'error' ? this.state.error : undefined));
40 readonly isLoading = computed(
41 () => this.state.status === 'loading' || this.state.status === 'reloading',
42 );
43
44 private isValueDefined = computed(
45 () => this.state.status !== 'error' && this.state.value !== undefined,
46 );
47
48 hasValue(this: T extends undefined ? this : never): this is Resource<Exclude<T, undefined>>;
49 hasValue(): boolean;
50 hasValue(): boolean {
51 return this.isValueDefined();
52 }
53}

Callers

nothing calls this directly

Calls 1

computedFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…