Skip to content

Commit

Permalink
Convert require statements to import statements
Browse files Browse the repository at this point in the history
This is currently a non-working version of the App class because
the SEOAssessor and Presenter are objects instead of the correct
class. However, this commit eliminates all possibilities of require
statements in our base file being the culprit of the out of memory
errors.
  • Loading branch information
Kingdutch committed Oct 22, 2018
1 parent e95bee7 commit 28b3020
Show file tree
Hide file tree
Showing 2 changed files with 538 additions and 18 deletions.
38 changes: 20 additions & 18 deletions lib/app.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
const yoast = require('yoastseo');
import {
ContentAssessor,
Paper,
Pluggable,
Researcher,
string,
} from 'yoastseo';

const defaultsDeep = require( "lodash/defaultsDeep" );
const isObject = require( "lodash/isObject" );
const isString = require( "lodash/isString" );
const isUndefined = require( "lodash/isUndefined" );
const isEmpty = require( "lodash/isEmpty" );
const forEach = require( "lodash/forEach" );
// TODO: Either depend on lodash or don't use this.
import _ from 'lodash';

const ContentAssessor = yoast.ContentAssessor;
const Paper = yoast.Paper;
const Pluggable = yoast.Pluggable;
const Researcher = yoast.Researcher;
const SEOAssessor = yoast.SEOAssessor;
const defaultsDeep = _.defaultsDeep;
const isObject = _.isObject;
const isUndefined = _.isUndefined;

// Import the following 'private' classes
const CornerstoneSEOAssessor = require( "yoastseo/js/cornerstone/seoAssessor.js" );
const CornerstoneContentAssessor = require( "yoastseo/js/cornerstone/contentAssessor.js" );
const AssessorPresenter = require( "yoastseo/js/renderers/AssessorPresenter.js" );
// TODO: This should probably be public: https://github.com/Yoast/YoastSEO.js/issues/1878
// const SEOAssessor = require( "yoastseo/js/seoAssessor.js");
const SEOAssessor = {};
// TODO: We should replace this with our own presenter.
// const AssessorPresenter = require( "yoastseo/js/renderers/AssessorPresenter.js" );
const AssessorPresenter = {};

const removeHtmlBlocks = require( "yoastseo/js/stringProcessing/htmlParser.js" );
const removeHtmlBlocks = string.removeHtmlBlocks;

/**
* Default config for Real Time SEO
Expand Down Expand Up @@ -54,6 +57,7 @@ function verifyArguments( args ) {
}

// TODO: Add TitleWidth as required data for getData callback or implement calculator
// there is a textWidth calculator in the YoastSEO library.

/**
* This should return an object with the given properties
Expand Down Expand Up @@ -197,7 +201,6 @@ App.prototype.initializeSEOAssessor = function( args ) {
}

this.defaultSeoAssessor = new SEOAssessor( this.i18n, { marker: this.config.marker } );
this.cornerStoneSeoAssessor = new CornerstoneSEOAssessor( this.i18n, { marker: this.config.marker } );

// Set the assessor
if ( isUndefined( args.seoAssessor ) ) {
Expand All @@ -219,7 +222,6 @@ App.prototype.initializeContentAssessor = function( args ) {
}

this.defaultContentAssessor = new ContentAssessor( this.i18n, { marker: this.config.marker, locale: this.config.locale } );
this.cornerStoneContentAssessor = new CornerstoneContentAssessor( this.i18n, { marker: this.config.marker, locale: this.config.locale } );

// Set the content assessor
if ( isUndefined( args.contentAssessor ) ) {
Expand Down
Loading

0 comments on commit 28b3020

Please sign in to comment.