Skip to content

Commit

Permalink
types: createDraft/finishDraft functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mweststrate authored and aleclarson committed Feb 2, 2019
1 parent e2eb0a8 commit edda437
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/immer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,19 @@ export function setUseProxies(useProxies: boolean): void
*/
export function applyPatches<S>(base: S, patches: Patch[]): S

/**
* Creates a mutable draft from an (immutable) object / array.
* The draft can be modified until `finishDraft` is called
*/
export function createDraft<T>(base: T): Draft<T>

/**
* Given a draft that was created using `createDraft`,
* finalizes the draft into a new immutable object.
* Optionally a patch-listener can be provided to gather the patches that are needed to construct the object.
*/
export function finishDraft<T>(base: Draft<T>, listener?: PatchListener): T

/** Get the underlying object that is represented by the given draft */
export function original<T>(value: T): T | void

Expand Down
13 changes: 13 additions & 0 deletions src/immer.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,16 @@ declare export function applyPatches<S>(state: S, patches: Patch[]): S
declare export function original<S>(value: S): ?S

declare export function isDraft(value: any): boolean

/**
* Creates a mutable draft from an (immutable) object / array.
* The draft can be modified until `finishDraft` is called
*/
declare export function createDraft<T>(base: T): T

/**
* Given a draft that was created using `createDraft`,
* finalizes the draft into a new immutable object.
* Optionally a patch-listener can be provided to gather the patches that are needed to construct the object.
*/
declare export function finishDraft<T>(base: T, listener?: PatchListener): T

0 comments on commit edda437

Please sign in to comment.