Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

isModified helper #1153

Open
Mangatt opened this issue Jan 3, 2025 · 0 comments
Open

isModified helper #1153

Mangatt opened this issue Jan 3, 2025 · 0 comments
Labels

Comments

@Mangatt
Copy link

Mangatt commented Jan 3, 2025

🚀 Feature Proposal

It would be great to have isModified helper, much like isDraft or current functions.

Motivation

More efficient updates of derived data in draft. Immer currently do have all necessary information, in it's essence it is stripped down version of current.

Can this be solved in user-land code?

It can be solved in following ways:

  1. You can compare current with original in draft - but that's unnecessarily expensive for simple yes/no query
  2. You can finishDraft, compare with original, then createDraft again if necessary

Example

produce(deeplyNestedObject, (draft) => {
	performOpaqueDeeplyNestedUpdates(draft)
	
	if(isModified(draft.item)){
		draft.item.modifiedOn = new Date()
	}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant