From 04f8b52627147977896edf3ff190164133e65185 Mon Sep 17 00:00:00 2001 From: Matt Sutkowski Date: Fri, 12 Jun 2020 12:23:57 -0700 Subject: [PATCH] Add missing export for current in pre-3.7 types, add notes about usage, fix typo in docs --- compat/pre-3.7/dist/immer.d.ts | 3 +++ docs/current.md | 2 +- src/core/current.ts | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/compat/pre-3.7/dist/immer.d.ts b/compat/pre-3.7/dist/immer.d.ts index a8934300..c4c376a1 100644 --- a/compat/pre-3.7/dist/immer.d.ts +++ b/compat/pre-3.7/dist/immer.d.ts @@ -230,6 +230,9 @@ export function finishDraft(draft: T, listener?: PatchListener): Immutable /** Get the underlying object that is represented by the given draft */ export function original(value: T): T | void +/** Takes a snapshot of the current state of a draft and finalizes it (but without freezing). This is a great utility to print the current state during debugging (no Proxies in the way). The output of current can also be safely leaked outside the producer. */ +export function current(value: T): T + /** Returns true if the given value is an Immer draft */ export function isDraft(value: any): boolean diff --git a/docs/current.md b/docs/current.md index 20d042c4..2c0b9211 100644 --- a/docs/current.md +++ b/docs/current.md @@ -13,7 +13,7 @@ Objects generated by `current` work similar to the objects created by produce it 1. Unmodified objects will be structurally shared with the original objects. 1. If no changes are made to a draft, generally it holds that `original(draft) === current(draft)`, but this is not guaranteed. 1. Future changes to the draft won't be reflected in the object produced by `current` (except for references to undraftable objects) -1. Unlinke `produce` objects created by `current` will _not_ be frozen. +1. Unlike `produce` objects created by `current` will _not_ be frozen. Use `current` sparingly, it can be a potentially expensive operation, especially when using ES5. diff --git a/src/core/current.ts b/src/core/current.ts index d809049d..9e49fd70 100644 --- a/src/core/current.ts +++ b/src/core/current.ts @@ -14,6 +14,7 @@ import { getPlugin } from "../internal" +/** Takes a snapshot of the current state of a draft and finalizes it (but without freezing). This is a great utility to print the current state during debugging (no Proxies in the way). The output of current can also be safely leaked outside the producer. */ export function current(value: T): T export function current(value: any): any { if (!isDraft(value)) die(22, value)