From 00027c3c54dadb22a38733f8a82edbf0a9b4d8c3 Mon Sep 17 00:00:00 2001 From: AsPulse Date: Thu, 12 Oct 2023 15:27:01 +0900 Subject: [PATCH] Use resetdirty instead --- packages/core/src/component/sugar/constant.ts | 4 ++-- packages/core/src/component/sugar/maple/array.ts | 4 ++-- packages/core/src/component/sugar/maple/index.ts | 4 ++-- packages/core/src/component/sugar/sync/ref.ts | 4 ++-- packages/core/src/component/sugar/sync/state.ts | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/core/src/component/sugar/constant.ts b/packages/core/src/component/sugar/constant.ts index c2d36c9..9c5dc90 100644 --- a/packages/core/src/component/sugar/constant.ts +++ b/packages/core/src/component/sugar/constant.ts @@ -1,6 +1,6 @@ import { logInSugar } from '@/util/logger'; import type { Sugar, SugarValue } from '.'; -import { setDirty } from './dirty'; +import { resetDirty, setDirty } from './dirty'; import { useMountSugar } from '@/util/mount'; export function constant( @@ -12,7 +12,7 @@ export function constant( useMountSugar({ sugar, mountAction: () => { - mountedSugar.isDirty = false; + resetDirty(mountedSugar); mountedSugar.get = (): SugarValue => ({ success: true, value }); mountedSugar.set = (): void => { logInSugar('WARN', 'Value of constant sugar conflicted by set method.', sugar); }; mountedSugar.setTemplate = (): void => { diff --git a/packages/core/src/component/sugar/maple/array.ts b/packages/core/src/component/sugar/maple/array.ts index 9bc7df8..ff1077f 100644 --- a/packages/core/src/component/sugar/maple/array.ts +++ b/packages/core/src/component/sugar/maple/array.ts @@ -3,7 +3,7 @@ import { useEffect , useId, useRef, useState } from 'react'; import type { SetTemplateMode, Sugar, SugarArrayNode, SugarArrayUser, SugarValue } from '@component/sugar'; import { logInSugar } from '@util/logger'; import { createEmptySugar } from '@component/sugar/create'; -import { setDirty } from '@component/sugar/dirty'; +import { resetDirty, setDirty } from '@component/sugar/dirty'; import { useMountSugar } from '@/util/mount'; // eslint-disable-next-line max-lines-per-function @@ -50,7 +50,7 @@ export function mapleArray( sugar, mountAction: () => { const mountedSugar = sugar as Sugar & { mounted: true }; - mountedSugar.isDirty = false; + resetDirty(mountedSugar); mountedSugar.get = (): SugarValue => { const values = keysRef.current.map(id => { const managed = getManagedSugar(id); diff --git a/packages/core/src/component/sugar/maple/index.ts b/packages/core/src/component/sugar/maple/index.ts index 1a3b6fe..2ce8b9f 100644 --- a/packages/core/src/component/sugar/maple/index.ts +++ b/packages/core/src/component/sugar/maple/index.ts @@ -5,7 +5,7 @@ import { SugarFormAssertionError, SugarFormUnmountedSugarError } from '@util/err import { log, logInSugar } from '@util/logger'; import type { BetterObjectConstructor, SugarObject } from '@util/object'; import { createEmptySugar } from '@component/sugar/create'; -import { setDirty } from '@component/sugar/dirty'; +import { resetDirty, setDirty } from '@component/sugar/dirty'; import { useMountSugarWithInit } from '@/util/mount'; declare const Object: BetterObjectConstructor; @@ -103,7 +103,7 @@ export function madeSugar( sugar.template = mode === 'replace' ? template : options.reshape.transform(newTemplate); set(fields, newTemplate, { type: 'template', mode }); }; - updateSugar.isDirty = false; + resetDirty(updateSugar); }, }; } diff --git a/packages/core/src/component/sugar/sync/ref.ts b/packages/core/src/component/sugar/sync/ref.ts index c056f0e..c323152 100644 --- a/packages/core/src/component/sugar/sync/ref.ts +++ b/packages/core/src/component/sugar/sync/ref.ts @@ -1,7 +1,7 @@ import type { MutableRefObject } from 'react'; import { useRef } from 'react'; import type { Sugar, SugarValue } from '..'; -import { setDirty } from '@component/sugar/dirty'; +import { resetDirty, setDirty } from '@component/sugar/dirty'; import { useMountSugar } from '@/util/mount'; export function syncRef( @@ -40,7 +40,7 @@ export function syncRef( setterWithDefault(v); setTimeout(refreshDirty, 0); }; - updateSugar.isDirty = false; + resetDirty(updateSugar); updateSugar.setTemplate(sugar.template); }, }); diff --git a/packages/core/src/component/sugar/sync/state.ts b/packages/core/src/component/sugar/sync/state.ts index ee96f8a..ad91d64 100644 --- a/packages/core/src/component/sugar/sync/state.ts +++ b/packages/core/src/component/sugar/sync/state.ts @@ -2,7 +2,7 @@ import type { Dispatch, SetStateAction } from 'react'; import { useEffect } from 'react'; import type { SugarValue , Sugar } from '@component/sugar'; import { isSugarObject } from '@util/object'; -import { setDirty } from '@component/sugar/dirty'; +import { resetDirty, setDirty } from '@component/sugar/dirty'; import { useMountSugar } from '@/util/mount'; import { logInSugar } from '@/util/logger'; @@ -19,7 +19,7 @@ export function syncState( sugar, mountAction: () => { const mountedSugar = sugar as Sugar & { mounted: true }; - mountedSugar.isDirty = false; + resetDirty(mountedSugar); mountedSugar.set = (value: T): void => setState(value); mountedSugar.setTemplate = (template: T): void => { sugar.template = template;