v0.2.2-rc.1
This commit is contained in:
parent
484a9d6c70
commit
270b20a2b0
110 changed files with 17357 additions and 3070 deletions
|
|
@ -1,11 +1,18 @@
|
|||
## Change Log
|
||||
|
||||
[v0.2.2-rc.1](http://mithril.js.org/archive/v0.2.2-rc.1)
|
||||
|
||||
### Bug Fixes:
|
||||
|
||||
- revert regressions from 0.2.1 refactor
|
||||
- revert `finally` because it's not in the ES6 promise spec
|
||||
|
||||
[v0.2.1](http://mithril.js.org/archive/v0.2.1)
|
||||
|
||||
### News:
|
||||
|
||||
- large refactor to take better advantage of Chrome js optimizations and improve source code readability (thanks to @isiahmeadows)
|
||||
- added `catch` and `finally` to promises
|
||||
- added `catch` to promises
|
||||
- improvements and fixes in the documentation and wiki
|
||||
- `m(component, ...args)` can now be used as a shorthand for `m.component(component, ...args)`
|
||||
|
||||
|
|
@ -15,7 +22,6 @@
|
|||
- fix edge case with falsy keys
|
||||
- fix controller prototype inheritance in component controllers
|
||||
- fix return value of `parseQueryString` if input is empty string
|
||||
- fix component unloading [#614](https://github.com/lhorie/mithril.js/issues/614) [#866](https://github.com/lhorie/mithril.js/issues/866)
|
||||
|
||||
---
|
||||
|
||||
|
|
@ -478,7 +484,7 @@
|
|||
### Bug Fixes:
|
||||
|
||||
- diff no longer touch the DOM when processing `style` attributes and event handlers
|
||||
- returning a thenable to a resolution callback in `m.deferred().promise` now causes the promise to adopt its state
|
||||
- returning a thennable to a resolution callback in `m.deferred().promise` now causes the promise to adopt its state
|
||||
- diff now correctly clears subtree if null or undefined is passed as a node
|
||||
|
||||
---
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/* global m: false */
|
||||
// NTBD: ensure this targets the current API.
|
||||
// TODO: ensure this targets the current API.
|
||||
window.templateConverter = (function () {
|
||||
"use strict"
|
||||
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ var MyComponent = {
|
|||
controller: function(data) {
|
||||
return {
|
||||
increment: function() {
|
||||
//This is a simplification for the sake of the example.
|
||||
//This is a simplication for the sake of the example.
|
||||
//Typically, values are modified via model methods,
|
||||
//rather than modified directly
|
||||
model.count++
|
||||
|
|
@ -590,7 +590,7 @@ where:
|
|||
|
||||
- **Component component**
|
||||
|
||||
A component is supposed to be an Object with two keys: `controller` and `view`. Each of these should point to a Javascript function. If a controller is not specified, Mithril will automatically create an empty controller function.
|
||||
A component is supposed to be an Object with two keys: `controller` and `view`. Each of these should point to a Javascript function. If a contoller is not specified, Mithril will automatically create an empty controller function.
|
||||
|
||||
- **Object attributes**
|
||||
|
||||
|
|
|
|||
|
|
@ -152,7 +152,7 @@ The `m.startComputation` / `m.endComputation` pair is designed to be "stacked",
|
|||
|
||||
Therefore, using the computation methods is recommended in order to reduce the amount of intermediate redraws that would otherwise occur as multiple asynchronous services are resolved.
|
||||
|
||||
When computation methods are used diligently and religiously, templates are never redrawn with incomplete data. However, it's important to always write conditional tests in templates to account for the possibility of nullables, because redraws may come to occur more aggressively than data is available (perhaps because a newly introduced 3rd party library calls `m.redraw`, or because you might want a more aggressive redraw policy to implement a specific feature down the road).
|
||||
When computation methods are used dilligently and religiously, templates are never redrawn with incomplete data. However, it's important to always write conditional tests in templates to account for the possibility of nullables, because redraws may come to occur more aggressively than data is available (perhaps because a newly introduced 3rd party library calls `m.redraw`, or because you might want a more aggressive redraw policy to implement a specific feature down the road).
|
||||
|
||||
Defending against nullables can typically be achieved via the `initialValue` option in [`m.request`](mithril.request.md) and basic null checks (e.g. `data ? m("div", data) : null`).
|
||||
|
||||
|
|
|
|||
|
|
@ -165,7 +165,7 @@ m.request({method: "GET", url: "/user/:id", data: {id: 1}})
|
|||
.then(function(user) {
|
||||
if (!user.isAdmin) throw new Error("Sorry, you don't have permissions")
|
||||
})
|
||||
.then(null, error) //handle the application error: bind to a getter-setter for displaying it on the template
|
||||
.then(null, error) //handle the application error: bind to a getter-setter for diplaying it on the template
|
||||
```
|
||||
|
||||
Note that the default promise exception handling semantics can be modified. See the next section.
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ The [`m.startComputation` / `m.endComputation` pair](mithril.computation.md) is
|
|||
|
||||
Therefore, using the computation methods is recommended in order to reduce the amount of intermediate redraws that would otherwise occur as multiple asynchronous services are resolved.
|
||||
|
||||
When computation methods are used diligently and religiously, templates are never redrawn with incomplete data. However, it's important to always write conditional tests in templates to account for the possibility of nullables, because redraws may come to occur more aggressively than data is available (perhaps because a newly introduced 3rd party library calls `m.redraw`, or because you might want a more aggressive redraw policy to implement a specific feature down the road).
|
||||
When computation methods are used dilligently and religiously, templates are never redrawn with incomplete data. However, it's important to always write conditional tests in templates to account for the possibility of nullables, because redraws may come to occur more aggressively than data is available (perhaps because a newly introduced 3rd party library calls `m.redraw`, or because you might want a more aggressive redraw policy to implement a specific feature down the road).
|
||||
|
||||
Defending against nullables can typically be achieved via the `initialValue` option in [`m.request`](mithril.request.md) and basic null checks (e.g. `data ? m("div", data) : null`).
|
||||
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ var users = m.request({method: "GET", url: "/user"});
|
|||
|
||||
Note that this getter-setter holds an *undefined* value until the AJAX request completes. Attempting to unwrap its value early will likely result in errors.
|
||||
|
||||
The returned getter-setter also implements the [promise](mithril.deferred.md) interface (also known as a *thenable*): this is the mechanism you should always use to queue operations to be performed on the data from the web service.
|
||||
The returned getter-setter also implements the [promise](mithril.deferred.md) interface (also known as a *thennable*): this is the mechanism you should always use to queue operations to be performed on the data from the web service.
|
||||
|
||||
The simplest use case of this feature is to implement functional value assignment via `m.prop` (i.e. the same thing as above). You can bind a pre-existing getter-setter by passing it in as a parameter to a `.then` method:
|
||||
|
||||
|
|
@ -73,9 +73,9 @@ var doSomething = function() { /*...*/ }
|
|||
m.request({method: "GET", url: "/user"}).then(users).then(doSomething)
|
||||
```
|
||||
|
||||
While both basic assignment syntax and thenable syntax can be used to the same effect, typically it's recommended that you use the assignment syntax whenever possible, as it's easier to read.
|
||||
While both basic assignment syntax and thennable syntax can be used to the same effect, typically it's recommended that you use the assignment syntax whenever possible, as it's easier to read.
|
||||
|
||||
The thenable mechanism is intended to be used in three ways:
|
||||
The thennable mechanism is intended to be used in three ways:
|
||||
|
||||
- in the model layer: to process web service data in transformative ways (e.g. filtering a list based on a parameter that the web service doesn't support)
|
||||
- in the controller layer: to bind redirection code upon a condition
|
||||
|
|
@ -122,7 +122,7 @@ var controller = function() {
|
|||
|
||||
#### Binding errors
|
||||
|
||||
Mithril thenables take two functions as optional parameters: the first parameter is called if the web service request completes successfully. The second one is called if it completes with an error.
|
||||
Mithril thennables take two functions as optional parameters: the first parameter is called if the web service request completes successfully. The second one is called if it completes with an error.
|
||||
|
||||
Error binding is meant to be done in the controller layer. Doing it in the model level is also possible, but generally leads to more code in order to connect all the dots.
|
||||
|
||||
|
|
|
|||
|
|
@ -254,11 +254,17 @@ where:
|
|||
|
||||
- **String key**
|
||||
|
||||
The name of a route parameter
|
||||
The name of a route parameter.
|
||||
|
||||
- **returns String value**
|
||||
|
||||
The value that maps to the parameter specified by `key`
|
||||
|
||||
**Object param()**
|
||||
|
||||
- **returns Object params**
|
||||
|
||||
An object containing all the route parameters
|
||||
|
||||
- <a name="buildQueryString"></a>
|
||||
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ var user = {
|
|||
[How to read signatures](how-to-read-signatures.md)
|
||||
|
||||
```clike
|
||||
EventHandler withAttr(String property, void callback(any value))
|
||||
EventHandler withAttr(String property, void callback(any value) [, any callbackThis])
|
||||
|
||||
where:
|
||||
EventHandler :: void handler(Event e)
|
||||
|
|
@ -63,6 +63,10 @@ where:
|
|||
|
||||
This is the value of the defined DOM element's property.
|
||||
|
||||
- **any callbackThis**
|
||||
|
||||
The object which the `this` keyword points to for the callback
|
||||
|
||||
- **returns EventHandler handler**
|
||||
|
||||
This handler method can be assigned to properties like `onclick`, or passed as callbacks to `addEventListener`.
|
||||
|
|
@ -14,7 +14,7 @@ Mithril provides utilities to handle three different aspect of routing:
|
|||
|
||||
### Defining routes
|
||||
|
||||
To define a list of routes, you need to specify a host DOM element, a default route and a key-value map of possible routes and respective [modules](mithril.mount.md) to be rendered. Note: `module` was renamed to `mount`. Documentation will be updated soon.
|
||||
To define a list of routes, you need to specify a host DOM element, a default route and a key-value map of possible routes and respective [modules](mithril.mount.md) to be rendered.
|
||||
|
||||
The example below defines three routes, to be rendered in `<body>`. `home`, `login` and `dashboard` are modules. We'll see how to define a module in a bit.
|
||||
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ In the example below, we bind an error getter-setter to our previous controller
|
|||
//controller
|
||||
var controller = function() {
|
||||
this.error = m.prop("")
|
||||
|
||||
|
||||
this.users = User.listEven().then(function(users) {
|
||||
if (users.length == 0) m.route("/add");
|
||||
}, this.error)
|
||||
|
|
@ -121,7 +121,7 @@ If the controller doesn't already have a success callback to run after a request
|
|||
//controller
|
||||
var controller = function() {
|
||||
this.error = m.prop("")
|
||||
|
||||
|
||||
this.users = User.listEven().then(null, this.error)
|
||||
}
|
||||
```
|
||||
|
|
@ -145,7 +145,7 @@ var users = m.request({method: "GET", url: "/user"})
|
|||
//add one more user to the response
|
||||
return users.concat({name: "Jane"})
|
||||
})
|
||||
|
||||
|
||||
function log(value) {
|
||||
console.log(value)
|
||||
return value
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue