Skip to content
This repository has been archived by the owner on Dec 11, 2023. It is now read-only.

Commit

Permalink
Use resetdirty instead
Browse files Browse the repository at this point in the history
  • Loading branch information
AsPulse committed Oct 12, 2023
1 parent 2a49c58 commit 00027c3
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/component/sugar/constant.ts
Original file line number Diff line number Diff line change
@@ -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<T>(
Expand All @@ -12,7 +12,7 @@ export function constant<T>(
useMountSugar({
sugar,
mountAction: () => {
mountedSugar.isDirty = false;
resetDirty(mountedSugar);
mountedSugar.get = (): SugarValue<T> => ({ success: true, value });
mountedSugar.set = (): void => { logInSugar('WARN', 'Value of constant sugar conflicted by set method.', sugar); };
mountedSugar.setTemplate = (): void => {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/component/sugar/maple/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -50,7 +50,7 @@ export function mapleArray<T>(
sugar,
mountAction: () => {
const mountedSugar = sugar as Sugar<T[]> & { mounted: true };
mountedSugar.isDirty = false;
resetDirty(mountedSugar);
mountedSugar.get = (): SugarValue<T[]> => {
const values = keysRef.current.map(id => {
const managed = getManagedSugar(id);
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/component/sugar/maple/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -103,7 +103,7 @@ export function madeSugar<T, U extends SugarObject>(
sugar.template = mode === 'replace' ? template : options.reshape.transform(newTemplate);
set<U>(fields, newTemplate, { type: 'template', mode });
};
updateSugar.isDirty = false;
resetDirty(updateSugar);
},
};
}
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/component/sugar/sync/ref.ts
Original file line number Diff line number Diff line change
@@ -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<T>(
Expand Down Expand Up @@ -40,7 +40,7 @@ export function syncRef<T>(
setterWithDefault(v);
setTimeout(refreshDirty, 0);
};
updateSugar.isDirty = false;
resetDirty(updateSugar);
updateSugar.setTemplate(sugar.template);
},
});
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/component/sugar/sync/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -19,7 +19,7 @@ export function syncState<T>(
sugar,
mountAction: () => {
const mountedSugar = sugar as Sugar<T> & { mounted: true };
mountedSugar.isDirty = false;
resetDirty(mountedSugar);
mountedSugar.set = (value: T): void => setState(value);
mountedSugar.setTemplate = (template: T): void => {
sugar.template = template;
Expand Down

0 comments on commit 00027c3

Please sign in to comment.