Add m.prop.sync
This commit is contained in:
parent
7227cc546f
commit
008ffc9587
4 changed files with 90 additions and 1 deletions
|
|
@ -11,6 +11,7 @@
|
|||
- [Reading/writing the current route](#readingwriting-the-current-route)
|
||||
- [Accessing route params](#accessing-route-params)
|
||||
- [Setting route prefix](#setting-route-prefix)
|
||||
- [m.request](#mrequest)
|
||||
|
||||
## `config` function
|
||||
|
||||
|
|
@ -270,3 +271,57 @@ m.route.mode = "pathname";
|
|||
```js
|
||||
m.route.prefix("");
|
||||
```
|
||||
|
||||
## m.request
|
||||
|
||||
[m.request](request.md) now returns an [m.prop stream](prop.md) instead of a promise. The main difference is you'll have to use `.run` to get similar functionality as a promise's `.then`:
|
||||
|
||||
### `v0.2.x`
|
||||
|
||||
```js
|
||||
m.request({ method: 'GET', url: 'https://api.github.com/' })
|
||||
.then(function (responseBody) {
|
||||
return m.request({ method: 'GET', url: responseBody.emojis_url });
|
||||
})
|
||||
.then(function (emojis) {
|
||||
console.log("+1 url:", emojis['+1']);
|
||||
});
|
||||
```
|
||||
|
||||
### `v1.x`
|
||||
|
||||
```js
|
||||
m.request({ method: 'GET', url: 'https://api.github.com/' })
|
||||
.run(function (responseBody) {
|
||||
return m.request({ method: 'GET', url: responseBody.emojis_url });
|
||||
})
|
||||
.run(function (emojis) {
|
||||
console.log("+1 url:", emojis['+1']);
|
||||
});
|
||||
```
|
||||
|
||||
The equivalent of `m.sync` is now `m.prop.sync`:
|
||||
|
||||
### `v0.2.x`
|
||||
|
||||
```js
|
||||
m.sync([
|
||||
m.request({ method: 'GET', url: 'https://api.github.com/users/lhorie' }),
|
||||
m.request({ method: 'GET', url: 'https://api.github.com/users/isiahmeadows' }),
|
||||
])
|
||||
.then(function (users) {
|
||||
console.log("Contributors:", users[0].name, "and", users[1].name);
|
||||
});
|
||||
```
|
||||
|
||||
### `v1.x`
|
||||
|
||||
```js
|
||||
m.prop.sync([
|
||||
m.request({ method: 'GET', url: 'https://api.github.com/users/lhorie' }),
|
||||
m.request({ method: 'GET', url: 'https://api.github.com/users/isiahmeadows' }),
|
||||
])
|
||||
.run(function (users) {
|
||||
console.log("Contributors:", users[0].name, "and", users[1].name);
|
||||
});
|
||||
```
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue