dynamic react router

This commit is contained in:
Eric Hulburd
2016-02-29 18:20:00 -06:00
parent 51eaa19a92
commit c890132f2b
44 changed files with 1163 additions and 733 deletions

View File

@@ -1,5 +1,6 @@
import Styles from 'config/styles';
import Templates from 'config/templates';
import {hashHistory} from 'react-router';
import app from './../../app';
Promise.all([
@@ -7,5 +8,5 @@ Promise.all([
Styles.sync()
]).then(()=>{
jQuery('#compiling_layouts').remove();
app();
app(hashHistory);
});

View File

@@ -11,11 +11,6 @@ const TEMPLATE_ROUTES = Object.freeze({
power: 'dashboard/power/power.rt'
});
const COMPONENTS = {
Power: Power,
Energy: Energy
};
var TEMPLATES = {};
class Templates {
@@ -40,16 +35,14 @@ class Templates {
url: TEMPLATE_ROUTES[view]
}).done((template)=>{
var code = rt.convertTemplateToReact(template, {modules: 'none', name: view}),
context = {};
code = code.replace('var '+view+' = ', 'context.'+view+' = ');
eval_context = {};
code = code.replace('var ' + view + ' = ', 'eval_context.' + view + ' = ');
new Function('with(this){ ' + code + ' } ').call({
Energy: Energy,
Power: Power,
context: context,
eval_context: eval_context,
'_': _,
'React': React
});
TEMPLATES[view] = context[view];
TEMPLATES[view] = eval_context[view];
fnResolve();
});
}

View File

@@ -1,3 +1,4 @@
import {browserHistory} from 'react-router';
import app from './../../app';
app();
app(browserHistory);

View File

@@ -1,15 +1,29 @@
// All react templates should be pre-compiled for development.
// run 'gulp compile_react_templates'
import fs from 'fs';
import aboutRt from './../../dashboard/about/about.rt.js';
import houseRt from './../../dashboard/house/house.rt.js';
import layoutRt from './../../dashboard/layout/layout.rt.js';
import energyRt from './../../dashboard/energy/energy.rt.js';
import energyGraphRt from './../../dashboard/energy/graph/graph.rt.js';
import energyTableRt from './../../dashboard/energy/table/table.rt.js';
import powerRt from './../../dashboard/power/power.rt.js';
import powerGraphRt from './../../dashboard/power/graph/graph.rt.js';
import powerTableRt from './../../dashboard/power/table/table.rt.js';
const TEMPLATES = Object.freeze({
const TEMPLATES = {
about: aboutRt,
house: houseRt,
layout: layoutRt,
energy: energyRt,
energy_graph: energyGraphRt,
energy_table: energyTableRt,
power: powerRt,
});
power_graph: powerGraphRt,
power_table: powerTableRt
};
class Templates {