Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(composables): set initial value in useSelect #19

Merged
merged 3 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libs/composables/ngxs/src/select.composable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ export function useSelect<T>(selector: StateToken<T>): Signal<T>;
export function useSelect<T>(selector: any) {
const store = inject(Store);

return toSignal(store.select<T>(selector));
return toSignal(store.select<T>(selector), { initialValue: store.selectSnapshot(selector) });
}
/* eslint-enable @typescript-eslint/no-explicit-any */
146 changes: 69 additions & 77 deletions libs/composables/observer/src/types/dom-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,62 +4,62 @@
* Taken form https://stackoverflow.com/a/62010854
*/
type DOMEventMapDefinitions = [
[ AbortSignal, AbortSignalEventMap ],
[ AbstractWorker, AbstractWorkerEventMap ],
[ Animation, AnimationEventMap ],
[ AudioScheduledSourceNode, AudioScheduledSourceNodeEventMap ],
[ AudioWorkletNode, AudioWorkletNodeEventMap ],
[ BaseAudioContext, BaseAudioContextEventMap ],
[ BroadcastChannel, BroadcastChannelEventMap ],
[ Document, DocumentEventMap ],
[ Element, ElementEventMap ],
[ EventSource, EventSourceEventMap ],
[ FileReader, FileReaderEventMap ],
[ GlobalEventHandlers, GlobalEventHandlersEventMap ],
[ HTMLBodyElement, HTMLBodyElementEventMap ],
[ HTMLElement, HTMLElementEventMap ],
[ HTMLMediaElement, HTMLMediaElementEventMap ],
[ IDBDatabase, IDBDatabaseEventMap ],
[ IDBOpenDBRequest, IDBOpenDBRequestEventMap ],
[ IDBRequest, IDBRequestEventMap ],
[ IDBTransaction, IDBTransactionEventMap ],
[ MediaDevices, MediaDevicesEventMap ],
[ MediaKeySession, MediaKeySessionEventMap ],
[ MediaQueryList, MediaQueryListEventMap ],
[ MediaSource, MediaSourceEventMap ],
[ MediaStream, MediaStreamEventMap ],
[ MediaStreamTrack, MediaStreamTrackEventMap ],
[ MessagePort, MessagePortEventMap ],
[ Notification, NotificationEventMap ],
[ OfflineAudioContext, OfflineAudioContextEventMap ],
[ PaymentRequest, PaymentRequestEventMap ],
[ Performance, PerformanceEventMap ],
[ PermissionStatus, PermissionStatusEventMap ],
[ RTCDTMFSender, RTCDTMFSenderEventMap ],
[ RTCDataChannel, RTCDataChannelEventMap ],
[ RTCDtlsTransport, RTCDtlsTransportEventMap ],
[ RTCIceTransport, RTCIceTransportEventMap ],
[ RTCPeerConnection, RTCPeerConnectionEventMap ],
[ RTCSctpTransport, RTCSctpTransportEventMap ],
[ SVGElement, SVGElementEventMap ],
[ SVGSVGElement, SVGSVGElementEventMap ],
[ ScreenOrientation, ScreenOrientationEventMap ],
[ ServiceWorker, ServiceWorkerEventMap ],
[ ServiceWorkerContainer, ServiceWorkerContainerEventMap ],
[ ServiceWorkerRegistration, ServiceWorkerRegistrationEventMap ],
[ SourceBuffer, SourceBufferEventMap ],
[ SourceBufferList, SourceBufferListEventMap ],
[ SpeechSynthesis, SpeechSynthesisEventMap ],
[ SpeechSynthesisUtterance, SpeechSynthesisUtteranceEventMap ],
[ TextTrack, TextTrackEventMap ],
[ TextTrackCue, TextTrackCueEventMap ],
[ TextTrackList, TextTrackListEventMap ],
[ WebSocket, WebSocketEventMap ],
[ Window, WindowEventMap ],
[ WindowEventHandlers, WindowEventHandlersEventMap ],
[ Worker, WorkerEventMap ],
[ XMLHttpRequest, XMLHttpRequestEventMap ],
[ XMLHttpRequestEventTarget, XMLHttpRequestEventTargetEventMap ]
[AbortSignal, AbortSignalEventMap],
[AbstractWorker, AbstractWorkerEventMap],
[Animation, AnimationEventMap],
[AudioScheduledSourceNode, AudioScheduledSourceNodeEventMap],
[AudioWorkletNode, AudioWorkletNodeEventMap],
[BaseAudioContext, BaseAudioContextEventMap],
[BroadcastChannel, BroadcastChannelEventMap],
[Document, DocumentEventMap],
[Element, ElementEventMap],
[EventSource, EventSourceEventMap],
[FileReader, FileReaderEventMap],
[GlobalEventHandlers, GlobalEventHandlersEventMap],
[HTMLBodyElement, HTMLBodyElementEventMap],
[HTMLElement, HTMLElementEventMap],
[HTMLMediaElement, HTMLMediaElementEventMap],
[IDBDatabase, IDBDatabaseEventMap],
[IDBOpenDBRequest, IDBOpenDBRequestEventMap],
[IDBRequest, IDBRequestEventMap],
[IDBTransaction, IDBTransactionEventMap],
[MediaDevices, MediaDevicesEventMap],
[MediaKeySession, MediaKeySessionEventMap],
[MediaQueryList, MediaQueryListEventMap],
[MediaSource, MediaSourceEventMap],
[MediaStream, MediaStreamEventMap],
[MediaStreamTrack, MediaStreamTrackEventMap],
[MessagePort, MessagePortEventMap],
[Notification, NotificationEventMap],
[OfflineAudioContext, OfflineAudioContextEventMap],
[PaymentRequest, PaymentRequestEventMap],
[Performance, PerformanceEventMap],
[PermissionStatus, PermissionStatusEventMap],
[RTCDTMFSender, RTCDTMFSenderEventMap],
[RTCDataChannel, RTCDataChannelEventMap],
[RTCDtlsTransport, RTCDtlsTransportEventMap],
[RTCIceTransport, RTCIceTransportEventMap],
[RTCPeerConnection, RTCPeerConnectionEventMap],
[RTCSctpTransport, RTCSctpTransportEventMap],
[SVGElement, SVGElementEventMap],
[SVGSVGElement, SVGSVGElementEventMap],
[ScreenOrientation, ScreenOrientationEventMap],
[ServiceWorker, ServiceWorkerEventMap],
[ServiceWorkerContainer, ServiceWorkerContainerEventMap],
[ServiceWorkerRegistration, ServiceWorkerRegistrationEventMap],
[SourceBuffer, SourceBufferEventMap],
[SourceBufferList, SourceBufferListEventMap],
[SpeechSynthesis, SpeechSynthesisEventMap],
[SpeechSynthesisUtterance, SpeechSynthesisUtteranceEventMap],
[TextTrack, TextTrackEventMap],
[TextTrackCue, TextTrackCueEventMap],
[TextTrackList, TextTrackListEventMap],
[WebSocket, WebSocketEventMap],
[Window, WindowEventMap],
[WindowEventHandlers, WindowEventHandlersEventMap],
[Worker, WorkerEventMap],
[XMLHttpRequest, XMLHttpRequestEventMap],
[XMLHttpRequestEventTarget, XMLHttpRequestEventTargetEventMap]
];

