Created
July 6, 2021 08:11
-
-
Save fostyfost/59bbc39012ab02082c6e6270972cecbc to your computer and use it in GitHub Desktop.
Saga equals function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export interface SagaWithArguments<T = any> { | |
saga: (argument?: T) => Iterator<any> | |
argument?: T | |
} | |
export type SagaRegistration<T = any> = (() => Iterator<any>) | SagaWithArguments<T> | |
export const sagaEquals = (sagaA: SagaRegistration, sagaB: SagaRegistration): boolean => { | |
if (typeof sagaA === 'function' && typeof sagaB === 'function') { | |
return sagaA === sagaB | |
} | |
if (!sagaA || !sagaB) { | |
return sagaA === sagaB | |
} | |
if (typeof sagaA === 'function') { | |
return ( | |
(sagaA as () => Iterator<any>) === (sagaB as SagaWithArguments).saga && !(sagaB as SagaWithArguments).argument | |
) | |
} | |
if (typeof sagaB === 'function') { | |
return ( | |
(sagaA as SagaWithArguments).saga === (sagaB as () => Iterator<any>) && !(sagaA as SagaWithArguments).argument | |
) | |
} | |
// TODO: This needs to be a deep equals | |
return ( | |
(sagaA as SagaWithArguments).saga === (sagaB as SagaWithArguments).saga && | |
(sagaA as SagaWithArguments).argument === (sagaB as SagaWithArguments).argument | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment