From 35e5b112219dc35a764c036d24d268cb133d4510 Mon Sep 17 00:00:00 2001
From: rednaZ
Date: Thu, 25 Jun 2020 18:43:55 +0200
Subject: [PATCH] Flow: add type for produceWithPatches
---
src/types/index.js.flow | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/src/types/index.js.flow b/src/types/index.js.flow
index fb952be4..29758fbd 100644
--- a/src/types/index.js.flow
+++ b/src/types/index.js.flow
@@ -39,9 +39,33 @@ interface IProduce {
): (currentState: S, a: A, b: B, c: C, ...extraArgs: any[]) => S;
}
+interface IProduceWithPatches {
+ /**
+ * Like `produce`, but instead of just returning the new state,
+ * a tuple is returned with [nextState, patches, inversePatches]
+ *
+ * Like produce, this function supports currying
+ */
+ (
+ currentState: S,
+ recipe: (draftState: S) => S | void
+ ): [S, Patch[], Patch[]];
+ // curried invocations with inital state
+ (
+ recipe: (draftState: S, a: A, b: B, c: C, ...extraArgs: any[]) => S | void,
+ initialState: S
+ ): (currentState: S | void, a: A, b: B, c: C, ...extraArgs: any[]) => [S, Patch[], Patch[]];
+ // curried invocations without inital state
+ (
+ recipe: (draftState: S, a: A, b: B, c: C, ...extraArgs: any[]) => S | void
+ ): (currentState: S, a: A, b: B, c: C, ...extraArgs: any[]) => [S, Patch[], Patch[]];
+}
+
declare export var produce: IProduce
declare export default IProduce
+declare export var produceWithPatches: IProduceWithPatches
+
declare export var nothing: typeof undefined
declare export var immerable: Symbol