Skip to content

Commit 6717081

Browse files
committed
docs: modify readme
1 parent f17067e commit 6717081

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

README.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,15 @@ You can call one of the functions of that object:
257257
|---|---|
258258
| `cmd.ofMsg` | Dispatches a new message. |
259259
| `cmd.batch` | Aggregates an array of messages. |
260+
| `cmd.ofEither` | Calls a function (sync or async) and maps the result into a message. |
261+
| `cmd.ofSuccess` | Same as `ofEither` but ignores the error case. |
262+
| `cmd.ofError` | Same as `ofEither` but ignores the success case. |
260263
| `cmd.ofFunc.either` | Calls a synchronous function and maps the result into a message. |
261-
| `cmd.ofFunc.attempt` | Like `either` but ignores the success case. |
262-
| `cmd.ofFunc.perform` | Like `either` but ignores the error case. |
264+
| `cmd.ofFunc.perform` | Same as `either` but ignores the error case. |
265+
| `cmd.ofFunc.attempt` | Same as `either` but ignores the success case. |
263266
| `cmd.ofPromise.either` | Calls an async function and maps the result into a message. |
264-
| `cmd.ofPromise.attempt` | Like `either` but ignores the success case. |
265-
| `cmd.ofPromise.perform` | Like `either` but ignores the error case. |
267+
| `cmd.ofPromise.perform` | Same as `either` but ignores the error case. |
268+
| `cmd.ofPromise.attempt` | Same as `either` but ignores the success case. |
266269
| `cmd.ofSub` | Use this function to trigger a command in a subscription. |
267270
268271
### Dispatch a message
@@ -334,7 +337,7 @@ and handle the messages in the **update** function:
334337
// If loadSettings resolves it dispatches "SettingsLoaded"
335338
// If it fails it dispatches "Error"
336339
// The return type of loadSettings must fit Msg.settingsLoaded
337-
return [{}, cmd.ofPromise.either(loadSettings, Msg.settingsLoaded, Msg.error, "firstArg", 123)];
340+
return [{}, cmd.ofEither(loadSettings, Msg.settingsLoaded, Msg.error, "firstArg", 123)];
338341
},
339342

340343
settingsLoaded () {
@@ -368,7 +371,7 @@ export function init (props: Props): InitResult {
368371
To dispatch more than one command from `init` or `update` you can either use the `cmd.batch` function or simply return multiple commands:
369372
370373
```ts
371-
return [{}, cmd.ofMsg(Msg.loadData()), cmd.ofPromise.either(doStuff, Msg.success, Msg.error)];
374+
return [{}, cmd.ofMsg(Msg.loadData()), cmd.ofEither(doStuff, Msg.success, Msg.error)];
372375
```
373376
374377
## Subscriptions
@@ -601,7 +604,7 @@ export function init (): Model {
601604

602605
export const update: UpdateMap<Props, Model, Message> = {
603606
loadSettings () {
604-
return [{}, cmd.ofPromise.either(loadSettings, Msg.settingsLoaded, Msg.error)];
607+
return [{}, cmd.ofEither(loadSettings, Msg.settingsLoaded, Msg.error)];
605608
}
606609

607610
settingsLoaded ({ settings }) {
@@ -708,7 +711,7 @@ export function init (): InitResult<Model, Message> {
708711
export function update (_model: Model, msg: Message): UpdateReturnType<Model, Message> {
709712
switch (msg.name) {
710713
case "loadSettings":
711-
return [{}, cmd.ofPromise.either(loadSettings, Msg.settingsLoaded, Msg.error)];
714+
return [{}, cmd.ofEither(loadSettings, Msg.settingsLoaded, Msg.error)];
712715

713716
case "settingsLoaded":
714717
return [{ settings: msg.settings }];
@@ -827,7 +830,7 @@ To inform the parent component about some action, let's say to close a dialog fo
827830
{
828831
// ...
829832
close () {
830-
return [{}, cmd.ofFunc.attempt(props.onClose, Msg.error)];
833+
return [{}, cmd.ofError(props.onClose, Msg.error)];
831834
}
832835
// ...
833836
};

0 commit comments

Comments
 (0)