mirror of
https://github.com/misskey-dev/misskey.git
synced 2024-12-28 22:49:24 +09:00
f5459a25df
* fix(frontend): vue v3.4.16でタイムラインが正常に表示できない問題を修正
* type
* Revert "fix: downgrade vue to 3.4.15"
This reverts commit e12369ac13
.
* Update pnpm-lock.yaml
---------
Co-authored-by: tamaina <tamaina@hotmail.co.jp>
Co-authored-by: syuilo <4439005+syuilo@users.noreply.github.com>
36 lines
1.3 KiB
TypeScript
36 lines
1.3 KiB
TypeScript
/*
|
||
* SPDX-FileCopyrightText: syuilo and misskey-project
|
||
* SPDX-License-Identifier: AGPL-3.0-only
|
||
*/
|
||
|
||
import { deepClone } from './clone.js';
|
||
import type { Cloneable } from './clone.js';
|
||
|
||
type DeepPartial<T> = {
|
||
[P in keyof T]?: T[P] extends Record<string | number | symbol, unknown> ? DeepPartial<T[P]> : T[P];
|
||
};
|
||
|
||
function isPureObject(value: unknown): value is Record<string | number | symbol, unknown> {
|
||
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
||
}
|
||
|
||
/**
|
||
* valueにないキーをdefからもらう(再帰的)\
|
||
* nullはそのまま、undefinedはdefの値
|
||
**/
|
||
export function deepMerge<X extends Record<string | number | symbol, unknown>>(value: DeepPartial<X>, def: X): X {
|
||
if (isPureObject(value) && isPureObject(def)) {
|
||
const result = deepClone(value as Cloneable) as X;
|
||
for (const [k, v] of Object.entries(def) as [keyof X, X[keyof X]][]) {
|
||
if (!Object.prototype.hasOwnProperty.call(value, k) || value[k] === undefined) {
|
||
result[k] = v;
|
||
} else if (isPureObject(v) && isPureObject(result[k])) {
|
||
const child = deepClone(result[k] as Cloneable) as DeepPartial<X[keyof X] & Record<string | number | symbol, unknown>>;
|
||
result[k] = deepMerge<typeof v>(child, v);
|
||
}
|
||
}
|
||
return result;
|
||
}
|
||
throw new Error('deepMerge: value and def must be pure objects');
|
||
}
|