Merge remote-tracking branch 'origin/next' into next
This commit is contained in:
commit
8eb68edae6
5 changed files with 31 additions and 3 deletions
|
|
@ -27,7 +27,7 @@ var Contact = function(data) {
|
||||||
this.email = m.prop(data.email)
|
this.email = m.prop(data.email)
|
||||||
}
|
}
|
||||||
Contact.list = function(data) {
|
Contact.list = function(data) {
|
||||||
return m.request({method: "GET", url: "/api/contact", data: data})
|
return m.request({method: "GET", url: "/api/contact", type: Contact})
|
||||||
}
|
}
|
||||||
Contact.save = function(data) {
|
Contact.save = function(data) {
|
||||||
return m.request({method: "POST", url: "/api/contact", data: data})
|
return m.request({method: "POST", url: "/api/contact", data: data})
|
||||||
|
|
|
||||||
|
|
@ -217,7 +217,7 @@ Components can be placed anywhere a regular element can. If you have components
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var App = {
|
var App = {
|
||||||
ctrl: function() {
|
controller: function() {
|
||||||
return {data: [1, 2, 3]}
|
return {data: [1, 2, 3]}
|
||||||
}
|
}
|
||||||
view: function(ctrl) {
|
view: function(ctrl) {
|
||||||
|
|
|
||||||
|
|
@ -164,7 +164,7 @@ m.route(document.body, "/", {
|
||||||
});
|
});
|
||||||
|
|
||||||
//re-route to dashboard
|
//re-route to dashboard
|
||||||
m.route("/dashboard"); // logs "unloading home"
|
m.route("/dashboard"); // logs "unloading home component"
|
||||||
```
|
```
|
||||||
|
|
||||||
This mechanism is useful to clear timers and unsubscribe event handlers. If you have a hierarchy of components, you can recursively call `onunload` on all the components in the tree or use a [pubsub](http://microjs.com/#pubsub) library to unload specific components on demand.
|
This mechanism is useful to clear timers and unsubscribe event handlers. If you have a hierarchy of components, you can recursively call `onunload` on all the components in the tree or use a [pubsub](http://microjs.com/#pubsub) library to unload specific components on demand.
|
||||||
|
|
|
||||||
|
|
@ -859,6 +859,7 @@ var m = (function app(window, undefined) {
|
||||||
prop.then = function(resolve, reject) {
|
prop.then = function(resolve, reject) {
|
||||||
return propify(promise.then(resolve, reject), initialValue)
|
return propify(promise.then(resolve, reject), initialValue)
|
||||||
};
|
};
|
||||||
|
prop.catch = prop.then.bind(null, null)
|
||||||
return prop
|
return prop
|
||||||
}
|
}
|
||||||
//Promiz.mithril.js | Zolmeister | MIT
|
//Promiz.mithril.js | Zolmeister | MIT
|
||||||
|
|
|
||||||
|
|
@ -3872,6 +3872,12 @@ function testMithril(mock) {
|
||||||
mock.XMLHttpRequest.$instances.pop().onreadystatechange()
|
mock.XMLHttpRequest.$instances.pop().onreadystatechange()
|
||||||
return prop().message === "error occurred" && error().message === "error occurred"
|
return prop().message === "error occurred" && error().message === "error occurred"
|
||||||
})
|
})
|
||||||
|
test(function() {
|
||||||
|
var error = m.prop("no error")
|
||||||
|
var prop = m.request({method: "GET", url: "test", deserialize: function() {throw new Error("error occurred")}}).catch(error)
|
||||||
|
mock.XMLHttpRequest.$instances.pop().onreadystatechange()
|
||||||
|
return prop().message === "error occurred" && error().message === "error occurred"
|
||||||
|
})
|
||||||
test(function() {
|
test(function() {
|
||||||
var error = m.prop("no error"), exception
|
var error = m.prop("no error"), exception
|
||||||
var prop = m.request({method: "GET", url: "test", deserialize: function() {throw new TypeError("error occurred")}}).then(null, error)
|
var prop = m.request({method: "GET", url: "test", deserialize: function() {throw new TypeError("error occurred")}}).then(null, error)
|
||||||
|
|
@ -4052,6 +4058,13 @@ function testMithril(mock) {
|
||||||
deferred.reject("test")
|
deferred.reject("test")
|
||||||
return value === "test"
|
return value === "test"
|
||||||
})
|
})
|
||||||
|
test(function() {
|
||||||
|
var value
|
||||||
|
var deferred = m.deferred()
|
||||||
|
deferred.promise.catch(function(data) {value = data})
|
||||||
|
deferred.reject("test")
|
||||||
|
return value === "test"
|
||||||
|
})
|
||||||
test(function() {
|
test(function() {
|
||||||
var value
|
var value
|
||||||
var deferred = m.deferred()
|
var deferred = m.deferred()
|
||||||
|
|
@ -4059,6 +4072,13 @@ function testMithril(mock) {
|
||||||
deferred.reject("test")
|
deferred.reject("test")
|
||||||
return value === "foo"
|
return value === "foo"
|
||||||
})
|
})
|
||||||
|
test(function() {
|
||||||
|
var value
|
||||||
|
var deferred = m.deferred()
|
||||||
|
deferred.promise.catch(function(data) {return "foo"}).then(function(data) {value = data})
|
||||||
|
deferred.reject("test")
|
||||||
|
return value === "foo"
|
||||||
|
})
|
||||||
test(function() {
|
test(function() {
|
||||||
var value1, value2
|
var value1, value2
|
||||||
var deferred = m.deferred()
|
var deferred = m.deferred()
|
||||||
|
|
@ -4224,6 +4244,13 @@ function testMithril(mock) {
|
||||||
deferred1.resolve("test")
|
deferred1.resolve("test")
|
||||||
return value[0] === "test" && value[1] === "foo"
|
return value[0] === "test" && value[1] === "foo"
|
||||||
})
|
})
|
||||||
|
test(function() {
|
||||||
|
var value
|
||||||
|
var deferred = m.deferred()
|
||||||
|
m.sync([deferred.promise]).catch(function(data) {value = data})
|
||||||
|
deferred.reject("fail")
|
||||||
|
return value[0] === "fail"
|
||||||
|
})
|
||||||
test(function() {
|
test(function() {
|
||||||
var value = 1
|
var value = 1
|
||||||
m.sync([]).then(function() {value = 2})
|
m.sync([]).then(function() {value = 2})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue