Merge pull request #5 from Bouncey/fix/rxHelpers

Fix/rx helpers
This commit is contained in:
Stuart Taylor
2018-04-09 00:11:35 +01:00
committed by Mrugesh Mohapatra
parent b546d8ed92
commit 93debd8892
4 changed files with 41 additions and 19 deletions

View File

@ -83,8 +83,26 @@ exports.createPages = ({ graphql, boundActionCreators }) => {
});
};
exports.modifyWebpackConfig = ({ config, stage, babelConfig }) => {
if (stage === 'build-javascript' || stage === 'develop') {
const generateBabelConfig = require('gatsby/dist/utils/babel-config');
exports.modifyWebpackConfig = ({ config, stage }) => {
const program = {
directory: __dirname,
browserslist: ['> 1%', 'last 2 versions', 'IE >= 9']
};
return generateBabelConfig(program, stage).then(babelConfig => {
config.removeLoader('js').loader('js', {
test: /\.jsx?$/,
exclude: modulePath => {
return (
/node_modules/.test(modulePath) &&
!(/node_modules\/(ansi-styles|chalk)/).test(modulePath)
);
},
loader: 'babel',
query: babelConfig
});
config.plugin('CopyWebpackPlugin', CopyWebpackPlugin, [
[
{
@ -93,16 +111,5 @@ exports.modifyWebpackConfig = ({ config, stage, babelConfig }) => {
}
]
]);
// remove the default 'js' loader so we can create our own
config.removeLoader('js');
// these modules are shipped with es6 code, we need to transform them due
// to the version of the uglifyjs plugin gatsby is using
config.loader('js', {
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)\/(?!ansi-styles|chalk)/,
loader: 'babel',
query: babelConfig
});
}
return config;
});
};

View File

@ -16,3 +16,12 @@ exports.replaceRenderer = ({
);
replaceBodyHTMLString(renderToString(<ConnectedBody />));
};
exports.onRenderBody = ({ setPostBodyComponents }) =>
setPostBodyComponents([
<script
async='true'
key='chai-CDN'
src='https://cdnjs.cloudflare.com/ajax/libs/chai/4.1.2/chai.min.js'
/>
]);

View File

@ -2,12 +2,18 @@ document.addEventListener('DOMContentLoaded', function() {
var testTimeout = 5000;
var Rx = document.Rx;
var frameReady = document.__frameReady;
var helpers = Rx.helpers;
var chai = require('chai');
var chai = parent.chai;
var source = document.__source;
var __getUserInput = document.__getUserInput || (x => x);
var checkChallengePayload = document.__checkChallengePayload;
function isPromise(value) {
return (
value &&
typeof value.subscribe !== 'function' &&
typeof value.then === 'function'
);
}
// Fake Deep Equal dependency
/* eslint-disable no-unused-vars */
const DeepEqual = (a, b) => JSON.stringify(a) === JSON.stringify(b);
@ -105,7 +111,7 @@ document.addEventListener('DOMContentLoaded', function() {
// sync tests can return Any type
__result = test(getUserInput);
if (helpers.isPromise(__result)) {
if (isPromise(__result)) {
// turn promise into an observable
__result = Rx.Observable.fromPromise(__result);
}

View File

@ -17,7 +17,7 @@
*/
import debugFactory from 'debug';
import { Observable, helpers } from 'rxjs';
import { Observable, noop } from 'rxjs';
const debug = debugFactory('fcc:ajax$');
const root = typeof window !== 'undefined' ? window : {};
@ -42,7 +42,7 @@ function getXMLHttpRequest() {
}
} catch (e) {
// purposely do nothing
helpers.noop(e);
noop.noop(e);
}
}
return new root.ActiveXObject(progId);