-
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.
chore(config-core): config use proxy
- Loading branch information
Showing
16 changed files
with
145 additions
and
64 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
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
type ChangeHandler = (path: string, value: any) => void; | ||
|
||
export function createReactiveObject<T extends object>(target: T, onChange: ChangeHandler, parentPath: string = ''): T { | ||
const handler: ProxyHandler<T> = { | ||
get(target: T, key: string | symbol, receiver: any): any { | ||
const result = Reflect.get(target, key, receiver); | ||
if (typeof result === 'object' && result !== null) { | ||
return createReactiveObject(result, onChange, `${parentPath}${String(key)}.`); | ||
} | ||
return result; | ||
}, | ||
|
||
set(target: T, key: string | symbol, value: any, receiver: any): boolean { | ||
const ownTarget = receiver === target ? target : Object.create(target); | ||
const oldValue = Reflect.get(ownTarget, key, receiver); | ||
|
||
if (oldValue !== value) { | ||
const path = `${parentPath}${String(key)}`; | ||
onChange(path, value); | ||
} | ||
|
||
return Reflect.set(ownTarget, key, value, receiver); | ||
}, | ||
}; | ||
|
||
return new Proxy(target, handler); | ||
} | ||
|
||
// // 使用示例 | ||
// function handleChange(path: string, value: any): void { | ||
// console.log(`Property "${path}" changed to`, value); | ||
// } | ||
|
||
// const r = createReactiveObject({ a: { b: 1 } }, handleChange); | ||
|
||
// r.a.b = 2; // 输出: Property "a.b" changed to 2 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
# TODO | ||
|
||
- 软同步与硬同步? | ||
- 软同步与硬同步?(这个不做) | ||
- async init 和 load | ||
- 细粒度更新(不是所有配置的变化) | ||
|
||
# DONE | ||
|
||
|
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 |
---|---|---|
|
@@ -9,6 +9,8 @@ | |
*/ | ||
|
||
export interface EventbusOptions { | ||
|
||
delimiter: "/", | ||
|
||
} | ||
|
||
|
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 +1,8 @@ | ||
import {ResultManager} from './' | ||
import { ResultFactory } from '../lib'; | ||
import zh from './zh'; | ||
|
||
const resultFactory = new ResultFactory({ | ||
friendlyMessageBuilder: (result) => { | ||
return zh[result.bizChain.join('.')] ?? zh['default']; | ||
}, | ||
}); |
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,8 @@ | ||
export default { | ||
user: { | ||
login: { | ||
success: '登录成功', | ||
error: '登录失败', | ||
}, | ||
}, | ||
}; |
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