Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F996021
config-manager.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
config-manager.ts
View Options
import
dotProp
from
"dot-prop"
;
import
merge
from
"deepmerge"
;
import
type
Config
from
"./config"
;
type
ConfigObject
=
{
[
key
:
string
]
:
any
};
export
default
class
ConfigManager
{
DEFAULT_CONFIG
:
ConfigObject
;
CUSTOM_CONFIG
:
ConfigObject
;
isLocked
:
boolean
;
constructor
()
{
this
.
DEFAULT_CONFIG
=
{};
this
.
CUSTOM_CONFIG
=
{};
this
.
isLocked
=
false
;
}
setDefault
(
key
:
string
,
value
:
any
)
{
this
.
_setGivenConfig
(
this
.
DEFAULT_CONFIG
,
key
,
value
);
}
getDefaultConfig
(
key
:
string
)
{
return
dotProp
.
get
(
this
.
DEFAULT_CONFIG
,
key
);
}
set
(
key
:
string
,
value
:
any
)
{
this
.
_setGivenConfig
(
this
.
CUSTOM_CONFIG
,
key
,
value
);
}
_setGivenConfig
(
config
:
ConfigObject
,
key
:
string
,
value
:
any
)
{
this
.
_warnIfLocked
();
dotProp
.
set
(
config
,
key
,
value
);
}
_warnIfLocked
()
{
if
(
this
.
isLocked
)
{
console
.
warn
(
"Warning: "
+
"you shouldn't change config after ConfigManager was locked"
);
}
}
setRoot
(
params
:
ConfigObject
)
{
this
.
_warnIfLocked
();
this
.
CUSTOM_CONFIG
=
merge
(
this
.
CUSTOM_CONFIG
,
params
);
}
get
<
Key
extends
keyof
Config
>
(
key
:
Key
)
:
Config
[
Key
]
{
return
dotProp
.
get
(
merge
(
this
.
DEFAULT_CONFIG
,
this
.
CUSTOM_CONFIG
),
key
)
as
Config
[
Key
];
}
lock
()
{
this
.
isLocked
=
true
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Tue, Dec 24, 07:11 (22 h, 2 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
556967
Default Alt Text
config-manager.ts (1 KB)
Attached To
Mode
rS Sealious
Attached
Detach File
Event Timeline
Log In to Comment