|
@@ -108,3 +108,25 @@ using `[...obj]`, not using `{...obj}`.
|
|
|
|
|
|
That way you can create eg. `const c = cowValueObject("person", 34, "name")`
|
|
|
to access `obj.person[34].name` with `c(obj)` / `c(obj, val)`.
|
|
|
+
|
|
|
+### `typedAction(type, fn)`
|
|
|
+
|
|
|
+This creates an action creator function that amend existing `fn` by:
|
|
|
+ - adding a `type` property to the result, as well as
|
|
|
+ - adding a `TYPE` property to action creator itself.
|
|
|
+
|
|
|
+So for example:
|
|
|
+
|
|
|
+```js
|
|
|
+export const answerQuestion =
|
|
|
+ typedAction("answer question", (index, answer) => ({
|
|
|
+ payload: {index, answer}
|
|
|
+ }));
|
|
|
+```
|
|
|
+
|
|
|
+allows you to call `answerQuestion(2, "Albert Einstein")` to create
|
|
|
+`{type: "answer question", payload: {index: 2, answer: "Albert Einstein"}}`;
|
|
|
+but it also allows you to use `case answerQuestion.TYPE:` in your reducer,
|
|
|
+since `answerQuestion.TYPE === "answer question"`.
|
|
|
+IOW, this removes the two-space problem of having `const FOO_BAR_TYPE`
|
|
|
+as well as `fooBar` action creator.
|