46 lines
1.5 KiB
JavaScript
46 lines
1.5 KiB
JavaScript
import { normalizeSocialLinks } from './social-links.js'
|
|
|
|
export const SOCIAL_SETTINGS_FIELDS = ['socialLinks']
|
|
|
|
/**
|
|
* SNS 설정 기본 스냅샷을 만든다.
|
|
* @returns {Object} 기본 SNS 설정 값
|
|
*/
|
|
export const createDefaultSocialSettingsSnapshot = () => ({
|
|
socialLinks: []
|
|
})
|
|
|
|
/**
|
|
* SNS 설정 값을 저장·비교 가능한 형태로 정규화한다.
|
|
* @param {Object} source - 원본 설정 값
|
|
* @returns {Object} 정규화된 SNS 설정 값
|
|
*/
|
|
export const normalizeSocialSettingsSection = (source = {}) => ({
|
|
socialLinks: normalizeSocialLinks(source.socialLinks)
|
|
})
|
|
|
|
/**
|
|
* SNS 설정 필드만 대상 객체에 복사한다.
|
|
* @param {Object} target - 값을 받을 객체
|
|
* @param {Object} source - 값을 제공할 객체
|
|
* @returns {void}
|
|
*/
|
|
export const assignSocialSettingsSection = (target, source = {}) => {
|
|
const normalized = normalizeSocialSettingsSection(source)
|
|
SOCIAL_SETTINGS_FIELDS.forEach((field) => {
|
|
target[field] = normalized[field]
|
|
})
|
|
}
|
|
|
|
/**
|
|
* 두 SNS 설정 값이 다른지 확인한다.
|
|
* @param {Object} current - 현재 설정 값
|
|
* @param {Object} snapshot - 비교할 스냅샷
|
|
* @returns {boolean} 변경 여부
|
|
*/
|
|
export const hasSocialSettingsSectionChanges = (current, snapshot) => {
|
|
const normalizedCurrent = normalizeSocialSettingsSection(current)
|
|
const normalizedSnapshot = normalizeSocialSettingsSection(snapshot)
|
|
return JSON.stringify(normalizedCurrent.socialLinks) !== JSON.stringify(normalizedSnapshot.socialLinks)
|
|
}
|