1 | 'use strict';
|
2 |
|
3 | var React = require( 'react' );
|
4 | var ReactDOM = require( 'react-dom' );
|
5 | var _ = require( 'lodash' );
|
6 | var Provider = require( 'react-redux' ).Provider;
|
7 |
|
8 |
|
9 | module.exports = function( pageComponents, templateComponents, store, useRedux ){
|
10 |
|
11 |
|
12 | |
13 |
|
14 |
|
15 |
|
16 | pageComponents.components.forEach( ( component, number, componentArry ) => {
|
17 |
|
18 | |
19 |
|
20 |
|
21 |
|
22 |
|
23 | if( templateComponents[ component.name ] ){
|
24 | initilizeComponents( templateComponents[ component.name ], component, store, useRedux );
|
25 | }
|
26 |
|
27 | } );
|
28 |
|
29 | };
|
30 |
|
31 | function initilizeComponents( templateComponent, pageComponent, store, useRedux ){
|
32 |
|
33 | pageComponent.instances.forEach( ( component, number, componentArry ) => {
|
34 |
|
35 | |
36 |
|
37 |
|
38 | if( templateComponent.hasOwnProperty( 'init' ) ){
|
39 |
|
40 | if( useRedux ) {
|
41 | templateComponent.init( component.config, component.data, store );
|
42 | } else{
|
43 | templateComponent.init( component.config, component.data );
|
44 | }
|
45 |
|
46 | }
|
47 |
|
48 | |
49 |
|
50 |
|
51 | if( templateComponent.hasOwnProperty( 'component' ) ){
|
52 |
|
53 | if( useRedux ){
|
54 | |
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 | let elementToBindTo = document.querySelector('[data-hook="' + component.config.hook + '"]');
|
61 |
|
62 | if( elementToBindTo ){
|
63 | ReactDOM.render(
|
64 | <Provider store={store}>
|
65 | <templateComponent.component data={component.config}/>
|
66 | </Provider>,
|
67 | elementToBindTo
|
68 | );
|
69 | }
|
70 | } else {
|
71 |
|
72 | |
73 |
|
74 |
|
75 |
|
76 | let elementToBindTo = document.querySelector('[data-hook="' + component.config.hook + '"]');
|
77 |
|
78 | if( elementToBindTo ){
|
79 | ReactDOM.render(
|
80 | <templateComponent.component data={component.config}/>,
|
81 | document.querySelector('[data-hook="' + component.config.hook + '"]')
|
82 | );
|
83 | }
|
84 |
|
85 | }
|
86 |
|
87 |
|
88 | }
|
89 |
|
90 | } );
|
91 |
|
92 | }
|