fix console.log higher-order calls in docs
This commit is contained in:
parent
d3c9a28c25
commit
9a00707eeb
3 changed files with 17 additions and 5 deletions
|
|
@ -137,10 +137,12 @@ dashboard.controller = function() {
|
||||||
|
|
||||||
dashboard.view = function(ctrl) {
|
dashboard.view = function(ctrl) {
|
||||||
return m("#example", [
|
return m("#example", [
|
||||||
new autocompleter.view(ctrl.autocompleter, {onchange: m.withAttr("value", console.log)}),
|
new autocompleter.view(ctrl.autocompleter, {onchange: m.withAttr("value", log)}),
|
||||||
]);
|
]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//an FP-friendly console.log
|
||||||
|
var log = function(value) {console.log(value)}
|
||||||
|
|
||||||
|
|
||||||
//initialize
|
//initialize
|
||||||
|
|
|
||||||
|
|
@ -136,14 +136,19 @@ For the most part, Mithril promises behave as you'd expect a [Promise/A+](http:/
|
||||||
Mithril promises forward a value downstream if a resolution callback returns `undefined`. This allows simpler debugging of promise chains:
|
Mithril promises forward a value downstream if a resolution callback returns `undefined`. This allows simpler debugging of promise chains:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
|
//a FP-friendly console.log
|
||||||
|
var log = function(value) {
|
||||||
|
console.log(value)
|
||||||
|
}
|
||||||
|
|
||||||
var data = m.request({method: "GET", url: "/data"})
|
var data = m.request({method: "GET", url: "/data"})
|
||||||
.then(console.log) //Mithril promises let us debug like this
|
.then(log) //Mithril promises let us debug like this
|
||||||
.then(doStuff)
|
.then(doStuff)
|
||||||
|
|
||||||
var data = m.request({method: "GET", url: "/data"})
|
var data = m.request({method: "GET", url: "/data"})
|
||||||
.then(function(value) { // Promises/A+ would require us to declare an anonymous function
|
.then(function(value) {
|
||||||
console.log(value) // here's the debugging snippet
|
console.log(value) // here's the debugging snippet
|
||||||
return value // and we need to remember to return the value as well
|
return value // Promises/A+ requires us to return a value
|
||||||
})
|
})
|
||||||
.then(doStuff) // or else `doStuff` will break
|
.then(doStuff) // or else `doStuff` will break
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -139,8 +139,13 @@ As you saw, you can chain operations that act on the response data. Typically th
|
||||||
In the example below, we take advantage of queuing to debug the AJAX response data prior to doing further processing on the user list
|
In the example below, we take advantage of queuing to debug the AJAX response data prior to doing further processing on the user list
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
|
//a FP-friendly console.log
|
||||||
|
var log = function(value) {
|
||||||
|
console.log(value)
|
||||||
|
}
|
||||||
|
|
||||||
var users = m.request({method: "GET", url: "/user"})
|
var users = m.request({method: "GET", url: "/user"})
|
||||||
.then(console.log);
|
.then(log);
|
||||||
.then(function(users) {
|
.then(function(users) {
|
||||||
//add one more user to the response
|
//add one more user to the response
|
||||||
return users.concat({name: "Jane"})
|
return users.concat({name: "Jane"})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue