mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 21:55:59 +00:00
use of createRef instead of not working { corrent: xxx }
This commit is contained in:
26
packages/web/src/utility/createRef.ts
Normal file
26
packages/web/src/utility/createRef.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
interface Reference<T> {
|
||||
set(value: T);
|
||||
get(): T;
|
||||
reset(): void;
|
||||
update(func: (arg: T) => T);
|
||||
}
|
||||
|
||||
export default function createRef<T>(value: T): Reference<T> {
|
||||
return {
|
||||
value,
|
||||
initValue: value,
|
||||
|
||||
set(value) {
|
||||
this.value = value;
|
||||
},
|
||||
reset() {
|
||||
this.value = this.initValue;
|
||||
},
|
||||
get() {
|
||||
return this.value;
|
||||
},
|
||||
update(func) {
|
||||
this.value = func(this.value);
|
||||
},
|
||||
} as Reference<T>;
|
||||
}
|
||||
Reference in New Issue
Block a user