1
0
mirror of https://github.com/bobwen-dev/react-templates synced 2025-04-12 00:56:39 +02:00

add docs for rt-virtual

This commit is contained in:
Omer Ganim 2016-05-01 13:27:21 +03:00
parent 44d91b4149
commit 45af9f0eca

View File

@ -148,6 +148,46 @@ define([
});
```
## rt-virtual
This directive creates as a virtual node, which will not be rendered to the DOM, but can still be used as a root for directives, e.g. `rt-if` and `rt-repeat`.
###### Sample:
For instance, to repeat several nodes at once without a shared root for each instance:
```html
<ul>
<rt-virtual rt-repeat="n in [1,2,3]">
<li>{n}</li>
<li>{n*2}</li>
</virtual>
</ul>
```
##### Compiled:
```javascript
define([
'react/addons',
'lodash'
], function (React, _) {
'use strict';
function repeatN1(n, nIndex) {
return [
React.createElement('li', {}, n),
React.createElement('li', {}, n * 2)
];
}
return function () {
return React.createElement.apply(this, [
'ul',
{},
_.map([
1,
2,
3
], repeatN1.bind(this))
]);
};
});
```
## rt-scope
This directive creates a new JavaScript scope by creating a new method and invoking it with its current context. The syntax is `rt-scope="expr1 as var1; expr2 as var2`.
This allows for a convenient shorthand to make the code more readable. It also helps to execute an expression only once per scope.