Skip to content

Commit b6454b7

Browse files
author
Noam Elboim
committed
chaging default rootElement to be a new element
1 parent 149b382 commit b6454b7

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ UiZoo.init(documentation: Object, components: Object, rootElement: HTMLElement?,
6161

6262
**components** - Object, mapping of components name to components. See [example](https://github.com/myheritage/uizoo.js/blob/master/client/components.js).
6363

64-
**rootElement** - HTMLElement, will bootstrap UiZoo on that Element. Default is an element with the id 'library-_-root'
64+
**rootElement** - HTMLElement, will bootstrap UiZoo on that Element. Default is a new element on the body.
6565

6666
**baseRoute** Route to be the base before the UiZoo routes. Default to '/'. for example if the UiZoo is on your site like so: 'www.mysite.com/my/zoo/', the base route should be '/my/zoo/'.
6767

@@ -119,7 +119,7 @@ To add tests, use the following steps -
119119

120120
First, make sure the app is up and running:
121121
```
122-
gulp
122+
npm start
123123
```
124124
The first time tests are run, install the npm dependencies:
125125
```

client/index.js

+9-7
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,22 @@ import mapComponentsByModule from './services/componentByModuleMapper';
1414

1515
window._extend = _.extend; // to be used instead of Object.assign
1616

17-
const defaultRoot = document.getElementById('library-_-root');
18-
1917
/**
20-
* Init
21-
* @param {Object} documentation
22-
* @param {Object} components
23-
* @param {HTMLElement} rootElement
18+
* Init - render UiZoo with documentation and components mappings
19+
* @param {Object} [documentation]
20+
* @param {Object} [components]
21+
* @param {HTMLElement} [rootElement] will default to a new element on the body
2422
*/
2523
function init(
2624
documentation = libraryDocs,
2725
components = libraryData,
28-
rootElement = defaultRoot,
26+
rootElement,
2927
baseRoute = '/'
3028
) {
29+
if (!rootElement) {
30+
rootElement = document.createElement('div');
31+
document.body.appendChild(rootElement);
32+
}
3133
checkDependencies(documentation, components);
3234

3335
const compiler = createCompiler(components); // JSX compiler

index.html

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
<link rel="stylesheet" href="/dist/index.css">
99
</head>
1010
<body>
11-
<div id="library-_-root"></div>
1211
<script src="/node_modules/underscore/underscore-min.js"></script>
1312
<script src="/node_modules/react/umd/react.production.min.js"></script>
1413
<script src="/node_modules/react-dom/umd/react-dom.production.min.js"></script>

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"build:iife": "./node_modules/.bin/rollup -c rollup.config.js -o dist/index.js -f iife -n UiZoo",
99
"build:cjs": "./node_modules/.bin/rollup -c rollup.config.js -o dist/index.cjs.js -f cjs -n UiZoo",
1010
"build:es": "./node_modules/.bin/rollup -c rollup.config.js -o dist/index.es.js -f es -n UiZoo",
11-
"gulp:w": "gulp",
11+
"gulp:w": "./node_modules/.bin/gulp",
1212
"test": "npm start & SERVER_PID=$!; (cd tests; npm i && node run-tests.js); kill $SERVER_PID"
1313
},
1414
"main": "dist/index.cjs.js",

0 commit comments

Comments
 (0)