This repository was archived by the owner on Nov 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtest2.ts
68 lines (63 loc) · 1.6 KB
/
test2.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import {
selectSignal,
signalStore,
signalStoreFeature,
type,
withHooks,
withMethods,
withSignals,
withState,
} from '@ngrx/signals';
import { Signal, signal } from '@angular/core';
function withX() {
return signalStoreFeature(withState({ x: 1 }));
}
type Y = { a: string; b: number };
const initialY: Y = { a: '', b: 5 };
function withY<_>() {
return signalStoreFeature(
{
state: type<{ q: string }>(),
signals: type<{ sig: Signal<boolean> }>(),
},
withState({ y: initialY }),
withSignals(() => ({ sigY: signal('sigY') })),
withHooks({
onInit(store) {
// store.$update({ q: '', y: { a: 'a', b: 2 } });
// store.$update({ wrong: '', y: { a: 'a', b: 2 } });
// store.$update({ y: 'wrong' });
},
})
);
}
export const Store = signalStore(
withSignals(() => ({ sig: signal(1) })),
withState({ q: 'q', q2: 'q2' }),
// withState({ q: 1 }),
withSignals(() => ({ sig: signal(false) })),
withX(),
withY(),
withSignals(() => ({ q: signal(10) })),
withMethods((store) => ({
f() {
store.$update({ x: 1, y: { a: '', b: 0 }, q2: 'q2new' });
// store.$update({ q: 'wrong' });
const sig = store.sig.asReadonly();
const q = store.q.asReadonly();
},
}))
);
export const feature = signalStoreFeature(
{ signals: type<{ sig: Signal<boolean> }>() },
// withSignals(() => ({ sig: signal(1) })),
withState({ q: 'q' }),
// withSignals(() => ({ sig: signal(false) })),
withX(),
withY(),
withMethods((store) => ({
f() {
store.$update({ x: 1, q: 'marko', y: { a: '', b: 0 } });
},
}))
);