Skip to content

Commit

Permalink
#35 multiple roots allowed
Browse files Browse the repository at this point in the history
  • Loading branch information
L3P3 committed Jul 3, 2021
1 parent d1c6143 commit 9125de7
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 27 deletions.
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,28 +55,28 @@ Normally, lui controls the entire page. But it is also possible to dynamically l

```js
require.config({
map: {
'*': {
'lui': 'https://cdn.jsdelivr.net/gh/L3P3/lui@dist/lui.r.js'
}
}
map: {
'*': {
'lui': 'https://cdn.jsdelivr.net/gh/L3P3/lui@dist/lui.r.js'
}
}
});
```

Use `lui.r.dev.js` when developing. And here is your widget's file:

```js
define(['lui'], function(lui) {
return function(root) {
lui.init(function() {
return [
null,
[
lui.node_dom('h1[innerText=Moin!]')
]
];
}, root);
};
return function(root) {
lui.init(function() {
return [
null,
[
lui.node_dom('h1[innerText=Moin!]')
]
];
}, root);
};
});
```

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lui",
"version": "1.1.0",
"version": "1.1.1",
"description": "web framework",
"homepage": "https://l3p3.de/dok/lui.html",
"repository": {
Expand Down
26 changes: 15 additions & 11 deletions src/lui.js
Original file line number Diff line number Diff line change
Expand Up @@ -2018,18 +2018,22 @@ export const init = (root, dom_c) => {
VERBOSE && log('init');

DEBUG && (
(
current ||
render_queue.length ||
render_queue_next.length
) &&
error('init called more than once'),
RJS
? (
dom_c ||
error('no root element specified'),
dom_c.lui &&
error('root element already mounted'),
dom_c.lui = true_
)
: (
current ||
render_queue.length ||
render_queue_next.length
) &&
error('init called more than once'),
typeof root !== 'function' &&
error('init function requires root component'),
RJS && (
dom_c ||
error('root element must be specified')
)
error('no init function specified')
);

let result;//[props, childs]
Expand Down
35 changes: 35 additions & 0 deletions test/rjs/rjs.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!doctype html>
<html>
<head>
<title>LUI+RequireJS</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js"></script>
<script>
require.config({
map: {
'*': {
'lui': '/dist/lui.r.dev.js'
}
}
});
</script>
</head>
<body>
<h1>Eine Testseite</h1>

<div id="widget1"></div>
<script>
require(['widget-uhr.js'], function(mount) {
mount(document.getElementById('widget1'));
});
</script>

<p>Und hier nochmal:</p>

<div id="widget2"></div>
<script>
require(['widget-uhr.js'], function(mount) {
mount(document.getElementById('widget2'));
});
</script>
</body>
</html>
21 changes: 21 additions & 0 deletions test/rjs/widget-uhr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
define(['lui'], function(lui) {
function Uhr() {
lui.hook_rerender();
lui.hook_dom('p', {
innerText: lui.now()
});
return null;
}

return function(root) {
lui.init(function() {
return [{
S: {
background: 'lime'
}
}, [
lui.node(Uhr)
]];
}, root);
};
});

0 comments on commit 9125de7

Please sign in to comment.