createPromiseLogic()
createPromiseLogic() is a factory function used to create custom PromiseLogic instances. Through configuration options, you can customize method names to better fit your project's naming conventions and business requirements.
This feature is particularly suitable for large projects, team collaboration, code refactoring, etc., helping you better organize and manage async logic code.
Syntax
createPromiseLogic(options?)
Parameters
| Parameter | Type | Description |
|---|---|---|
| options | CreatePromiseLogicOptions | Configuration options for customizing instance behavior and naming |
Configuration Option Properties
| Parameter | Type | Description |
|---|---|---|
| prefix | string | Method name prefix, e.g. "async" will generate asyncAnd, asyncOr, etc. |
| suffix | string | Method name suffix, e.g. "Logic" will generate andLogic, orLogic, etc. |
| rename | Record<string, string> | Custom rename mapping, e.g. { and: "conjunction", or: "disjunction" } |
Return Value
Returns a custom PromiseLogic instance containing configured methods.
PromiseLogicInstanceBehavior
Creation Successful
Successfully creates a custom PromiseLogic instance containing configured methods.
Special Case
The createPromiseLogic method never fails, always returns a valid PromiseLogic instance.
Examples
Basic Usage
Create default PromiseLogic instance
Add Prefix
Create instance with prefixed method names
Add Suffix
Create instance with suffixed method names
Custom Rename
Fully customize method names
Combined Configuration
Combine prefix, suffix, and rename
Real Application
Organize different logic groups in project
Naming Rules
Method Name Generation Rules
Priority Order
- 1. First check if there is a custom name in
renameconfiguration - 2. If not, apply
prefix + original name + suffixrule - 3. If none configured, use default name
Example
// Configuration: { prefix: 'async', suffix: 'Logic', rename: { and: 'conjunction' } }
// Generated method names:
// and → asyncConjunctionLogic (rename priority)
// or → asyncOrLogic (prefix + or + suffix)
// xor → asyncXorLogic (prefix + xor + suffix)
// Other methods follow the same pattern...
Important Notes
- • createPromiseLogic is used to create custom PromiseLogic instances, supporting method name customization
- • Can use prefix, suffix, and rename configurations simultaneously, configurations are applied in order
- • Methods not specified in rename will use default naming rules (prefix + original name + suffix)
- • Custom instances have the same functionality and behavior as default PromiseLogic
- • Suitable for projects that need to use different naming conventions in different business scenarios
- • Can be used for code organization, namespace isolation, team standard unification, etc.