<commit_before>"use strict"

let Backbone = require('backbone');

let React    = require('react');
let ReactDom = require('react-dom');

let userRoutes = {};
let userRoutesList = require("./../wiring/routes");

let req = require.context("./../.views", true, /\.js$/);

for (let route in userRoutesList) {
  //console.log("./"+userRoutesList[route]+".js");
  if (userRoutesList.hasOwnProperty(route)
  && "string" === typeof userRoutesList[route]) {
    userRoutes[route] = req("./"+userRoutesList[route]+".js");
  }
}

let Actions    = require('./../wiring/actions');

module.exports = function(UnderlyingChange,clientSideLiveData, dispatcher, modelHelpers){

//++++++++++++++++++++++++++++++++ Initiate the router
//++++++++++++++++++++++++++++++++++++++++++++++++++++
    let routes = { }
      
    for (let routeName in userRoutes){
      
      
      if( ! userRoutes.hasOwnProperty(routeName)){
        continue; // if the property is not on the routes object skip to the next one
      }
      
      //urlPattern[routeName] = RoutePattern.fromString(routeName);
      
      let routeNameS = [routeName];
      
      let charCount = routeName.length;
      
      //get the last char from routeName String
      if (routeName[charCount -1] !== "/"
      && undefined === routeName[routeName + "/"]) {
        //check if a route with a '/' is definded
        routeNameS.push(routeName + "/")
      } else if(undefined === routeName.substr(charCount - 2)){
        routeNameS.push(routeName.substr(charCount - 2))
      }
      
      routeNameS.forEach(function(routePattern){
        routes[routePattern] = load.bind( null, userRoutes[routeName],routePattern )
      }); // END for routeNameS
      
    } // END for userRoutes
    

    
    // let lastPageArgs;
    
    // Execution sequence of a React component’s lifecycle methods << Good to know ;)
    // http://javascript.tutorialhorizon.com/2014/09/13/execution-sequence-of-a-react-components-lifecycle-methods/
    
    let Content = React.createClass({
        displayName: 'Body Content',
        getInitialState : function(){
          UnderlyingChange.on(this.reload);
          return { count : 0 }  
        },
        reload : function(type, data, changes){
          this.setState({ count : this.state.count++ });
        },
        componentDidMount : function(){
          UnderlyingChange.on(this.reload);
        },
        componentWillUnmount : function(){
          UnderlyingChange.off(this.reload);
        },
        render: function(){
          
            let dataJson = Object.keys(clientSideLiveData).reduce(function(pojo, collectionName){
     
                  pojo[collectionName] = clientSideLiveData[collectionName].toJSON();
                  return pojo;
              },{});
          
            return React.createElement( this.props.page, React.__spread({AppDB:dataJson}, this.props))
        }
    })
    
//=====================================================
//================================ Page load controller
//=====================================================
    
    function load(pageElemt, routePattern) {
     
//++++++++++++++++++++++++++++++++++ process arguments
//++++++++++++++++++++++++++++++++++++++++++++++++++++
    
        let args = [].slice.call(arguments).slice(2);
       
//+++++++++++++++++++++++++++++++ map args to fragment
//++++++++++++++++++++++++++++++++++++++++++++++++++++

        let quary = args.pop();
        
        if (quary) {
          try{
          quary = JSON.parse('{"' + quary.replace(/&/g, '","').replace(/=/g,'":"') + '"}',
                 function(key, value) { return key===""?value:decodeURIComponent(value) });
          } catch (err){
            console.error("Error in parsing URL quary. Check all keys has a vaule",quary);
            quary =  {};<commit_msg>URL quary passed to page now supports empty values. e.g. ?user&name=max >> user = null ?user=&namemax >> user = ""<commit_after>"use strict"

let Backbone = require('backbone');

let React    = require('react');
let ReactDom = require('react-dom');

let userRoutes = {};
let userRoutesList = require("./../wiring/routes");

let req = require.context("./../.views", true, /\.js$/);

for (let route in userRoutesList) {
  //console.log("./"+userRoutesList[route]+".js");
  if (userRoutesList.hasOwnProperty(route)
  && "string" === typeof userRoutesList[route]) {
    userRoutes[route] = req("./"+userRoutesList[route]+".js");
  }
}

let Actions    = require('./../wiring/actions');

module.exports = function(UnderlyingChange,clientSideLiveData, dispatcher, modelHelpers){

//++++++++++++++++++++++++++++++++ Initiate the router
//++++++++++++++++++++++++++++++++++++++++++++++++++++
    let routes = { }
      
    for (let routeName in userRoutes){
      
      
      if( ! userRoutes.hasOwnProperty(routeName)){
        continue; // if the property is not on the routes object skip to the next one
      }
      
      //urlPattern[routeName] = RoutePattern.fromString(routeName);
      
      let routeNameS = [routeName];
      
      let charCount = routeName.length;
      
      //get the last char from routeName String
      if (routeName[charCount -1] !== "/"
      && undefined === routeName[routeName + "/"]) {
        //check if a route with a '/' is definded
        routeNameS.push(routeName + "/")
      } else if(undefined === routeName.substr(charCount - 2)){
        routeNameS.push(routeName.substr(charCount - 2))
      }
      
      routeNameS.forEach(function(routePattern){
        routes[routePattern] = load.bind(null, userRoutes[routeName],routePattern )
      }); // END for routeNameS
      
    } // END for userRoutes
    

    
    // let lastPageArgs;
    
    // Execution sequence of a React component’s lifecycle methods << Good to know ;)
    // http://javascript.tutorialhorizon.com/2014/09/13/execution-sequence-of-a-react-components-lifecycle-methods/
    
    let Content = React.createClass({
        displayName: 'Body Content',
        getInitialState : function(){
          UnderlyingChange.on(this.reload);
          return { count : 0 }  
        },
        reload : function(type, data, changes){
          this.setState({ count : this.state.count++ });
        },
        componentDidMount : function(){
          UnderlyingChange.on(this.reload);
        },
        componentWillUnmount : function(){
          UnderlyingChange.off(this.reload);
        },
        render: function(){
          
            let dataJson = Object.keys(clientSideLiveData).reduce(function(pojo, collectionName){
     
                  pojo[collectionName] = clientSideLiveData[collectionName].toJSON();
                  return pojo;
              },{});
          
            return React.createElement( this.props.page, React.__spread({AppDB:dataJson}, this.props))
        }
    })
    
//=====================================================
//================================ Page load controller
//=====================================================
    
    function load(pageElemt, routePattern) {
     
//++++++++++++++++++++++++++++++++++ process arguments
//++++++++++++++++++++++++++++++++++++++++++++++++++++
    
        let args = [].slice.call(arguments).slice(2);
       
//+++++++++++++++++++++++++++++++ map args to fragment
//++++++++++++++++++++++++++++++++++++++++++++++++++++

        let quary = args.pop();
        
        if (quary) {
          try{
         
          // fix missing values
          quary = quary.split("&").reduce((items,quaryItem)=>{
            
            let key_value = quaryItem.split("=");
            
            // no value set to null
            items[decodeURIComponent(key_value[0])] =
              (1 === key_value.length) ? null : decodeURIComponent(key_value[1]);
            
            // cast to boolean
            
            // cast to int
            
            // cast to float
                                                                             
            return items;
            },{});
            
          } catch (err){
            console.error(err);
            quary =  {};
{'fraction_non_alphanumeric': 0.22021837811311495, 'fraction_numerical': 0.003557845663108821, 'mean_word_length': 2.3192182410423454, 'pattern_counts': {'":': 1, '<': 7, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5733963', 'n_tokens_mistral': 2267, 'n_tokens_neox': 2161, 'n_words': 447}