document component shorthand syntax
This commit is contained in:
parent
2b24c7a64d
commit
ed3f3f0686
4 changed files with 65 additions and 0 deletions
|
|
@ -12,6 +12,7 @@
|
|||
- [SVG](#svg)
|
||||
- [Dealing with focus](#dealing-with-focus)
|
||||
- [Dealing with sorting and deleting in lists](#dealing-with-sorting-and-deleting-in-lists)
|
||||
- [Component shorthand](#component-shorthand)
|
||||
- [Signature](#signature)
|
||||
- [The `config` attribute](#the-config-attribute)
|
||||
---
|
||||
|
|
@ -464,6 +465,31 @@ You should always use keys if you need to sort lists, remove items from them or
|
|||
|
||||
---
|
||||
|
||||
### Component Shorthand
|
||||
|
||||
If the first argument to `m()` is a component, it acts as an alias of `m.component()`
|
||||
|
||||
```javascript
|
||||
var MyComponent = {
|
||||
controller: function() {
|
||||
return {greeting: "hello"}
|
||||
},
|
||||
view: function(ctrl, args) {
|
||||
return m("h1", ctrl.greeting + " " + args.data)
|
||||
}
|
||||
}
|
||||
|
||||
m.render(document.body, [
|
||||
//the two lines below are equivalent
|
||||
m(component, {data: "world"}),
|
||||
m.component(component, {data: "world"})
|
||||
])
|
||||
```
|
||||
|
||||
See [components](mithril.component.md) for more information.
|
||||
|
||||
---
|
||||
|
||||
### Signature
|
||||
|
||||
[How to read signatures](how-to-read-signatures.md)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue