-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add global configuration for node key generation and update clone fun…
…ction to use it
- Loading branch information
1 parent
1670c0b
commit 3804c00
Showing
3 changed files
with
57 additions
and
11 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { NodeKeyGenerator, defaultNodeKeyGenerator } from "./node/utils/nodeKeyGenerator" | ||
|
||
/** | ||
* Global config object. | ||
*/ | ||
export interface GlobalConfig { | ||
/** | ||
* Node key generator function. | ||
*/ | ||
keyGenerator: NodeKeyGenerator | ||
} | ||
|
||
// defaults | ||
let globalConfig: GlobalConfig = { | ||
keyGenerator: defaultNodeKeyGenerator, | ||
} | ||
|
||
/** | ||
* Partially sets the current global config. | ||
* | ||
* @param config Partial object with the new configurations. Options not included in the object won't be changed. | ||
*/ | ||
export function setGlobalConfig(config: Partial<GlobalConfig>) { | ||
globalConfig = Object.freeze({ | ||
...globalConfig, | ||
...config, | ||
}) | ||
} | ||
|
||
/** | ||
* Returns the current global config object. | ||
* | ||
* @returns | ||
*/ | ||
export function getGlobalConfig(): Readonly<GlobalConfig> { | ||
return globalConfig | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,16 @@ | ||
import { configure } from "mobx" | ||
import { setGlobalConfig } from "../src/globalConfig" | ||
|
||
configure({ enforceActions: "always" }) | ||
|
||
let id = 1 | ||
|
||
setGlobalConfig({ | ||
keyGenerator() { | ||
return `id-${id++}` | ||
}, | ||
}) | ||
|
||
beforeEach(() => { | ||
id = 1 | ||
}) |