-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(signals): add support for _ method names in withCalls
Add support for private methods (methods with _ in the start of the name) to withCalls fix #142
- Loading branch information
1 parent
b79659c
commit 0fa2efe
Showing
4 changed files
with
123 additions
and
14 deletions.
There are no files selected for viewing
38 changes: 29 additions & 9 deletions
38
libs/ngrx-traits/signals/src/lib/with-call-status/with-call-status.util.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,35 @@ | ||
import { capitalize } from '../util'; | ||
|
||
export function getWithCallStatusKeys(config?: { prop?: string }) { | ||
const prop = config?.prop; | ||
export function getWithCallStatusKeys(config?: { | ||
prop?: string; | ||
supportPrivate?: boolean; | ||
}) { | ||
let prop = config?.prop; | ||
let prefix = ''; | ||
|
||
if (config?.supportPrivate && prop?.startsWith('_')) { | ||
prop = prop.slice(1); | ||
prefix = '_'; | ||
} | ||
|
||
const capitalizedProp = prop && capitalize(prop); | ||
return { | ||
callStatusKey: prop ? `${config.prop}CallStatus` : 'callStatus', | ||
loadingKey: prop ? `is${capitalizedProp}Loading` : 'isLoading', | ||
loadedKey: prop ? `is${capitalizedProp}Loaded` : 'isLoaded', | ||
errorKey: prop ? `${config.prop}Error` : 'error', | ||
setLoadingKey: prop ? `set${capitalizedProp}Loading` : 'setLoading', | ||
setLoadedKey: prop ? `set${capitalizedProp}Loaded` : 'setLoaded', | ||
setErrorKey: prop ? `set${capitalizedProp}Error` : 'setError', | ||
callStatusKey: prop ? `${prefix}${prop}CallStatus` : `${prefix}callStatus`, | ||
loadingKey: prop | ||
? `${prefix}is${capitalizedProp}Loading` | ||
: `${prefix}isLoading`, | ||
loadedKey: prop | ||
? `${prefix}is${capitalizedProp}Loaded` | ||
: `${prefix}isLoaded`, | ||
errorKey: prop ? `${prefix}${prop}Error` : `${prefix}error`, | ||
setLoadingKey: prop | ||
? `${prefix}set${capitalizedProp}Loading` | ||
: `${prefix}setLoading`, | ||
setLoadedKey: prop | ||
? `${prefix}set${capitalizedProp}Loaded` | ||
: `${prefix}setLoaded`, | ||
setErrorKey: prop | ||
? `${prefix}set${capitalizedProp}Error` | ||
: `${prefix}setError`, | ||
}; | ||
} |
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
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
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