immerjs / immerjs/immer

isModified helper

Open
#1,153 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

proposal
Dominant language
JavaScript
Stars
29k
Forks
881
PR merge metrics
No merged PRs in 30d

Description

🚀 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()
	}
})

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the existing isDraft, current, original, finishDraft, and createDraft APIs and how draft modification state is tracked. Define the public isModified behavior for nested drafts, add coverage for the requested opaque-update example, and confirm the existing test suite passes.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.