mirror of
				https://github.com/Alamantus/Lexiconga.git
				synced 2025-11-04 10:17:01 +01:00 
			
		
		
		
	Remove lazyload-inferno-component now that I know how Webpack's import() works
				
					
				
			This commit is contained in:
		
							parent
							
								
									f02bec30e6
								
							
						
					
					
						commit
						f296dacdad
					
				
					 2 changed files with 2 additions and 61 deletions
				
			
		| 
						 | 
				
			
			@ -3,20 +3,11 @@ import { Component } from 'inferno';
 | 
			
		|||
import PropTypes from 'prop-types';
 | 
			
		||||
import marked from 'marked';
 | 
			
		||||
 | 
			
		||||
// npm lazyload-inferno-component uses outdated inferno dependencies, so just using the script.
 | 
			
		||||
import LazyLoader from '../../../vendor/LGabAnnell/lazyload-inferno-component/lazyload-component';
 | 
			
		||||
 | 
			
		||||
import idManager from '../../managers/IDManager';
 | 
			
		||||
 | 
			
		||||
import { Ad } from './Ad';
 | 
			
		||||
import { WordDisplay } from './WordDisplay';
 | 
			
		||||
 | 
			
		||||
const loadAd = (callback, { props, router }) => {
 | 
			
		||||
  require.ensure([], (require) => {
 | 
			
		||||
    const component = require("./Ad").Ad;
 | 
			
		||||
    callback(component);
 | 
			
		||||
  });
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export class WordsList extends Component {
 | 
			
		||||
  constructor (props) {
 | 
			
		||||
    super(props);
 | 
			
		||||
| 
						 | 
				
			
			@ -39,7 +30,7 @@ export class WordsList extends Component {
 | 
			
		|||
            return (
 | 
			
		||||
              <div key={ `word_${word.id}` }>
 | 
			
		||||
                {index % adsEveryXWords == 1
 | 
			
		||||
                  && <LazyLoader key={ index } lazyLoad={ loadAd } />
 | 
			
		||||
                  && <Ad key={ index } />
 | 
			
		||||
                }
 | 
			
		||||
                
 | 
			
		||||
                <WordDisplay word={ word }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,50 +0,0 @@
 | 
			
		|||
import { createElement } from "inferno-create-element";
 | 
			
		||||
import { Component } from "inferno";
 | 
			
		||||
 | 
			
		||||
/** @internal 
 | 
			
		||||
	* Function pretty much copied from infernojs - Route.ts
 | 
			
		||||
  */
 | 
			
		||||
function rest(object, excluded) {
 | 
			
		||||
  const t = {};
 | 
			
		||||
  for (let p in object) {
 | 
			
		||||
    if (excluded.indexOf(p) < 0) {
 | 
			
		||||
      t[p] = object[p];
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  return t;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export default class LazyLoader extends Component {
 | 
			
		||||
 | 
			
		||||
  constructor(props, context) {
 | 
			
		||||
    super(props, context);
 | 
			
		||||
    this.state = {
 | 
			
		||||
      child: null
 | 
			
		||||
    };
 | 
			
		||||
    this.context = context;
 | 
			
		||||
    this.lazyLoad = props.lazyLoad;
 | 
			
		||||
    this.children = props.children;
 | 
			
		||||
    this.loadComponent = this.loadComponent.bind(this);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  loadComponent(componentName, props) {
 | 
			
		||||
    let finalProps;
 | 
			
		||||
    if (!props) {
 | 
			
		||||
      finalProps = rest(this.props, ["lazyLoad", "children"]);
 | 
			
		||||
    } else {
 | 
			
		||||
      finalProps = Object.assign({}, props, rest(this.props, ["lazyLoad", "children"]));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    this.setState({
 | 
			
		||||
      child: createElement(componentName, finalProps, this.children)
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  componentWillMount() {
 | 
			
		||||
    this.lazyLoad(this.loadComponent, {props: this.props, router: this.context.router});
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  render() {
 | 
			
		||||
    return this.state.child ? this.state.child : null;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	Add table
		
		Reference in a new issue