Allow bare effecter as effect (#1075)
This commit is contained in:
parent
935f4c6acc
commit
82caa5d941
|
@ -9,7 +9,7 @@ As with [subscriptions](subscriptions.md), effects are used to deal with impure
|
|||
**_Signature:_**
|
||||
|
||||
```elm
|
||||
Effect : [EffecterFn, Payload?]
|
||||
Effect : EffecterFn | [EffecterFn, Payload]
|
||||
```
|
||||
|
||||
**_Naming Recommendation:_**
|
||||
|
|
|
@ -490,14 +490,13 @@ The way to run arbitrary code with some action, is to wrap that code in a functi
|
|||
```js
|
||||
const Select = (state, selected) => [
|
||||
{...state, selected},
|
||||
[() => {
|
||||
() =>
|
||||
fetch("https://jsonplaceholder.typicode.com/users/" + state.ids[selected])
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
console.log("Got data: ", data)
|
||||
/* now what ? */
|
||||
})
|
||||
}]
|
||||
]
|
||||
```
|
||||
|
||||
|
@ -507,11 +506,11 @@ When an action returns something like `[newState, [function]]`, the function is
|
|||
```js
|
||||
const Select = (state, selected) => [
|
||||
{...state, selected},
|
||||
[dispatch => { // <---
|
||||
dispatch => { // <---
|
||||
fetch("https://jsonplaceholder.typicode.com/users/" + state.ids[selected])
|
||||
.then(response => response.json())
|
||||
.then(data => dispatch(GotBio, data)) // <---
|
||||
}]
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
|
|
|
@ -120,11 +120,17 @@ declare module "hyperapp" {
|
|||
| Action<S, P>
|
||||
| readonly [action: Action<S, P>, payload: P]
|
||||
|
||||
// An effect is where side effects and any additional dispatching may occur.
|
||||
type Effect<S, P = any> = readonly [
|
||||
effecter: (dispatch: Dispatch<S>, payload: P) => void | Promise<void>,
|
||||
// An effecter is the function that runs an effect.
|
||||
type Effecter<S, P = any> = (
|
||||
dispatch: Dispatch<S>,
|
||||
payload: P
|
||||
]
|
||||
) => void | Promise<void>
|
||||
|
||||
// An effect is where side effects and any additional dispatching may occur.
|
||||
type Effect<S, P = any> =
|
||||
| Effecter<S, P>
|
||||
| readonly [effecter: Effecter<S, P>, payload: P]
|
||||
|
||||
|
||||
// Effects can be declared conditionally.
|
||||
type MaybeEffect<S, P> = null | undefined | boolean | "" | 0 | Effect<S, P>
|
||||
|
|
Loading…
Reference in New Issue