/*
Expand All @@ -71,30 +71,23 @@ type DOMEventMapDefinitions = [
/**
* A list of all event names for the given target
*/
export type EventName<Target extends EventTarget> = CastToName<{
[K in keyof DOMEventMapDefinitions]: DOMEventMapDefinitions[K] extends [
infer TargetType,
infer EventMap
]
? Target extends TargetType
? keyof EventMap
: never
: never;
}[keyof DOMEventMapDefinitions]>;
export type EventName<Target extends EventTarget> = CastToName<
{
[K in keyof DOMEventMapDefinitions]: DOMEventMapDefinitions[K] extends [infer TargetType, infer EventMap]
? Target extends TargetType
? keyof EventMap
: never
: never;
}[keyof DOMEventMapDefinitions]
>;

/**
* The event type for the given target and event name
*/
export type EventType<
Target extends EventTarget,
Name extends string
> = CastToEvent<GetEventType_<Target, Name>>;
export type EventType<Target extends EventTarget, Name extends string> = CastToEvent<GetEventType<Target, Name>>;

type GetEventType_<Target extends EventTarget, Name extends string> = {
[K in keyof DOMEventMapDefinitions]: DOMEventMapDefinitions[K] extends [
infer TargetType,
infer EventMap
]
type GetEventType<Target extends EventTarget, Name extends string> = {
[K in keyof DOMEventMapDefinitions]: DOMEventMapDefinitions[K] extends [infer TargetType, infer EventMap]
? Target extends TargetType
? Name extends keyof EventMap
? EventMap[Name]
Expand All @@ -103,10 +96,9 @@ type GetEventType_<Target extends EventTarget, Name extends string> = {
: never;
}[keyof DOMEventMapDefinitions];


// if `Target` doesn't match any item form the
// `DOMEventMapDefinitions`, we fallback to Event
type CastToEvent<T> = IsNever<T> extends true ? Event : T;
type CastToName<T> = IsNever<T> extends true ? string : T;

type IsNever<T> = [ T ] extends [ never ] ? true : false;
type IsNever<T> = [T] extends [never] ? true : false;
9 changes: 8 additions & 1 deletion libs/composables/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,15 @@
"@angular/cdk": ">=16.0.0 <18.0.0",
"@angular/platform-browser": ">=16.0.0 <18.0.0",
"@ngxs/store": "^3.8.1",
"rxjs": ">=7.0.0"
"rxjs": ">=7.0.0",
"@angular/common": "16.2.9",
"jest-preset-angular": "~13.1.0",
"jest-matchmedia-mock": "^1.1.0"
},
"dependencies": {},
"devDependencies": {
"jest-preset-angular": "~13.1.0",
"jest-matchmedia-mock": "^1.1.0"
},
"sideEffects": false
}
Loading