Skip to content

Commit 71b9d53

Browse files
committed
Added the Iterator pattern for demo purposes
1 parent 67e2dc4 commit 71b9d53

File tree

1 file changed

+41
-40
lines changed

1 file changed

+41
-40
lines changed

src/index.js

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import styled from 'styled-components';
44

55
import { Light as SyntaxHighlighter } from 'react-syntax-highlighter';
66
import js from 'react-syntax-highlighter/dist/languages/hljs/javascript';
7-
import railscasts from 'react-syntax-highlighter/dist/styles/hljs/railscasts';
7+
import style from 'react-syntax-highlighter/dist/styles/hljs/atom-one-dark';
88

99
SyntaxHighlighter.registerLanguage('javascript', js);
1010

@@ -18,55 +18,56 @@ const Title = styled.h1`
1818
margin: 0;
1919
`;
2020

21-
const codeString = `
22-
module.exports = {
23-
devtool: 'inline-source-map',
24-
entry: './src/index.js',
25-
output: {
26-
path: path.join(__dirname, '/build'),
27-
publicPath: '/',
28-
filename: 'bundle.js'
29-
},
30-
optimization: {
31-
splitChunks: {
32-
chunks: 'all'
33-
}
34-
},
35-
devServer: {
36-
contentBase: './build'
37-
},
38-
module: {
39-
rules: [
40-
{
41-
test: /\.(js|jsx)$/,
42-
exclude: /node_modules/,
43-
use: ['babel-loader', 'eslint-loader']
44-
}
45-
]
21+
const codeES6 = `
22+
class Pattern {
23+
constructor(el) {
24+
this.index = 0;
25+
this.elements = el;
26+
}
27+
28+
next() {
29+
return this.elements[this.index++];
30+
}
31+
32+
hasNext() {
33+
return this.index < this.elements.length;
34+
}
35+
}
36+
37+
export default Pattern;
38+
39+
`;
40+
41+
const code = `
42+
function Pattern(el) {
43+
this.index = 0;
44+
this.elements = el;
45+
}
46+
47+
Pattern.prototype = {
48+
next: function() {
49+
return this.elements[this.index++];
4650
},
47-
plugins: [
48-
new HtmlWebpackPlugin({
49-
template: path.resolve('./index.html')
50-
}),
51-
new BundleAnalyzerPlugin({
52-
analyzerMode: 'disabled',
53-
generateStatsFile: true,
54-
statsOptions: { source: false },
55-
statsFilename: path.join(__dirname, 'stats/stats.json')
56-
})
57-
],
58-
performance: { hints: false }
51+
hasNext: function() {
52+
return this.index < this.elements.length;
53+
}
5954
};
6055
56+
module.exports = Pattern;
57+
6158
`;
6259

6360
class Welcome extends React.Component {
6461
render() {
6562
return (
6663
<React.Fragment>
6764
<Title>JavaScript</Title>
68-
<SyntaxHighlighter language="javascript" style={railscasts} customStyle={{ fontSize: '1.25rem' }}>
69-
{codeString}
65+
<SyntaxHighlighter language="javascript" style={style} customStyle={{ fontSize: '1.25rem' }}>
66+
{code}
67+
</SyntaxHighlighter>
68+
ES6
69+
<SyntaxHighlighter language="javascript" style={style} customStyle={{ fontSize: '1.25rem' }}>
70+
{codeES6}
7071
</SyntaxHighlighter>
7172
</React.Fragment>
7273
);

0 commit comments

Comments
 (0)