freeCodeCamp/seed/challenges/03-front-end-libraries/react-and-redux.json

761 lines
61 KiB
JSON
Raw Normal View History

2017-01-17 04:44:38 +00:00
{
"name": "React and Redux",
"order": 7,
"time": "5 hours",
"helpRoom": "Help",
Feat: react redux migration (#16200) * feat: crudely enables test to run solution code against React challenge (and passes!) * feat: Updates comment * feat: Adds React 2 and 3, validates challenges in app * feat: Adds React 4, validates tests * feat: Adds Peter's migrated challenge seed files for all challenges * feat: Adds redux, react-redux imports, adds tests for React 7, * feat: Adds tests for React 08 * fix(challenges): wrap reserved words in <code> and add tests * feat: complete first two tests for React 9 * feat: modifies tests in React 09 * feat: Adds working tests for React 37, including async setState tests * feat: Escape hatch to avoid async tests in automated test suite * feat: Updates React 15 with working tests * feat: build passes, yay * feat: Provisions original code string in challenges and adds tests for React Redux 01 * fix(tests): add self-closing tags challenge, other small fixes * fix(challenge): add react_10, some other stuff * fix(challenges): update react 22, add react 23 * fix(challenges): react 5 and react 8 * feat: removes dependencies that will break in browser, will replace later * feat: fix build * feat: add redux 1 * fix(challenge): add react 24 tests * feat: partial implemented Redux 2 * feat: migrate redux 3 * feat: Adds React-Redux 04 with working tests under npm test * feat: Updates automated test runner, just provide all the dependencies. Adds Redux-Thunk. * feat: Adds working tests for React Redux 07 * feat: redux challenge 4 * feat: migrate redux 5 * feat: redux 6 * feat: migrate Redux test 7 * fix(challenge): add react 25 tests * feat: Adds tests for React 48, npm test does not pass... * feat: Migrate Redux test 8 * fix(challenges): skip 26, add react 27 tests * fix(challenges): add react 28 tests, replace function w/ => throughout, fix linter warnings * feat: fixes (patches) hard to understand problem with automated test suite * feat: updates async tests patch * feat: adds converted tests for React 47 * feat: adds converted tests for React 46 * feat: Partially adds tests for React 43 * docs: adds TO-DO tests for React 43 * feat: migrates tests for React 42 * feat: migrates tests for React 41 * feat: migrates tests for React 39 * feat: Migrates tests for React 38, automated test script fails again! * feat: migrates tests for React 32 * feat: QAs more React Redux challenge in FCC UI * feat: Updates tests for React 7 * feat: Migrates React-Redux 3 tests and hardcodes deep-freeze dependency * feat: migrates React Redux 05 tests * feat: migrates React Redux 06 tests * feat: Migrates React Redux 10 * feat: Migrates tests for React 16 * feat: Migrates React 17 tests * feat: Migrates React 18 tests * feat: Migrates React 19 tests * feat: Migrates React 19 tests * feat: fixing usage of code, replace with editor.getOriginalCode * feat: Migrates React 21 tests * feat: Finishes migration of React 09 * fix(challenges): add react 45 tests 💀 * feat: Adds React 11 tests * feat: Migrates React 50 tests * feat: Re-enables original code in FCC editor, QAs challenges blocked by original code * feat: hacks head tail code in editor test environment * feat: updates React 20 head code * feat: QAs React Redux 07 in UI * fix(challenges): add React 29 tests * fix(challenges): add React 30 tests * feat: updates async tests * feat: Migrates React 12, gets ReactDOM challenges working and QAs them * feat: Migrates React 13 tests * feat: Migrates tests for React 14 and updates challenge description formatting * feat: Refactors 2nd test for Redux 02 * feat: Migrates React 33 * feat: Removes React 26 and 43 * feat: Adds React 34 from Kevin * fix(challenges): add React 31 & 35 tests (thanks Kevin) * feat: Migrate Redux challenge 10 - pass both UI QA and terminal test * fix(challenge): add react 40 tests * feat: Migrates React Redux 02 tests * feat: Migrates React Redux 08 and fixes async syntax in React challenge * fix(challenge): add react 49 tests with caveat * feat: fixes React 49 tests and adds first tests for React Redux 09 * feat: Migrate Redux 11 - pass both terminal test and UI test * feat: Migrate Redux 12 - passing both UI test and terminal test * feat: Migrate Redux 13 - passing both terminal and UI tests * feat: Adding in code tags for previous redux challenges - terminal and UI tests pass * feat: Migrates React Redux 09 and React 44 (thanks Kevin) * feat: fix code tag issues - passed UI and terminal tests * feat: Migrates Redux 14 tests * feat: Migrates Redux 14 * feat: Migrates Redux 15 * feat: Migrates Redux 17 * feat: Final migration and QA of Redux, except for Redux 9 * feat: migrates React 36 and QAs * feat: Rewrites Redux 09 and migrates * feat: refactors pull request and cleans up code * style(challenges): QA React challenges * style(challenges): QA react challenges * fix(challenges): fix react 41 and 45 tests * style(challenges): QA redux challenges * style(challenges): QA react and redux challenges * fix(seed/react): Move head/tail to files * fix(seed/redux): Move head/tail to file level * chore(packages): Move jsdom to dev deps * fix(seed/react/redux): Async funcs make async func defined * fix(seed): %s/editor.getUserCode/getUserInput/gc * fix(Challenges/build): Make sure head/tail is bundled and transformed * feat(Challenges.react): Add tail to render component * chore(seed): Disable modern challenge testing for now We will put these on beta while we update the auto testing framework
2017-12-18 21:04:03 +00:00
"required": [
{
"src": "https://cdnjs.cloudflare.com/ajax/libs/react/16.1.1/umd/react.development.js"
},
{
"src": "https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.1.1/umd/react-dom.development.js"
},
{
"src": "https://cdnjs.cloudflare.com/ajax/libs/redux/3.7.2/redux.js"
},
{
"src": "https://cdnjs.cloudflare.com/ajax/libs/react-redux/5.0.6/react-redux.js"
}
],
"template": "<body><div id='root'></div>${ source }</body>",
2017-01-17 04:44:38 +00:00
"challenges": [
{
Feat: react redux migration (#16200) * feat: crudely enables test to run solution code against React challenge (and passes!) * feat: Updates comment * feat: Adds React 2 and 3, validates challenges in app * feat: Adds React 4, validates tests * feat: Adds Peter's migrated challenge seed files for all challenges * feat: Adds redux, react-redux imports, adds tests for React 7, * feat: Adds tests for React 08 * fix(challenges): wrap reserved words in <code> and add tests * feat: complete first two tests for React 9 * feat: modifies tests in React 09 * feat: Adds working tests for React 37, including async setState tests * feat: Escape hatch to avoid async tests in automated test suite * feat: Updates React 15 with working tests * feat: build passes, yay * feat: Provisions original code string in challenges and adds tests for React Redux 01 * fix(tests): add self-closing tags challenge, other small fixes * fix(challenge): add react_10, some other stuff * fix(challenges): update react 22, add react 23 * fix(challenges): react 5 and react 8 * feat: removes dependencies that will break in browser, will replace later * feat: fix build * feat: add redux 1 * fix(challenge): add react 24 tests * feat: partial implemented Redux 2 * feat: migrate redux 3 * feat: Adds React-Redux 04 with working tests under npm test * feat: Updates automated test runner, just provide all the dependencies. Adds Redux-Thunk. * feat: Adds working tests for React Redux 07 * feat: redux challenge 4 * feat: migrate redux 5 * feat: redux 6 * feat: migrate Redux test 7 * fix(challenge): add react 25 tests * feat: Adds tests for React 48, npm test does not pass... * feat: Migrate Redux test 8 * fix(challenges): skip 26, add react 27 tests * fix(challenges): add react 28 tests, replace function w/ => throughout, fix linter warnings * feat: fixes (patches) hard to understand problem with automated test suite * feat: updates async tests patch * feat: adds converted tests for React 47 * feat: adds converted tests for React 46 * feat: Partially adds tests for React 43 * docs: adds TO-DO tests for React 43 * feat: migrates tests for React 42 * feat: migrates tests for React 41 * feat: migrates tests for React 39 * feat: Migrates tests for React 38, automated test script fails again! * feat: migrates tests for React 32 * feat: QAs more React Redux challenge in FCC UI * feat: Updates tests for React 7 * feat: Migrates React-Redux 3 tests and hardcodes deep-freeze dependency * feat: migrates React Redux 05 tests * feat: migrates React Redux 06 tests * feat: Migrates React Redux 10 * feat: Migrates tests for React 16 * feat: Migrates React 17 tests * feat: Migrates React 18 tests * feat: Migrates React 19 tests * feat: Migrates React 19 tests * feat: fixing usage of code, replace with editor.getOriginalCode * feat: Migrates React 21 tests * feat: Finishes migration of React 09 * fix(challenges): add react 45 tests 💀 * feat: Adds React 11 tests * feat: Migrates React 50 tests * feat: Re-enables original code in FCC editor, QAs challenges blocked by original code * feat: hacks head tail code in editor test environment * feat: updates React 20 head code * feat: QAs React Redux 07 in UI * fix(challenges): add React 29 tests * fix(challenges): add React 30 tests * feat: updates async tests * feat: Migrates React 12, gets ReactDOM challenges working and QAs them * feat: Migrates React 13 tests * feat: Migrates tests for React 14 and updates challenge description formatting * feat: Refactors 2nd test for Redux 02 * feat: Migrates React 33 * feat: Removes React 26 and 43 * feat: Adds React 34 from Kevin * fix(challenges): add React 31 & 35 tests (thanks Kevin) * feat: Migrate Redux challenge 10 - pass both UI QA and terminal test * fix(challenge): add react 40 tests * feat: Migrates React Redux 02 tests * feat: Migrates React Redux 08 and fixes async syntax in React challenge * fix(challenge): add react 49 tests with caveat * feat: fixes React 49 tests and adds first tests for React Redux 09 * feat: Migrate Redux 11 - pass both terminal test and UI test * feat: Migrate Redux 12 - passing both UI test and terminal test * feat: Migrate Redux 13 - passing both terminal and UI tests * feat: Adding in code tags for previous redux challenges - terminal and UI tests pass * feat: Migrates React Redux 09 and React 44 (thanks Kevin) * feat: fix code tag issues - passed UI and terminal tests * feat: Migrates Redux 14 tests * feat: Migrates Redux 14 * feat: Migrates Redux 15 * feat: Migrates Redux 17 * feat: Final migration and QA of Redux, except for Redux 9 * feat: migrates React 36 and QAs * feat: Rewrites Redux 09 and migrates * feat: refactors pull request and cleans up code * style(challenges): QA React challenges * style(challenges): QA react challenges * fix(challenges): fix react 41 and 45 tests * style(challenges): QA redux challenges * style(challenges): QA react and redux challenges * fix(seed/react): Move head/tail to files * fix(seed/redux): Move head/tail to file level * chore(packages): Move jsdom to dev deps * fix(seed/react/redux): Async funcs make async func defined * fix(seed): %s/editor.getUserCode/getUserInput/gc * fix(Challenges/build): Make sure head/tail is bundled and transformed * feat(Challenges.react): Add tail to render component * chore(seed): Disable modern challenge testing for now We will put these on beta while we update the auto testing framework
2017-12-18 21:04:03 +00:00
"id": "5a24c314108439a4d4036141",
"title": "Getting Started with React Redux",
"releasedOn": "December 25, 2017",
"description": [
"This series of challenges introduces how to use Redux with React. First, here's a review of some of the key principles of each technology. React is a view library that you provide with data, then it renders the view in an efficient, predictable way. Redux is a state management framework that you can use to simplify the management of your application's state. Typically, in a React Redux app, you create a single Redux store that manages the state of your entire app. Your React components subscribe to only the pieces of data in the store that are relevant to their role. Then, you dispatch actions directly from React components, which then trigger store updates.",
"Although React components can manage their own state locally, when you have a complex app, it's generally better to keep the app state in a single location with Redux. There are exceptions when individual components may have local state specific only to them. Finally, because Redux is not designed to work with React out of the box, you need to use the <code>react-redux</code> package. It provides a way for you to pass Redux <code>state</code> and <code>dispatch</code> to your React components as <code>props</code>.",
"Over the next few challenges, first, you'll create a simple React component which allows you to input new text messages. These are added to an array that's displayed in the view. This should be a nice review of what you learned in the React lessons. Next, you'll create a Redux store and actions that manage the state of the messages array. Finally, you'll use <code>react-redux</code> to connect the Redux store with your component, thereby extracting the local state into the Redux store.",
"<hr>",
"Start with a <code>DisplayMessages</code> component. Add a constructor to this component and initialize it with a state that has two properties: <code>input</code>, that's set to an empty string, and <code>messages</code>, that's set to an empty array."
],
"files": {
"indexjsx": {
"key": "indexjsx",
"ext": "jsx",
"name": "index",
"contents": [
"class DisplayMessages extends React.Component {",
" // change code below this line",
"",
" // change code above this line",
" render() {",
" return <div />",
" }",
"};"
],
"tail": "ReactDOM.render(<DisplayMessages />, document.getElementById('root'))"
}
},
"tests": [
"assert((function() { const mockedComponent = Enzyme.mount(React.createElement(DisplayMessages)); return mockedComponent.find('div').text() === '' })(), 'message: The <code>DisplayMessages</code> component should render an empty <code>div</code> element.');",
"getUserInput => assert((function() { const noWhiteSpace = getUserInput('index').replace(/\\s/g,''); return noWhiteSpace.includes('constructor(props)') && noWhiteSpace.includes('super(props'); })(), 'message: The <code>DisplayMessages</code> constructor should be called properly with <code>super</code>, passing in <code>props</code>.');",
Feat: react redux migration (#16200) * feat: crudely enables test to run solution code against React challenge (and passes!) * feat: Updates comment * feat: Adds React 2 and 3, validates challenges in app * feat: Adds React 4, validates tests * feat: Adds Peter's migrated challenge seed files for all challenges * feat: Adds redux, react-redux imports, adds tests for React 7, * feat: Adds tests for React 08 * fix(challenges): wrap reserved words in <code> and add tests * feat: complete first two tests for React 9 * feat: modifies tests in React 09 * feat: Adds working tests for React 37, including async setState tests * feat: Escape hatch to avoid async tests in automated test suite * feat: Updates React 15 with working tests * feat: build passes, yay * feat: Provisions original code string in challenges and adds tests for React Redux 01 * fix(tests): add self-closing tags challenge, other small fixes * fix(challenge): add react_10, some other stuff * fix(challenges): update react 22, add react 23 * fix(challenges): react 5 and react 8 * feat: removes dependencies that will break in browser, will replace later * feat: fix build * feat: add redux 1 * fix(challenge): add react 24 tests * feat: partial implemented Redux 2 * feat: migrate redux 3 * feat: Adds React-Redux 04 with working tests under npm test * feat: Updates automated test runner, just provide all the dependencies. Adds Redux-Thunk. * feat: Adds working tests for React Redux 07 * feat: redux challenge 4 * feat: migrate redux 5 * feat: redux 6 * feat: migrate Redux test 7 * fix(challenge): add react 25 tests * feat: Adds tests for React 48, npm test does not pass... * feat: Migrate Redux test 8 * fix(challenges): skip 26, add react 27 tests * fix(challenges): add react 28 tests, replace function w/ => throughout, fix linter warnings * feat: fixes (patches) hard to understand problem with automated test suite * feat: updates async tests patch * feat: adds converted tests for React 47 * feat: adds converted tests for React 46 * feat: Partially adds tests for React 43 * docs: adds TO-DO tests for React 43 * feat: migrates tests for React 42 * feat: migrates tests for React 41 * feat: migrates tests for React 39 * feat: Migrates tests for React 38, automated test script fails again! * feat: migrates tests for React 32 * feat: QAs more React Redux challenge in FCC UI * feat: Updates tests for React 7 * feat: Migrates React-Redux 3 tests and hardcodes deep-freeze dependency * feat: migrates React Redux 05 tests * feat: migrates React Redux 06 tests * feat: Migrates React Redux 10 * feat: Migrates tests for React 16 * feat: Migrates React 17 tests * feat: Migrates React 18 tests * feat: Migrates React 19 tests * feat: Migrates React 19 tests * feat: fixing usage of code, replace with editor.getOriginalCode * feat: Migrates React 21 tests * feat: Finishes migration of React 09 * fix(challenges): add react 45 tests 💀 * feat: Adds React 11 tests * feat: Migrates React 50 tests * feat: Re-enables original code in FCC editor, QAs challenges blocked by original code * feat: hacks head tail code in editor test environment * feat: updates React 20 head code * feat: QAs React Redux 07 in UI * fix(challenges): add React 29 tests * fix(challenges): add React 30 tests * feat: updates async tests * feat: Migrates React 12, gets ReactDOM challenges working and QAs them * feat: Migrates React 13 tests * feat: Migrates tests for React 14 and updates challenge description formatting * feat: Refactors 2nd test for Redux 02 * feat: Migrates React 33 * feat: Removes React 26 and 43 * feat: Adds React 34 from Kevin * fix(challenges): add React 31 & 35 tests (thanks Kevin) * feat: Migrate Redux challenge 10 - pass both UI QA and terminal test * fix(challenge): add react 40 tests * feat: Migrates React Redux 02 tests * feat: Migrates React Redux 08 and fixes async syntax in React challenge * fix(challenge): add react 49 tests with caveat * feat: fixes React 49 tests and adds first tests for React Redux 09 * feat: Migrate Redux 11 - pass both terminal test and UI test * feat: Migrate Redux 12 - passing both UI test and terminal test * feat: Migrate Redux 13 - passing both terminal and UI tests * feat: Adding in code tags for previous redux challenges - terminal and UI tests pass * feat: Migrates React Redux 09 and React 44 (thanks Kevin) * feat: fix code tag issues - passed UI and terminal tests * feat: Migrates Redux 14 tests * feat: Migrates Redux 14 * feat: Migrates Redux 15 * feat: Migrates Redux 17 * feat: Final migration and QA of Redux, except for Redux 9 * feat: migrates React 36 and QAs * feat: Rewrites Redux 09 and migrates * feat: refactors pull request and cleans up code * style(challenges): QA React challenges * style(challenges): QA react challenges * fix(challenges): fix react 41 and 45 tests * style(challenges): QA redux challenges * style(challenges): QA react and redux challenges * fix(seed/react): Move head/tail to files * fix(seed/redux): Move head/tail to file level * chore(packages): Move jsdom to dev deps * fix(seed/react/redux): Async funcs make async func defined * fix(seed): %s/editor.getUserCode/getUserInput/gc * fix(Challenges/build): Make sure head/tail is bundled and transformed * feat(Challenges.react): Add tail to render component * chore(seed): Disable modern challenge testing for now We will put these on beta while we update the auto testing framework
2017-12-18 21:04:03 +00:00
"assert((function() { const mockedComponent = Enzyme.mount(React.createElement(DisplayMessages)); const initialState = mockedComponent.state(); return typeof initialState === 'object' && initialState.input === '' && Array.isArray(initialState.messages) && initialState.messages.length === 0; })(), 'message: The <code>DisplayMessages</code> component should have an initial state equal to <code>{input: \"\", messages: []}</code>.');"
],
"solutions": [
"class DisplayMessages extends React.Component {\n constructor(props) {\n super(props);\n this.state = {\n input: '',\n messages: []\n }\n }\n render() {\n return <div/>\n }\n};"
],
"type": "modern",
"isRequired": false,
"translations": {},
"react": true
},
{
"id": "5a24c314108439a4d4036142",
"title": "Manage State Locally First",
"releasedOn": "December 25, 2017",
2017-01-17 04:44:38 +00:00
"description": [
Feat: react redux migration (#16200) * feat: crudely enables test to run solution code against React challenge (and passes!) * feat: Updates comment * feat: Adds React 2 and 3, validates challenges in app * feat: Adds React 4, validates tests * feat: Adds Peter's migrated challenge seed files for all challenges * feat: Adds redux, react-redux imports, adds tests for React 7, * feat: Adds tests for React 08 * fix(challenges): wrap reserved words in <code> and add tests * feat: complete first two tests for React 9 * feat: modifies tests in React 09 * feat: Adds working tests for React 37, including async setState tests * feat: Escape hatch to avoid async tests in automated test suite * feat: Updates React 15 with working tests * feat: build passes, yay * feat: Provisions original code string in challenges and adds tests for React Redux 01 * fix(tests): add self-closing tags challenge, other small fixes * fix(challenge): add react_10, some other stuff * fix(challenges): update react 22, add react 23 * fix(challenges): react 5 and react 8 * feat: removes dependencies that will break in browser, will replace later * feat: fix build * feat: add redux 1 * fix(challenge): add react 24 tests * feat: partial implemented Redux 2 * feat: migrate redux 3 * feat: Adds React-Redux 04 with working tests under npm test * feat: Updates automated test runner, just provide all the dependencies. Adds Redux-Thunk. * feat: Adds working tests for React Redux 07 * feat: redux challenge 4 * feat: migrate redux 5 * feat: redux 6 * feat: migrate Redux test 7 * fix(challenge): add react 25 tests * feat: Adds tests for React 48, npm test does not pass... * feat: Migrate Redux test 8 * fix(challenges): skip 26, add react 27 tests * fix(challenges): add react 28 tests, replace function w/ => throughout, fix linter warnings * feat: fixes (patches) hard to understand problem with automated test suite * feat: updates async tests patch * feat: adds converted tests for React 47 * feat: adds converted tests for React 46 * feat: Partially adds tests for React 43 * docs: adds TO-DO tests for React 43 * feat: migrates tests for React 42 * feat: migrates tests for React 41 * feat: migrates tests for React 39 * feat: Migrates tests for React 38, automated test script fails again! * feat: migrates tests for React 32 * feat: QAs more React Redux challenge in FCC UI * feat: Updates tests for React 7 * feat: Migrates React-Redux 3 tests and hardcodes deep-freeze dependency * feat: migrates React Redux 05 tests * feat: migrates React Redux 06 tests * feat: Migrates React Redux 10 * feat: Migrates tests for React 16 * feat: Migrates React 17 tests * feat: Migrates React 18 tests * feat: Migrates React 19 tests * feat: Migrates React 19 tests * feat: fixing usage of code, replace with editor.getOriginalCode * feat: Migrates React 21 tests * feat: Finishes migration of React 09 * fix(challenges): add react 45 tests 💀 * feat: Adds React 11 tests * feat: Migrates React 50 tests * feat: Re-enables original code in FCC editor, QAs challenges blocked by original code * feat: hacks head tail code in editor test environment * feat: updates React 20 head code * feat: QAs React Redux 07 in UI * fix(challenges): add React 29 tests * fix(challenges): add React 30 tests * feat: updates async tests * feat: Migrates React 12, gets ReactDOM challenges working and QAs them * feat: Migrates React 13 tests * feat: Migrates tests for React 14 and updates challenge description formatting * feat: Refactors 2nd test for Redux 02 * feat: Migrates React 33 * feat: Removes React 26 and 43 * feat: Adds React 34 from Kevin * fix(challenges): add React 31 & 35 tests (thanks Kevin) * feat: Migrate Redux challenge 10 - pass both UI QA and terminal test * fix(challenge): add react 40 tests * feat: Migrates React Redux 02 tests * feat: Migrates React Redux 08 and fixes async syntax in React challenge * fix(challenge): add react 49 tests with caveat * feat: fixes React 49 tests and adds first tests for React Redux 09 * feat: Migrate Redux 11 - pass both terminal test and UI test * feat: Migrate Redux 12 - passing both UI test and terminal test * feat: Migrate Redux 13 - passing both terminal and UI tests * feat: Adding in code tags for previous redux challenges - terminal and UI tests pass * feat: Migrates React Redux 09 and React 44 (thanks Kevin) * feat: fix code tag issues - passed UI and terminal tests * feat: Migrates Redux 14 tests * feat: Migrates Redux 14 * feat: Migrates Redux 15 * feat: Migrates Redux 17 * feat: Final migration and QA of Redux, except for Redux 9 * feat: migrates React 36 and QAs * feat: Rewrites Redux 09 and migrates * feat: refactors pull request and cleans up code * style(challenges): QA React challenges * style(challenges): QA react challenges * fix(challenges): fix react 41 and 45 tests * style(challenges): QA redux challenges * style(challenges): QA react and redux challenges * fix(seed/react): Move head/tail to files * fix(seed/redux): Move head/tail to file level * chore(packages): Move jsdom to dev deps * fix(seed/react/redux): Async funcs make async func defined * fix(seed): %s/editor.getUserCode/getUserInput/gc * fix(Challenges/build): Make sure head/tail is bundled and transformed * feat(Challenges.react): Add tail to render component * chore(seed): Disable modern challenge testing for now We will put these on beta while we update the auto testing framework
2017-12-18 21:04:03 +00:00
"Here you'll finish creating the <code>DisplayMessages</code> component.",
"<hr>",
"First, in the <code>render()</code> method, have the component render an <code>input</code> element, <code>button</code> element, and <code>ul</code> element. When the <code>input</code> element changes, it should trigger a <code>handleChange()</code> method. Also, the <code>input</code> element should render the value of <code>input</code> that's in the component's state. The <code>button</code> element should trigger a <code>submitMessage()</code> method when it's clicked.",
"Second, write these two methods. The <code>handleChange()</code> method should update the <code>input</code> with what the user is typing. The <code>submitMessage()</code> method should concatenate the current message (stored in <code>input</code>) to the <code>messages</code> array in local state, and clear the value of the <code>input</code>.",
"Finally, use the <code>ul</code> to map over the array of <code>messages</code> and render it to the screen as a list of <code>li</code> elements."
],
"files": {
"indexjsx": {
"key": "indexjsx",
"ext": "jsx",
"name": "index",
"contents": [
"class DisplayMessages extends React.Component {",
" constructor(props) {",
" super(props);",
" this.state = {",
" input: '',",
" messages: []",
" }",
" }",
" // add handleChange() and submitMessage() methods here",
"",
" render() {",
" return (",
" <div>",
" <h2>Type in a new Message:</h2>",
" { /* render an input, button, and ul here */ }",
"",
" { /* change code above this line */ }",
" </div>",
" );",
" }",
"};"
],
"tail": "ReactDOM.render(<DisplayMessages />, document.getElementById('root'))"
}
},
"tests": [
"assert((function() { const mockedComponent = Enzyme.mount(React.createElement(DisplayMessages)); const initialState = mockedComponent.state(); return ( typeof initialState === 'object' && initialState.input === '' && initialState.messages.length === 0); })(), 'message: The <code>DisplayMessages</code> component should initialize with a state equal to <code>{ input: \"\", messages: [] }</code>.');",
"async () => { const mockedComponent = Enzyme.mount(React.createElement(DisplayMessages)); const waitForIt = (fn) => new Promise((resolve, reject) => setTimeout(() => resolve(fn()), 100)); const state = () => { mockedComponent.setState({messages: ['__TEST__MESSAGE']}); return waitForIt(() => mockedComponent )}; const updated = await state(); assert(updated.find('div').length === 1 && updated.find('h2').length === 1 && updated.find('button').length === 1 && updated.find('ul').length === 1, 'message: The <code>DisplayMessages</code> component should render a <code>div</code> containing an <code>h2</code> element, a <code>button</code> element, a <code>ul</code> element, and <code>li</code> elements as children.'); }; ",
"async () => { const mockedComponent = Enzyme.mount(React.createElement(DisplayMessages)); const waitForIt = (fn) => new Promise((resolve, reject) => setTimeout(() => resolve(fn()), 100)); const causeChange = (c, v) => c.find('input').simulate('change', { target: { value: v }}); const testValue = '__TEST__EVENT__INPUT'; const changed = () => { causeChange(mockedComponent, testValue); return waitForIt(() => mockedComponent )}; const updated = await changed(); assert(updated.find('input').props().value === testValue, 'message: The <code>input</code> element should render the value of <code>input</code> in local state.'); }; ",
"async () => { const mockedComponent = Enzyme.mount(React.createElement(DisplayMessages)); const waitForIt = (fn) => new Promise((resolve, reject) => setTimeout(() => resolve(fn()), 100)); const causeChange = (c, v) => c.find('input').simulate('change', { target: { value: v }}); const initialState = mockedComponent.state(); const testMessage = '__TEST__EVENT__MESSAGE__'; const changed = () => { causeChange(mockedComponent, testMessage); return waitForIt(() => mockedComponent )}; const afterInput = await changed(); assert(initialState.input === '' && afterInput.state().input === '__TEST__EVENT__MESSAGE__', 'message: Calling the method <code>handleChange</code> should update the <code>input</code> value in state to the current input.'); }; ",
"async () => { const mockedComponent = Enzyme.mount(React.createElement(DisplayMessages)); const waitForIt = (fn) => new Promise((resolve, reject) => setTimeout(() => resolve(fn()), 100)); const causeChange = (c, v) => c.find('input').simulate('change', { target: { value: v }}); const initialState = mockedComponent.state(); const testMessage_1 = '__FIRST__MESSAGE__'; const firstChange = () => { causeChange(mockedComponent, testMessage_1); return waitForIt(() => mockedComponent )}; const firstResult = await firstChange(); const firstSubmit = () => { mockedComponent.find('button').simulate('click'); return waitForIt(() => mockedComponent )}; const afterSubmit_1 = await firstSubmit(); const submitState_1 = afterSubmit_1.state(); const testMessage_2 = '__SECOND__MESSAGE__'; const secondChange = () => { causeChange(mockedComponent, testMessage_2); return waitForIt(() => mockedComponent )}; const secondResult = await secondChange(); const secondSubmit = () => { mockedComponent.find('button').simulate('click'); return waitForIt(() => mockedComponent )}; const afterSubmit_2 = await secondSubmit(); const submitState_2 = afterSubmit_2.state(); assert(initialState.messages.length === 0 && submitState_1.messages.length === 1 && submitState_2.messages.length === 2 && submitState_2.messages[1] === testMessage_2, 'message: Clicking the <code>Add message</code> button should call the method <code>submitMessage</code> which should add the current <code>input</code> to the <code>messages</code> array in state.'); }; ",
"async () => { const mockedComponent = Enzyme.mount(React.createElement(DisplayMessages)); const waitForIt = (fn) => new Promise((resolve, reject) => setTimeout(() => resolve(fn()), 100)); const causeChange = (c, v) => c.find('input').simulate('change', { target: { value: v }}); const initialState = mockedComponent.state(); const testMessage = '__FIRST__MESSAGE__'; const firstChange = () => { causeChange(mockedComponent, testMessage); return waitForIt(() => mockedComponent )}; const firstResult = await firstChange(); const firstState = firstResult.state(); const firstSubmit = () => { mockedComponent.find('button').simulate('click'); return waitForIt(() => mockedComponent )}; const afterSubmit = await firstSubmit(); const submitState = afterSubmit.state(); assert(firstState.input === testMessage && submitState.input === '', 'message: The <code>submitMessage</code> method should clear the current input.'); }; "
],
"solutions": [
"class DisplayMessages extends React.Component {\n constructor(props) {\n super(props);\n this.state = {\n input: '',\n messages: []\n }\n this.handleChange = this.handleChange.bind(this); \n this.submitMessage = this.submitMessage.bind(this); \n }\n handleChange(event) {\n this.setState({\n input: event.target.value\n });\n }\n submitMessage() {\n const currentMessage = this.state.input;\n this.setState({\n input: '',\n messages: this.state.messages.concat(currentMessage)\n });\n }\n render() {\n return (\n <div>\n <h2>Type in a new Message:</h2>\n <input\n value={this.state.input}\n onChange={this.handleChange}/><br/>\n <button onClick={this.submitMessage}>Submit</button>\n <ul>\n {this.state.messages.map( (message, idx) => {\n return (\n <li key={idx}>{message}</li>\n )\n })\n }\n </ul>\n </div>\n );\n }\n};"
],
"type": "modern",
"isRequired": false,
"translations": {},
"reactRedux": true
},
{
"id": "5a24c314108439a4d4036143",
"title": "Extract State Logic to Redux",
"releasedOn": "December 25, 2017",
"description": [
"Now that you finished the React component, you need to move the logic it's performing locally in its <code>state</code> into Redux. This is the first step to connect the simple React app to Redux. The only functionality your app has is to add new messages from the user to an unordered list. The example is simple in order to demonstrate how React and Redux work together.",
"<hr>",
"First, define an action type 'ADD' and set it to a const <code>ADD</code>. Next, define an action creator <code>addMessage()</code> which creates the action to add a message. You'll need to pass a <code>message</code> to this action creator and include the message in the returned <code>action</code>.",
"Then create a reducer called <code>messageReducer()</code> that handles the state for the messages. The initial state should equal an empty array. This reducer should add a message to the array of messages held in state, or return the current state. Finally, create your Redux store and pass it the reducer."
],
"files": {
"indexjsx": {
"key": "indexjsx",
"ext": "jsx",
"name": "index",
"contents": [
"// define ADD, addMessage(), messageReducer(), and store here:",
""
]
}
},
"tests": [
"assert(ADD === 'ADD', 'message: The const <code>ADD</code> should exist and hold a value equal to the string <code>ADD</code>');",
"assert((function() { const addAction = addMessage('__TEST__MESSAGE__'); return addAction.type === ADD && addAction.message === '__TEST__MESSAGE__'; })(), 'message: The action creator <code>addMessage</code> should return an object with <code>type</code> equal to <code>ADD</code> and message equal to the message that is passed in.');",
"assert(typeof messageReducer === 'function', 'message: <code>messageReducer</code> should be a function.');",
"assert((function() { const initialState = store.getState(); return typeof store === 'object' && initialState.length === 0; })(), 'message: The store should exist and have an initial state set to an empty array.');",
"assert((function() { const initialState = store.getState(); const isFrozen = DeepFreeze(initialState); store.dispatch(addMessage('__A__TEST__MESSAGE')); const addState = store.getState(); return (isFrozen && addState[0] === '__A__TEST__MESSAGE'); })(), 'message: Dispatching <code>addMessage</code> against the store should immutably add a new message to the array of messages held in state.');",
"assert((function() { const addState = store.getState(); store.dispatch({type: 'FAKE_ACTION'}); const testState = store.getState(); return (addState === testState); })(), 'message: The <code>messageReducer</code> should return the current state if called with any other actions.');"
],
"solutions": [
"const ADD = 'ADD';\n\nconst addMessage = (message) => {\n return {\n type: ADD,\n message\n }\n};\n\nconst messageReducer = (state = [], action) => {\n switch (action.type) {\n case ADD:\n return [\n ...state,\n action.message\n ];\n default:\n return state;\n }\n};\n\nconst store = Redux.createStore(messageReducer);"
],
"type": "modern",
"isRequired": false,
"translations": {},
"reactRedux": true
},
{
"id": "5a24c314108439a4d4036144",
"title": "Use Provider to Connect Redux to React",
"releasedOn": "December 25, 2017",
"description": [
"In the last challenge, you created a Redux store to handle the messages array and created an action for adding new messages. The next step is to provide React access to the Redux store and the actions it needs to dispatch updates. React Redux provides its <code>react-redux</code> package to help accomplish these tasks.",
"React Redux provides a small API with two key features: <code>Provider</code> and <code>connect</code>. Another challenge covers <code>connect</code>. The <code>Provider</code> is a wrapper component from React Redux that wraps your React app. This wrapper then allows you to access the Redux <code>store</code> and <code>dispatch</code> functions throughout your component tree. <code>Provider</code> takes two props, the Redux store and the child components of your app. Defining the <code>Provider</code> for an App component might look like this:",
"<blockquote>&lt;Provider store={store}&gt;<br> &lt;App/&gt;<br>&lt;/Provider&gt;</blockquote>",
"<hr>",
"The code editor now shows all your Redux and React code from the past several challenges. It includes the Redux store, actions, and the <code>DisplayMessages</code> component. The only new piece is the <code>AppWrapper</code> component at the bottom. Use this top level component to render the <code>Provider</code> from <code>ReactRedux</code>, and pass the Redux store as a prop. Then render the <code>DisplayMessages</code> component as a child. Once you are finished, you should see your React component rendered to the page.",
"<strong>Note:</strong>&nbsp;React Redux is available as a global variable here, so you can access the Provider with dot notation. The code in the editor takes advantage of this and sets it to a constant <code>Provider</code> for you to use in the <code>AppWrapper</code> render method."
],
"files": {
"indexjsx": {
"key": "indexjsx",
"ext": "jsx",
"name": "index",
"contents": [
"// Redux Code:",
"const ADD = 'ADD';",
"",
"const addMessage = (message) => {",
" return {",
" type: ADD,",
" message",
" }",
"};",
"",
"const messageReducer = (state = [], action) => {",
" switch (action.type) {",
" case ADD:",
" return [",
" ...state,",
" action.message",
" ];",
" default:",
" return state;",
" }",
"};",
"",
"",
"",
"const store = Redux.createStore(messageReducer);",
"",
"// React Code:",
"",
"class DisplayMessages extends React.Component {",
" constructor(props) {",
" super(props);",
" this.state = {",
" input: '',",
" messages: []",
" }",
" this.handleChange = this.handleChange.bind(this);",
" this.submitMessage = this.submitMessage.bind(this);",
" }",
" handleChange(event) {",
" this.setState({",
" input: event.target.value",
" });",
" }",
" submitMessage() {",
" const currentMessage = this.state.input;",
" this.setState({",
" input: '',",
" messages: this.state.messages.concat(currentMessage)",
" });",
" }",
" render() {",
" return (",
" <div>",
" <h2>Type in a new Message:</h2>",
" <input",
" value={this.state.input}",
" onChange={this.handleChange}/><br/>",
" <button onClick={this.submitMessage}>Submit</button>",
" <ul>",
" {this.state.messages.map( (message, idx) => {",
" return (",
" <li key={idx}>{message}</li>",
" )",
" })",
" }",
" </ul>",
" </div>",
" );",
" }",
"};",
"",
"const Provider = ReactRedux.Provider;",
"",
"class AppWrapper extends React.Component {",
" // render the Provider here",
"",
" // change code above this line",
"};"
],
"tail": "ReactDOM.render(<AppWrapper />, document.getElementById('root'))"
}
},
"tests": [
"assert((function() { const mockedComponent = Enzyme.mount(React.createElement(AppWrapper)); return mockedComponent.find('AppWrapper').length === 1; })(), 'message: The <code>AppWrapper</code> should render.');",
"getUserInput => assert((function() { const mockedComponent = Enzyme.mount(React.createElement(AppWrapper)); return getUserInput('index').replace(/\\s/g,'').includes('<Providerstore={store}>'); })(), 'message: The <code>Provider</code> wrapper component should have a prop of <code>store</code> passed to it, equal to the Redux store.');",
Feat: react redux migration (#16200) * feat: crudely enables test to run solution code against React challenge (and passes!) * feat: Updates comment * feat: Adds React 2 and 3, validates challenges in app * feat: Adds React 4, validates tests * feat: Adds Peter's migrated challenge seed files for all challenges * feat: Adds redux, react-redux imports, adds tests for React 7, * feat: Adds tests for React 08 * fix(challenges): wrap reserved words in <code> and add tests * feat: complete first two tests for React 9 * feat: modifies tests in React 09 * feat: Adds working tests for React 37, including async setState tests * feat: Escape hatch to avoid async tests in automated test suite * feat: Updates React 15 with working tests * feat: build passes, yay * feat: Provisions original code string in challenges and adds tests for React Redux 01 * fix(tests): add self-closing tags challenge, other small fixes * fix(challenge): add react_10, some other stuff * fix(challenges): update react 22, add react 23 * fix(challenges): react 5 and react 8 * feat: removes dependencies that will break in browser, will replace later * feat: fix build * feat: add redux 1 * fix(challenge): add react 24 tests * feat: partial implemented Redux 2 * feat: migrate redux 3 * feat: Adds React-Redux 04 with working tests under npm test * feat: Updates automated test runner, just provide all the dependencies. Adds Redux-Thunk. * feat: Adds working tests for React Redux 07 * feat: redux challenge 4 * feat: migrate redux 5 * feat: redux 6 * feat: migrate Redux test 7 * fix(challenge): add react 25 tests * feat: Adds tests for React 48, npm test does not pass... * feat: Migrate Redux test 8 * fix(challenges): skip 26, add react 27 tests * fix(challenges): add react 28 tests, replace function w/ => throughout, fix linter warnings * feat: fixes (patches) hard to understand problem with automated test suite * feat: updates async tests patch * feat: adds converted tests for React 47 * feat: adds converted tests for React 46 * feat: Partially adds tests for React 43 * docs: adds TO-DO tests for React 43 * feat: migrates tests for React 42 * feat: migrates tests for React 41 * feat: migrates tests for React 39 * feat: Migrates tests for React 38, automated test script fails again! * feat: migrates tests for React 32 * feat: QAs more React Redux challenge in FCC UI * feat: Updates tests for React 7 * feat: Migrates React-Redux 3 tests and hardcodes deep-freeze dependency * feat: migrates React Redux 05 tests * feat: migrates React Redux 06 tests * feat: Migrates React Redux 10 * feat: Migrates tests for React 16 * feat: Migrates React 17 tests * feat: Migrates React 18 tests * feat: Migrates React 19 tests * feat: Migrates React 19 tests * feat: fixing usage of code, replace with editor.getOriginalCode * feat: Migrates React 21 tests * feat: Finishes migration of React 09 * fix(challenges): add react 45 tests 💀 * feat: Adds React 11 tests * feat: Migrates React 50 tests * feat: Re-enables original code in FCC editor, QAs challenges blocked by original code * feat: hacks head tail code in editor test environment * feat: updates React 20 head code * feat: QAs React Redux 07 in UI * fix(challenges): add React 29 tests * fix(challenges): add React 30 tests * feat: updates async tests * feat: Migrates React 12, gets ReactDOM challenges working and QAs them * feat: Migrates React 13 tests * feat: Migrates tests for React 14 and updates challenge description formatting * feat: Refactors 2nd test for Redux 02 * feat: Migrates React 33 * feat: Removes React 26 and 43 * feat: Adds React 34 from Kevin * fix(challenges): add React 31 & 35 tests (thanks Kevin) * feat: Migrate Redux challenge 10 - pass both UI QA and terminal test * fix(challenge): add react 40 tests * feat: Migrates React Redux 02 tests * feat: Migrates React Redux 08 and fixes async syntax in React challenge * fix(challenge): add react 49 tests with caveat * feat: fixes React 49 tests and adds first tests for React Redux 09 * feat: Migrate Redux 11 - pass both terminal test and UI test * feat: Migrate Redux 12 - passing both UI test and terminal test * feat: Migrate Redux 13 - passing both terminal and UI tests * feat: Adding in code tags for previous redux challenges - terminal and UI tests pass * feat: Migrates React Redux 09 and React 44 (thanks Kevin) * feat: fix code tag issues - passed UI and terminal tests * feat: Migrates Redux 14 tests * feat: Migrates Redux 14 * feat: Migrates Redux 15 * feat: Migrates Redux 17 * feat: Final migration and QA of Redux, except for Redux 9 * feat: migrates React 36 and QAs * feat: Rewrites Redux 09 and migrates * feat: refactors pull request and cleans up code * style(challenges): QA React challenges * style(challenges): QA react challenges * fix(challenges): fix react 41 and 45 tests * style(challenges): QA redux challenges * style(challenges): QA react and redux challenges * fix(seed/react): Move head/tail to files * fix(seed/redux): Move head/tail to file level * chore(packages): Move jsdom to dev deps * fix(seed/react/redux): Async funcs make async func defined * fix(seed): %s/editor.getUserCode/getUserInput/gc * fix(Challenges/build): Make sure head/tail is bundled and transformed * feat(Challenges.react): Add tail to render component * chore(seed): Disable modern challenge testing for now We will put these on beta while we update the auto testing framework
2017-12-18 21:04:03 +00:00
"assert((function() { const mockedComponent = Enzyme.mount(React.createElement(AppWrapper)); return mockedComponent.find('AppWrapper').find('DisplayMessages').length === 1; })(), 'message: <code>DisplayMessages</code> should render as a child of <code>AppWrapper</code>.');",
"assert((function() { const mockedComponent = Enzyme.mount(React.createElement(AppWrapper)); return mockedComponent.find('div').length === 1 && mockedComponent.find('h2').length === 1 && mockedComponent.find('button').length === 1 && mockedComponent.find('ul').length === 1; })(), 'message: The <code>DisplayMessages</code> component should render an h2, input, button, and <code>ul</code> element.');"
],
"solutions": [
"// Redux Code:\nconst ADD = 'ADD';\n\nconst addMessage = (message) => {\n return {\n type: ADD,\n message\n }\n};\n\nconst messageReducer = (state = [], action) => {\n switch (action.type) {\n case ADD:\n return [\n ...state,\n action.message\n ];\n default:\n return state;\n }\n};\n\nconst store = Redux.createStore(messageReducer);\n\n// React Code:\n\nclass DisplayMessages extends React.Component {\n constructor(props) {\n super(props);\n this.state = {\n input: '',\n messages: []\n }\n this.handleChange = this.handleChange.bind(this); \n this.submitMessage = this.submitMessage.bind(this); \n }\n handleChange(event) {\n this.setState({\n input: event.target.value\n });\n }\n submitMessage() {\n const currentMessage = this.state.input;\n this.setState({\n input: '',\n messages: this.state.messages.concat(currentMessage)\n });\n }\n render() {\n return (\n <div>\n <h2>Type in a new Message:</h2>\n <input\n value={this.state.input}\n onChange={this.handleChange}/><br/>\n <button onClick={this.submitMessage}>Submit</button>\n <ul>\n {this.state.messages.map( (message, idx) => {\n return (\n <li key={idx}>{message}</li>\n )\n })\n }\n </ul>\n </div>\n );\n }\n};\n\nconst Provider = ReactRedux.Provider;\n\nclass AppWrapper extends React.Component {\n // change code below this line\n render() {\n return (\n <Provider store = {store}>\n <DisplayMessages/>\n </Provider>\n );\n }\n // change code above this line\n};"
],
"type": "modern",
"isRequired": false,
"translations": {},
"reactRedux": true
},
{
"id": "5a24c314108439a4d4036145",
"title": "Map State to Props",
"releasedOn": "December 25, 2017",
"description": [
"The <code>Provider</code> component allows you to provide <code>state</code> and <code>dispatch</code> to your React components, but you must specify exactly what state and actions you want. This way, you make sure that each component only has access to the state it needs. You accomplish this by creating two functions: <code>mapStateToProps()</code> and <code>mapDispatchToProps()</code>.",
"In these functions, you declare what pieces of state you want to have access to and which action creators you need to be able to dispatch. Once these functions are in place, you'll see how to use the React Redux <code>connect</code> method to connect them to your components in another challenge.",
"<strong>Note:</strong>&nbsp;Behind the scenes, React Redux uses the <code>store.subscribe()</code> method to implement <code>mapStateToProps()</code>.",
"<hr>",
"Create a function <code>mapStateToProps()</code>. This function should take <code>state</code> as an argument, then return an object which maps that state to specific property names. These properties will become accessible to your component via <code>props</code>. Since this example keeps the entire state of the app in a single array, you can pass that entire state to your component. Create a property <code>messages</code> in the object that's being returned, and set it to <code>state</code>."
],
"files": {
"indexjsx": {
"key": "indexjsx",
"ext": "jsx",
"name": "index",
"contents": [
"const state = [];",
"",
"// change code below this line",
""
]
}
},
"tests": [
"assert(Array.isArray(state) && state.length === 0, 'message: The const <code>state</code> should be an empty array.');",
"assert(typeof mapStateToProps === 'function', 'message: <code>mapStateToProps</code> should be a function.');",
"assert(typeof mapStateToProps() === 'object', 'message: <code>mapStateToProps</code> should return an object.');",
"assert(mapStateToProps(['messages']).messages.pop() === 'messages', 'message: Passing an array as state to <code>mapStateToProps</code> should return this array assigned to a key of <code>messages</code>.');"
],
"solutions": [
"const state = [];\n\n// change code below this line\n\nconst mapStateToProps = (state) => {\n return {\n messages: state\n }\n};"
],
"type": "modern",
"isRequired": false,
"translations": {},
"reactRedux": true
},
{
"id": "5a24c314108439a4d4036146",
"title": "Map Dispatch to Props",
"releasedOn": "December 25, 2017",
"description": [
"The <code>mapDispatchToProps()</code> function is used to provide specific action creators to your React components so they can dispatch actions against the Redux store. It's similar in structure to the <code>mapStateToProps()</code> function you wrote in the last challenge. It returns an object that maps dispatch actions to property names, which become component <code>props</code>. However, instead of returning a piece of <code>state</code>, each property returns a function that calls <code>dispatch</code> with an action creator and any relevant action data. You have access to this <code>dispatch</code> because it's passed in to <code>mapDispatchToProps()</code> as a parameter when you define the function, just like you passed <code>state</code> to <code>mapStateToProps()</code>. Behind the scenes, React Redux is using Redux's <code>store.dispatch()</code> to conduct these dispatches with <code>mapDispatchToProps()</code>. This is similar to how it uses <code>store.subscribe()</code> for components that are mapped to <code>state</code>.",
"For example, you have a <code>loginUser()</code> action creator that takes a <code>username</code> as an action payload. The object returned from <code>mapDispatchToProps()</code> for this action creator would look something like:",
"<blockquote>{<br> submitLoginUser: function(username) {<br> dispatch(loginUser(username));<br> }<br>}</blockquote>",
"<hr>",
"The code editor provides an action creator called <code>addMessage()</code>. Write the function <code>mapDispatchToProps()</code> that takes <code>dispatch</code> as an argument, then returns an object. The object should have a property <code>submitNewMessage</code> set to the dispatch function, which takes a parameter for the new message to add when it dispatches <code>addMessage()</code>."
],
"files": {
"indexjsx": {
"key": "indexjsx",
"ext": "jsx",
"name": "index",
"contents": [
"const addMessage = (message) => {",
" return {",
" type: 'ADD',",
" message: message",
" }",
"};",
"",
"// change code below this line",
""
]
}
},
"tests": [
"assert((function() { const addMessageTest = addMessage(); return ( addMessageTest.hasOwnProperty('type') && addMessageTest.hasOwnProperty('message')); })(), 'message: <code>addMessage</code> should return an object with keys <code>type</code> and <code>message</code>.');",
"assert(typeof mapDispatchToProps === 'function', 'message: <code>mapDispatchToProps</code> should be a function.');",
"assert(typeof mapDispatchToProps() === 'object', 'message: <code>mapDispatchToProps</code> should return an object.');",
"assert((function() { let testAction; const dispatch = (fn) => { testAction = fn; }; let dispatchFn = mapDispatchToProps(dispatch); dispatchFn.submitNewMessage('__TEST__MESSAGE__'); return (testAction.type === 'ADD' && testAction.message === '__TEST__MESSAGE__'); })(), 'message: Dispatching <code>addMessage</code> with <code>submitNewMessage</code> from <code>mapDispatchToProps</code> should return a message to the dispatch function.');"
],
"solutions": [
"const addMessage = (message) => {\n return {\n type: 'ADD',\n message: message\n }\n};\n\n// change code below this line\n\nconst mapDispatchToProps = (dispatch) => {\n return {\n submitNewMessage: function(message) {\n dispatch(addMessage(message));\n }\n }\n};"
],
"type": "modern",
"isRequired": false,
"translations": {},
"reactRedux": true
},
{
"id": "5a24c314108439a4d4036147",
"title": "Connect Redux to React",
"releasedOn": "December 25, 2017",
"description": [
"Now that you've written both the <code>mapStateToProps()</code> and the <code>mapDispatchToProps()</code> functions, you can use them to map <code>state</code> and <code>dispatch</code> to the <code>props</code> of one of your React components. The <code>connect</code> method from React Redux can handle this task. This method takes two optional arguments, <code>mapStateToProps()</code> and <code>mapDispatchToProps()</code>. They are optional because you may have a component that only needs access to <code>state</code> but doesn't need to dispatch any actions, or vice versa.",
"To use this method, pass in the functions as arguments, and immediately call the result with your component. This syntax is a little unusual and looks like:",
"<code>connect(mapStateToProps, mapDispatchToProps)(MyComponent)</code>",
"<strong>Note:</strong>&nbsp;If you want to omit one of the arguments to the <code>connect</code> method, you pass <code>null</code> in its place.",
"<hr>",
"The code editor has the <code>mapStateToProps()</code> and <code>mapDispatchToProps()</code> functions and a new React component called <code>Presentational</code>. Connect this component to Redux with the <code>connect</code> method from the <code>ReactRedux</code> global object, and call it immediately on the <code>Presentational</code> component. Assign the result to a new <code>const</code> called <code>ConnectedComponent</code> that represents the connected component. That's it, now you're connected to Redux! Try changing either of <code>connect</code>'s arguments to <code>null</code> and observe the test results."
],
"files": {
"indexjsx": {
"key": "indexjsx",
"ext": "jsx",
"name": "index",
"contents": [
"const addMessage = (message) => {",
" return {",
" type: 'ADD',",
" message: message",
" }",
"};",
"",
"const mapStateToProps = (state) => {",
" return {",
" messages: state",
" }",
"};",
"",
"const mapDispatchToProps = (dispatch) => {",
" return {",
" submitNewMessage: (message) => {",
" dispatch(addMessage(message));",
" }",
" }",
"};",
"",
"class Presentational extends React.Component {",
" constructor(props) {",
" super(props);",
" }",
" render() {",
" return <h3>This is a Presentational Component</h3>",
" }",
"};",
"",
"const connect = ReactRedux.connect;",
"// change code below this line",
""
],
"tail": [
"",
"const store = Redux.createStore(",
" (state = '__INITIAL__STATE__', action) => state",
");",
"class AppWrapper extends React.Component {",
" render() {",
" return (",
" <ReactRedux.Provider store = {store}>",
" <ConnectedComponent/>",
" </ReactRedux.Provider>",
" );",
" }",
"};",
"ReactDOM.render(<AppWrapper />, document.getElementById('root'))"
]
}
},
"tests": [
"assert((function() { const mockedComponent = Enzyme.mount(React.createElement(AppWrapper)); return mockedComponent.find('Presentational').length === 1; })(), 'message: The <code>Presentational</code> component should render.');",
"assert((function() { const mockedComponent = Enzyme.mount(React.createElement(AppWrapper)); const props = mockedComponent.find('Presentational').props(); return props.messages === '__INITIAL__STATE__'; })(), 'message: The <code>Presentational</code> component should receive a prop <code>messages</code> via <code>connect</code>.');",
"assert((function() { const mockedComponent = Enzyme.mount(React.createElement(AppWrapper)); const props = mockedComponent.find('Presentational').props(); return typeof props.submitNewMessage === 'function'; })(), 'message: The <code>Presentational</code> component should receive a prop <code>submitNewMessage</code> via <code>connect</code>.');"
],
"solutions": [
"const addMessage = (message) => {\n return {\n type: 'ADD',\n message: message\n }\n};\n\nconst mapStateToProps = (state) => {\n return {\n messages: state\n }\n};\n\nconst mapDispatchToProps = (dispatch) => {\n return {\n submitNewMessage: (message) => {\n dispatch(addMessage(message));\n }\n }\n};\n\nclass Presentational extends React.Component {\n constructor(props) {\n super(props);\n }\n render() {\n return <h3>This is a Presentational Component</h3>\n }\n};\n\nconst connect = ReactRedux.connect;\n// change code below this line\n\nconst ConnectedComponent = connect(mapStateToProps, mapDispatchToProps)(Presentational); \n"
],
"type": "modern",
"isRequired": false,
"translations": {},
"reactRedux": true
},
{
"id": "5a24c314108439a4d4036148",
"title": "Connect Redux to the Messages App",
"releasedOn": "December 25, 2017",
"description": [
"Now that you understand how to use <code>connect</code> to connect React to Redux, you can apply what you've learned to your React component that handles messages.",
"In the last lesson, the component you connected to Redux was named <code>Presentational</code>, and this wasn't arbitrary. This term <i>generally</i> refers to React components that are not directly connected to Redux. They are simply responsible for the presentation of UI and do this as a function of the props they receive. By contrast, container components are connected to Redux. These are typically responsible for dispatching actions to the store and often pass store state to child components as props.",
"<hr>",
"The code editor has all the code you've written in this section so far. The only change is that the React component is renamed to <code>Presentational</code>. Create a new component held in a constant called <code>Container</code> that uses <code>connect</code> to connect the <code>Presentational</code> component to Redux. Then, in the <code>AppWrapper</code>, render the React Redux <code>Provider</code> component. Pass <code>Provider</code> the Redux <code>store</code> as a prop and render <code>Container</code> as a child. Once everything is setup, you will see the messages app rendered to the page again."
],
"files": {
"indexjsx": {
"key": "indexjsx",
"ext": "jsx",
"name": "index",
"contents": [
"// Redux:",
"const ADD = 'ADD';",
"",
"const addMessage = (message) => {",
" return {",
" type: ADD,",
" message: message",
" }",
"};",
"",
"const messageReducer = (state = [], action) => {",
" switch (action.type) {",
" case ADD:",
" return [",
" ...state,",
" action.message",
" ];",
" default:",
" return state;",
" }",
"};",
"",
"const store = Redux.createStore(messageReducer);",
"",
"// React:",
"class Presentational extends React.Component {",
" constructor(props) {",
" super(props);",
" this.state = {",
" input: '',",
" messages: []",
" }",
" this.handleChange = this.handleChange.bind(this);",
" this.submitMessage = this.submitMessage.bind(this);",
" }",
" handleChange(event) {",
" this.setState({",
" input: event.target.value",
" });",
" }",
" submitMessage() {",
" const currentMessage = this.state.input;",
" this.setState({",
" input: '',",
" messages: this.state.messages.concat(currentMessage)",
" });",
" }",
" render() {",
" return (",
" <div>",
" <h2>Type in a new Message:</h2>",
" <input",
" value={this.state.input}",
" onChange={this.handleChange}/><br/>",
" <button onClick={this.submitMessage}>Submit</button>",
" <ul>",
" {this.state.messages.map( (message, idx) => {",
" return (",
" <li key={idx}>{message}</li>",
" )",
" })",
" }",
" </ul>",
" </div>",
" );",
" }",
"};",
"",
"// React-Redux:",
"const mapStateToProps = (state) => {",
" return { messages: state }",
"};",
"",
"const mapDispatchToProps = (dispatch) => {",
" return {",
" submitNewMessage: (newMessage) => {",
" dispatch(addMessage(newMessage))",
" }",
" }",
"};",
"",
"const Provider = ReactRedux.Provider;",
"const connect = ReactRedux.connect;",
"",
"// define the Container component here:",
"",
"",
"class AppWrapper extends React.Component {",
" constructor(props) {",
" super(props);",
" }",
" render() {",
" // complete the return statement:",
" return (",
"",
" );",
" }",
"};"
],
"tail": "ReactDOM.render(<AppWrapper />, document.getElementById('root'))"
}
},
"tests": [
"assert((function() { const mockedComponent = Enzyme.mount(React.createElement(AppWrapper)); return mockedComponent.find('AppWrapper').length === 1; })(), 'message: The <code>AppWrapper</code> should render to the page.');",
"assert((function() { const mockedComponent = Enzyme.mount(React.createElement(AppWrapper)); return mockedComponent.find('Presentational').length === 1; })(), 'message: The <code>Presentational</code> component should render an <code>h2</code>, <code>input</code>, <code>button</code>, and <code>ul</code> elements.');",
"assert((function() { const mockedComponent = Enzyme.mount(React.createElement(AppWrapper)); const PresentationalComponent = mockedComponent.find('Presentational'); return ( PresentationalComponent.find('div').length === 1 && PresentationalComponent.find('h2').length === 1 && PresentationalComponent.find('button').length === 1 && PresentationalComponent.find('ul').length === 1 ); })(), 'message: The <code>Presentational</code> component should render an <code>h2</code>, <code>input</code>, <code>button</code>, and <code>ul</code> elements.');",
"assert((function() { const mockedComponent = Enzyme.mount(React.createElement(AppWrapper)); const PresentationalComponent = mockedComponent.find('Presentational'); const props = PresentationalComponent.props(); return Array.isArray(props.messages); })(), 'message: The <code>Presentational</code> component should receive <code>messages</code> from the Redux store as a prop.');",
"assert((function() { const mockedComponent = Enzyme.mount(React.createElement(AppWrapper)); const PresentationalComponent = mockedComponent.find('Presentational'); const props = PresentationalComponent.props(); return typeof props.submitNewMessage === 'function'; })(), 'message: The <code>Presentational</code> component should receive the <code>submitMessage</code> action creator as a prop.');"
],
"solutions": [
"// Redux:\nconst ADD = 'ADD';\n\nconst addMessage = (message) => {\n return {\n type: ADD,\n message: message\n }\n};\n\nconst messageReducer = (state = [], action) => {\n switch (action.type) {\n case ADD:\n return [\n ...state,\n action.message\n ];\n default:\n return state;\n }\n};\n\nconst store = Redux.createStore(messageReducer);\n\n// React:\nclass Presentational extends React.Component {\n constructor(props) {\n super(props);\n this.state = {\n input: '',\n messages: []\n }\n this.handleChange = this.handleChange.bind(this); \n this.submitMessage = this.submitMessage.bind(this); \n }\n handleChange(event) {\n this.setState({\n input: event.target.value\n });\n }\n submitMessage() {\n const currentMessage = this.state.input;\n this.setState({\n input: '',\n messages: this.state.messages.concat(currentMessage)\n });\n }\n render() {\n return (\n <div>\n <h2>Type in a new Message:</h2>\n <input\n value={this.state.input}\n onChange={this.handleChange}/><br/>\n <button onClick={this.submitMessage}>Submit</button>\n <ul>\n {this.state.messages.map( (message, idx) => {\n return (\n <li key={idx}>{message}</li>\n )\n })\n }\n </ul>\n </div>\n );\n }\n};\n\n// React-Redux:\nconst mapStateToProps = (state) => {\n return { messages: state }\n};\n\nconst mapDispatchToProps = (dispatch) => {\n return {\n submitNewMessage: (newMessage) => {\n dispatch(addMessage(newMessage))\n }\n }\n};\n\nconst Provider = ReactRedux.Provider;\nconst connect = ReactRedux.connect;\n\n// define the Container component here:\nconst Container = connect(mapStateToProps, mapDispatchToProps)(Presentational);\n\nclass AppWrapper extends React.Component {\n constructor(props) {\n super(props);\n }\n render() {\n // complete the return statement:\n return (\n <Provider store={store}>\n <Container/>\n </Provider>\n );\n }\n};"
],
"type": "modern",
"isRequired": false,
"translations": {},
"reactRedux": true
},
{
"id": "5a24c314108439a4d4036149",
"title": "Extract Local State into Redux",
"releasedOn": "December 25, 2017",
"description": [
"You're almost done! Recall that you wrote all the Redux code so that Redux could control the state management of your React messages app. Now that Redux is connected, you need to extract the state management out of the <code>Presentational</code> component and into Redux. Currently, you have Redux connected, but you are handling the state locally within the <code>Presentational</code> component.",
"<hr>",
"In the <code>Presentational</code> component, first, remove the <code>messages</code> property in the local <code>state</code>. These messages will be managed by Redux. Next, modify the <code>submitMessage()</code> method so that it dispatches <code>submitNewMessage()</code> from <code>this.props</code>, and pass in the current message input from local <code>state</code> as an argument. Because you removed <code>messages</code> from local state, remove the <code>messages</code> property from the call to <code>this.setState()</code> here as well. Finally, modify the <code>render()</code> method so that it maps over the messages received from <code>props</code> rather than <code>state</code>.",
"Once these changes are made, the app will continue to function the same, except Redux manages the state. This example also illustrates how a component may have local <code>state</code>: your component still tracks user input locally in its own <code>state</code>. You can see how Redux provides a useful state management framework on top of React. You achieved the same result using only React's local state at first, and this is usually possible with simple apps. However, as your apps become larger and more complex, so does your state management, and this is the problem Redux solves."
],
"files": {
"indexjsx": {
"key": "indexjsx",
"ext": "jsx",
"name": "index",
"contents": [
"// Redux:",
"const ADD = 'ADD';",
"",
"const addMessage = (message) => {",
" return {",
" type: ADD,",
" message: message",
" }",
"};",
"",
"const messageReducer = (state = [], action) => {",
" switch (action.type) {",
" case ADD:",
" return [",
" ...state,",
" action.message",
" ];",
" default:",
" return state;",
" }",
"};",
"",
"const store = Redux.createStore(messageReducer);",
"",
"// React:",
"const Provider = ReactRedux.Provider;",
"const connect = ReactRedux.connect;",
"",
"// Change code below this line",
"class Presentational extends React.Component {",
" constructor(props) {",
" super(props);",
" this.state = {",
" input: '',",
" messages: []",
" }",
" this.handleChange = this.handleChange.bind(this);",
" this.submitMessage = this.submitMessage.bind(this);",
" }",
" handleChange(event) {",
" this.setState({",
" input: event.target.value",
" });",
" }",
" submitMessage() {",
" this.setState({",
" input: '',",
" messages: this.state.messages.concat(this.state.input)",
" });",
" }",
" render() {",
" return (",
" <div>",
" <h2>Type in a new Message:</h2>",
" <input",
" value={this.state.input}",
" onChange={this.handleChange}/><br/>",
" <button onClick={this.submitMessage}>Submit</button>",
" <ul>",
" {this.state.messages.map( (message, idx) => {",
" return (",
" <li key={idx}>{message}</li>",
" )",
" })",
" }",
" </ul>",
" </div>",
" );",
" }",
"};",
"// Change code above this line",
"",
"const mapStateToProps = (state) => {",
" return {messages: state}",
"};",
"",
"const mapDispatchToProps = (dispatch) => {",
" return {",
" submitNewMessage: (message) => {",
" dispatch(addMessage(message))",
" }",
" }",
"};",
"",
"const Container = connect(mapStateToProps, mapDispatchToProps)(Presentational);",
"",
"class AppWrapper extends React.Component {",
" render() {",
" return (",
" <Provider store={store}>",
" <Container/>",
" </Provider>",
" );",
" }",
"};"
],
"tail": "ReactDOM.render(<AppWrapper />, document.getElementById('root'))"
}
},
"tests": [
"assert((function() { const mockedComponent = Enzyme.mount(React.createElement(AppWrapper)); return mockedComponent.find('AppWrapper').length === 1; })(), 'message: The <code>AppWrapper</code> should render to the page.');",
"assert((function() { const mockedComponent = Enzyme.mount(React.createElement(AppWrapper)); return mockedComponent.find('Presentational').length === 1; })(), 'message: The <code>Presentational</code> component should render an <code>h2</code>, <code>input</code>, <code>button</code>, and <code>ul</code> elements.');",
"assert((function() { const mockedComponent = Enzyme.mount(React.createElement(AppWrapper)); const PresentationalComponent = mockedComponent.find('Presentational'); return ( PresentationalComponent.find('div').length === 1 && PresentationalComponent.find('h2').length === 1 && PresentationalComponent.find('button').length === 1 && PresentationalComponent.find('ul').length === 1 ); })(), 'message: The <code>Presentational</code> component should render an <code>h2</code>, <code>input</code>, <code>button</code>, and <code>ul</code> elements.');",
"assert((function() { const mockedComponent = Enzyme.mount(React.createElement(AppWrapper)); const PresentationalComponent = mockedComponent.find('Presentational'); const props = PresentationalComponent.props(); return Array.isArray(props.messages); })(), 'message: The <code>Presentational</code> component should receive <code>messages</code> from the Redux store as a prop.');",
"assert((function() { const mockedComponent = Enzyme.mount(React.createElement(AppWrapper)); const PresentationalComponent = mockedComponent.find('Presentational'); const props = PresentationalComponent.props(); return typeof props.submitNewMessage === 'function'; })(), 'message: The <code>Presentational</code> component should receive the <code>submitMessage</code> action creator as a prop.');",
"assert((function() { const mockedComponent = Enzyme.mount(React.createElement(AppWrapper)); const PresentationalState = mockedComponent.find('Presentational').instance().state; return typeof PresentationalState.input === 'string' && Object.keys(PresentationalState).length === 1; })(), 'message: The state of the <code>Presentational</code> component should contain one property, <code>input</code>, which is initialized to an empty string.');",
"async () => { const mockedComponent = Enzyme.mount(React.createElement(AppWrapper)); const testValue = '__MOCK__INPUT__'; const waitForIt = (fn) => new Promise((resolve, reject) => setTimeout(() => resolve(fn()), 100)); const causeChange = (c, v) => c.find('input').simulate('change', { target: { value: v }}); let initialInput = mockedComponent.find('Presentational').find('input'); const changed = () => { causeChange(mockedComponent, testValue); return waitForIt(() => mockedComponent )}; const updated = await changed(); const updatedInput = updated.find('Presentational').find('input'); assert(initialInput.props().value === '' && updatedInput.props().value === '__MOCK__INPUT__', 'message: Typing in the <code>input</code> element should update the state of the <code>Presentational</code> component.'); }; ",
"async () => { const mockedComponent = Enzyme.mount(React.createElement(AppWrapper)); const waitForIt = (fn) => new Promise((resolve, reject) => setTimeout(() => resolve(fn()), 100)); let beforeProps = mockedComponent.find('Presentational').props(); const testValue = '__TEST__EVENT__INPUT__'; const causeChange = (c, v) => c.find('input').simulate('change', { target: { value: v }}); const changed = () => { causeChange(mockedComponent, testValue); return waitForIt(() => mockedComponent )}; const clickButton = () => { mockedComponent.find('button').simulate('click'); return waitForIt(() => mockedComponent )}; const afterChange = await changed(); const afterChangeInput = afterChange.find('input').props().value; const afterClick = await clickButton(); const afterProps = mockedComponent.find('Presentational').props(); assert(beforeProps.messages.length === 0 && afterChangeInput === testValue && afterProps.messages.pop() === testValue && afterClick.find('input').props().value === '', 'message: Dispatching the <code>submitMessage</code> on the <code>Presentational</code> component should update Redux store and clear the input in local state.'); }; ",
"async () => { const mockedComponent = Enzyme.mount(React.createElement(AppWrapper)); const waitForIt = (fn) => new Promise((resolve, reject) => setTimeout(() => resolve(fn()), 100)); let beforeProps = mockedComponent.find('Presentational').props(); const testValue = '__TEST__EVENT__INPUT__'; const causeChange = (c, v) => c.find('input').simulate('change', { target: { value: v }}); const changed = () => { causeChange(mockedComponent, testValue); return waitForIt(() => mockedComponent )}; const clickButton = () => { mockedComponent.find('button').simulate('click'); return waitForIt(() => mockedComponent )}; const afterChange = await changed(); const afterChangeInput = afterChange.find('input').props().value; const afterClick = await clickButton(); const afterProps = mockedComponent.find('Presentational').props(); assert(beforeProps.messages.length === 0 && afterChangeInput === testValue && afterProps.messages.pop() === testValue && afterClick.find('input').props().value === '' && afterClick.find('ul').childAt(0).text() === testValue, 'message: The <code>Presentational</code> component should render the <code>messages</code> from the Redux store.'); }; "
],
"solutions": [
"// Redux:\nconst ADD = 'ADD';\n\nconst addMessage = (message) => {\n return {\n type: ADD,\n message: message\n }\n};\n\nconst messageReducer = (state = [], action) => {\n switch (action.type) {\n case ADD:\n return [\n ...state,\n action.message\n ];\n default:\n return state;\n }\n};\n\nconst store = Redux.createStore(messageReducer);\n\n// React:\nconst Provider = ReactRedux.Provider;\nconst connect = ReactRedux.connect;\n\n// Change code below this line\nclass Presentational extends React.Component {\n constructor(props) {\n super(props);\n this.state = {\n input: ''\n }\n this.handleChange = this.handleChange.bind(this); \n this.submitMessage = this.submitMessage.bind(this); \n }\n handleChange(event) {\n this.setState({\n input: event.target.value\n });\n }\n submitMessage() {\n this.props.submitNewMessage(this.state.input);\n this.setState({\n input: ''\n });\n }\n render() {\n return (\n <div>\n <h2>Type in a new Message:</h2>\n <input\n value={this.state.input}\n onChange={this.handleChange}/><br/>\n <button onClick={this.submitMessage}>Submit</button>\n <ul>\n {this.props.messages.map( (message, idx) => {\n return (\n <li key={idx}>{message}</li>\n )\n })\n }\n </ul>\n </div>\n );\n }\n};\n// Change code above this line\n\nconst mapStateToProps = (state) => {\n return {messages: state}\n};\n\nconst mapDispatchToProps = (dispatch) => {\n return {\n submitNewMessage: (message) => {\n dispatch(addMessage(message))\n }\n }\n};\n\nconst Container = connect(mapStateToProps, mapDispatchToProps)(Presentational);\n\nclass AppWrapper extends React.Component {\n render() {\n return (\n <Provider store={store}>\n <Container/>\n </Provider>\n );\n }\n};"
],
"type": "modern",
"isRequired": false,
"translations": {},
"reactRedux": true
},
{
"id": "5a24c314108439a4d403614a",
"title": "Moving Forward From Here",
"releasedOn": "December 25, 2017",
"description": [
"Congratulations! You finished the lessons on React and Redux. There's one last item worth pointing out before you move on. Typically, you won't write React apps in a code editor like this. This challenge gives you a glimpse of what the syntax looks like if you're working with npm and a file system on your own machine. The code should look similar, except for the use of <code>import</code> statements (these pull in all of the dependencies that have been provided for you in the challenges). The \"Managing Packages with npm\" section covers npm in more detail.",
"Finally, writing React and Redux code generally requires some configuration. This can get complicated quickly. If you are interested in experimenting on your own machine, the",
"<a id='CRA' target ='_blank' href='https://github.com/facebookincubator/create-react-app'>Create React App</a> comes configured and ready to go.",
"Alternatively, you can enable Babel as a JavaScript Preprocessor in CodePen, add React and ReactDOM as external JavaScript resources, and work there as well.",
"<hr>",
"Log the message <code>'Now I know React and Redux!'</code> to the console."
],
"files": {
"indexjsx": {
"key": "indexjsx",
"ext": "jsx",
"name": "index",
"contents": [
"// import React from 'react'",
"// import ReactDOM from 'react-dom'",
"// import { Provider, connect } from 'react-redux'",
"// import { createStore, combineReducers, applyMiddleware } from 'redux'",
"// import thunk from 'redux-thunk'",
"",
"// import rootReducer from './redux/reducers'",
"// import App from './components/App'",
"",
"// const store = createStore(",
"// rootReducer,",
"// applyMiddleware(thunk)",
"// );",
"",
"// ReactDOM.render(",
"// <Provider store={store}>",
"// <App/>",
"// </Provider>,",
"// document.getElementById('root')",
"// );",
"",
"// change code below this line",
""
]
}
},
"tests": [
"assert(editor.getValue().includes('console.log(\"Now I know React and Redux!\")') || editor.getValue().includes('console.log(\\'Now I know React and Redux!\\')'), 'message: The message <code>Now I know React and Redux!</code> should be logged to the console.');"
],
"solutions": [
"console.log('Now I know React and Redux!');"
2017-01-17 04:44:38 +00:00
],
Feat: react redux migration (#16200) * feat: crudely enables test to run solution code against React challenge (and passes!) * feat: Updates comment * feat: Adds React 2 and 3, validates challenges in app * feat: Adds React 4, validates tests * feat: Adds Peter's migrated challenge seed files for all challenges * feat: Adds redux, react-redux imports, adds tests for React 7, * feat: Adds tests for React 08 * fix(challenges): wrap reserved words in <code> and add tests * feat: complete first two tests for React 9 * feat: modifies tests in React 09 * feat: Adds working tests for React 37, including async setState tests * feat: Escape hatch to avoid async tests in automated test suite * feat: Updates React 15 with working tests * feat: build passes, yay * feat: Provisions original code string in challenges and adds tests for React Redux 01 * fix(tests): add self-closing tags challenge, other small fixes * fix(challenge): add react_10, some other stuff * fix(challenges): update react 22, add react 23 * fix(challenges): react 5 and react 8 * feat: removes dependencies that will break in browser, will replace later * feat: fix build * feat: add redux 1 * fix(challenge): add react 24 tests * feat: partial implemented Redux 2 * feat: migrate redux 3 * feat: Adds React-Redux 04 with working tests under npm test * feat: Updates automated test runner, just provide all the dependencies. Adds Redux-Thunk. * feat: Adds working tests for React Redux 07 * feat: redux challenge 4 * feat: migrate redux 5 * feat: redux 6 * feat: migrate Redux test 7 * fix(challenge): add react 25 tests * feat: Adds tests for React 48, npm test does not pass... * feat: Migrate Redux test 8 * fix(challenges): skip 26, add react 27 tests * fix(challenges): add react 28 tests, replace function w/ => throughout, fix linter warnings * feat: fixes (patches) hard to understand problem with automated test suite * feat: updates async tests patch * feat: adds converted tests for React 47 * feat: adds converted tests for React 46 * feat: Partially adds tests for React 43 * docs: adds TO-DO tests for React 43 * feat: migrates tests for React 42 * feat: migrates tests for React 41 * feat: migrates tests for React 39 * feat: Migrates tests for React 38, automated test script fails again! * feat: migrates tests for React 32 * feat: QAs more React Redux challenge in FCC UI * feat: Updates tests for React 7 * feat: Migrates React-Redux 3 tests and hardcodes deep-freeze dependency * feat: migrates React Redux 05 tests * feat: migrates React Redux 06 tests * feat: Migrates React Redux 10 * feat: Migrates tests for React 16 * feat: Migrates React 17 tests * feat: Migrates React 18 tests * feat: Migrates React 19 tests * feat: Migrates React 19 tests * feat: fixing usage of code, replace with editor.getOriginalCode * feat: Migrates React 21 tests * feat: Finishes migration of React 09 * fix(challenges): add react 45 tests 💀 * feat: Adds React 11 tests * feat: Migrates React 50 tests * feat: Re-enables original code in FCC editor, QAs challenges blocked by original code * feat: hacks head tail code in editor test environment * feat: updates React 20 head code * feat: QAs React Redux 07 in UI * fix(challenges): add React 29 tests * fix(challenges): add React 30 tests * feat: updates async tests * feat: Migrates React 12, gets ReactDOM challenges working and QAs them * feat: Migrates React 13 tests * feat: Migrates tests for React 14 and updates challenge description formatting * feat: Refactors 2nd test for Redux 02 * feat: Migrates React 33 * feat: Removes React 26 and 43 * feat: Adds React 34 from Kevin * fix(challenges): add React 31 & 35 tests (thanks Kevin) * feat: Migrate Redux challenge 10 - pass both UI QA and terminal test * fix(challenge): add react 40 tests * feat: Migrates React Redux 02 tests * feat: Migrates React Redux 08 and fixes async syntax in React challenge * fix(challenge): add react 49 tests with caveat * feat: fixes React 49 tests and adds first tests for React Redux 09 * feat: Migrate Redux 11 - pass both terminal test and UI test * feat: Migrate Redux 12 - passing both UI test and terminal test * feat: Migrate Redux 13 - passing both terminal and UI tests * feat: Adding in code tags for previous redux challenges - terminal and UI tests pass * feat: Migrates React Redux 09 and React 44 (thanks Kevin) * feat: fix code tag issues - passed UI and terminal tests * feat: Migrates Redux 14 tests * feat: Migrates Redux 14 * feat: Migrates Redux 15 * feat: Migrates Redux 17 * feat: Final migration and QA of Redux, except for Redux 9 * feat: migrates React 36 and QAs * feat: Rewrites Redux 09 and migrates * feat: refactors pull request and cleans up code * style(challenges): QA React challenges * style(challenges): QA react challenges * fix(challenges): fix react 41 and 45 tests * style(challenges): QA redux challenges * style(challenges): QA react and redux challenges * fix(seed/react): Move head/tail to files * fix(seed/redux): Move head/tail to file level * chore(packages): Move jsdom to dev deps * fix(seed/react/redux): Async funcs make async func defined * fix(seed): %s/editor.getUserCode/getUserInput/gc * fix(Challenges/build): Make sure head/tail is bundled and transformed * feat(Challenges.react): Add tail to render component * chore(seed): Disable modern challenge testing for now We will put these on beta while we update the auto testing framework
2017-12-18 21:04:03 +00:00
"type": "modern",
2017-01-17 04:44:38 +00:00
"isRequired": false,
Feat: react redux migration (#16200) * feat: crudely enables test to run solution code against React challenge (and passes!) * feat: Updates comment * feat: Adds React 2 and 3, validates challenges in app * feat: Adds React 4, validates tests * feat: Adds Peter's migrated challenge seed files for all challenges * feat: Adds redux, react-redux imports, adds tests for React 7, * feat: Adds tests for React 08 * fix(challenges): wrap reserved words in <code> and add tests * feat: complete first two tests for React 9 * feat: modifies tests in React 09 * feat: Adds working tests for React 37, including async setState tests * feat: Escape hatch to avoid async tests in automated test suite * feat: Updates React 15 with working tests * feat: build passes, yay * feat: Provisions original code string in challenges and adds tests for React Redux 01 * fix(tests): add self-closing tags challenge, other small fixes * fix(challenge): add react_10, some other stuff * fix(challenges): update react 22, add react 23 * fix(challenges): react 5 and react 8 * feat: removes dependencies that will break in browser, will replace later * feat: fix build * feat: add redux 1 * fix(challenge): add react 24 tests * feat: partial implemented Redux 2 * feat: migrate redux 3 * feat: Adds React-Redux 04 with working tests under npm test * feat: Updates automated test runner, just provide all the dependencies. Adds Redux-Thunk. * feat: Adds working tests for React Redux 07 * feat: redux challenge 4 * feat: migrate redux 5 * feat: redux 6 * feat: migrate Redux test 7 * fix(challenge): add react 25 tests * feat: Adds tests for React 48, npm test does not pass... * feat: Migrate Redux test 8 * fix(challenges): skip 26, add react 27 tests * fix(challenges): add react 28 tests, replace function w/ => throughout, fix linter warnings * feat: fixes (patches) hard to understand problem with automated test suite * feat: updates async tests patch * feat: adds converted tests for React 47 * feat: adds converted tests for React 46 * feat: Partially adds tests for React 43 * docs: adds TO-DO tests for React 43 * feat: migrates tests for React 42 * feat: migrates tests for React 41 * feat: migrates tests for React 39 * feat: Migrates tests for React 38, automated test script fails again! * feat: migrates tests for React 32 * feat: QAs more React Redux challenge in FCC UI * feat: Updates tests for React 7 * feat: Migrates React-Redux 3 tests and hardcodes deep-freeze dependency * feat: migrates React Redux 05 tests * feat: migrates React Redux 06 tests * feat: Migrates React Redux 10 * feat: Migrates tests for React 16 * feat: Migrates React 17 tests * feat: Migrates React 18 tests * feat: Migrates React 19 tests * feat: Migrates React 19 tests * feat: fixing usage of code, replace with editor.getOriginalCode * feat: Migrates React 21 tests * feat: Finishes migration of React 09 * fix(challenges): add react 45 tests 💀 * feat: Adds React 11 tests * feat: Migrates React 50 tests * feat: Re-enables original code in FCC editor, QAs challenges blocked by original code * feat: hacks head tail code in editor test environment * feat: updates React 20 head code * feat: QAs React Redux 07 in UI * fix(challenges): add React 29 tests * fix(challenges): add React 30 tests * feat: updates async tests * feat: Migrates React 12, gets ReactDOM challenges working and QAs them * feat: Migrates React 13 tests * feat: Migrates tests for React 14 and updates challenge description formatting * feat: Refactors 2nd test for Redux 02 * feat: Migrates React 33 * feat: Removes React 26 and 43 * feat: Adds React 34 from Kevin * fix(challenges): add React 31 & 35 tests (thanks Kevin) * feat: Migrate Redux challenge 10 - pass both UI QA and terminal test * fix(challenge): add react 40 tests * feat: Migrates React Redux 02 tests * feat: Migrates React Redux 08 and fixes async syntax in React challenge * fix(challenge): add react 49 tests with caveat * feat: fixes React 49 tests and adds first tests for React Redux 09 * feat: Migrate Redux 11 - pass both terminal test and UI test * feat: Migrate Redux 12 - passing both UI test and terminal test * feat: Migrate Redux 13 - passing both terminal and UI tests * feat: Adding in code tags for previous redux challenges - terminal and UI tests pass * feat: Migrates React Redux 09 and React 44 (thanks Kevin) * feat: fix code tag issues - passed UI and terminal tests * feat: Migrates Redux 14 tests * feat: Migrates Redux 14 * feat: Migrates Redux 15 * feat: Migrates Redux 17 * feat: Final migration and QA of Redux, except for Redux 9 * feat: migrates React 36 and QAs * feat: Rewrites Redux 09 and migrates * feat: refactors pull request and cleans up code * style(challenges): QA React challenges * style(challenges): QA react challenges * fix(challenges): fix react 41 and 45 tests * style(challenges): QA redux challenges * style(challenges): QA react and redux challenges * fix(seed/react): Move head/tail to files * fix(seed/redux): Move head/tail to file level * chore(packages): Move jsdom to dev deps * fix(seed/react/redux): Async funcs make async func defined * fix(seed): %s/editor.getUserCode/getUserInput/gc * fix(Challenges/build): Make sure head/tail is bundled and transformed * feat(Challenges.react): Add tail to render component * chore(seed): Disable modern challenge testing for now We will put these on beta while we update the auto testing framework
2017-12-18 21:04:03 +00:00
"translations": {},
"reactRedux": true
2017-01-17 04:44:38 +00:00
}
]
Feat: react redux migration (#16200) * feat: crudely enables test to run solution code against React challenge (and passes!) * feat: Updates comment * feat: Adds React 2 and 3, validates challenges in app * feat: Adds React 4, validates tests * feat: Adds Peter's migrated challenge seed files for all challenges * feat: Adds redux, react-redux imports, adds tests for React 7, * feat: Adds tests for React 08 * fix(challenges): wrap reserved words in <code> and add tests * feat: complete first two tests for React 9 * feat: modifies tests in React 09 * feat: Adds working tests for React 37, including async setState tests * feat: Escape hatch to avoid async tests in automated test suite * feat: Updates React 15 with working tests * feat: build passes, yay * feat: Provisions original code string in challenges and adds tests for React Redux 01 * fix(tests): add self-closing tags challenge, other small fixes * fix(challenge): add react_10, some other stuff * fix(challenges): update react 22, add react 23 * fix(challenges): react 5 and react 8 * feat: removes dependencies that will break in browser, will replace later * feat: fix build * feat: add redux 1 * fix(challenge): add react 24 tests * feat: partial implemented Redux 2 * feat: migrate redux 3 * feat: Adds React-Redux 04 with working tests under npm test * feat: Updates automated test runner, just provide all the dependencies. Adds Redux-Thunk. * feat: Adds working tests for React Redux 07 * feat: redux challenge 4 * feat: migrate redux 5 * feat: redux 6 * feat: migrate Redux test 7 * fix(challenge): add react 25 tests * feat: Adds tests for React 48, npm test does not pass... * feat: Migrate Redux test 8 * fix(challenges): skip 26, add react 27 tests * fix(challenges): add react 28 tests, replace function w/ => throughout, fix linter warnings * feat: fixes (patches) hard to understand problem with automated test suite * feat: updates async tests patch * feat: adds converted tests for React 47 * feat: adds converted tests for React 46 * feat: Partially adds tests for React 43 * docs: adds TO-DO tests for React 43 * feat: migrates tests for React 42 * feat: migrates tests for React 41 * feat: migrates tests for React 39 * feat: Migrates tests for React 38, automated test script fails again! * feat: migrates tests for React 32 * feat: QAs more React Redux challenge in FCC UI * feat: Updates tests for React 7 * feat: Migrates React-Redux 3 tests and hardcodes deep-freeze dependency * feat: migrates React Redux 05 tests * feat: migrates React Redux 06 tests * feat: Migrates React Redux 10 * feat: Migrates tests for React 16 * feat: Migrates React 17 tests * feat: Migrates React 18 tests * feat: Migrates React 19 tests * feat: Migrates React 19 tests * feat: fixing usage of code, replace with editor.getOriginalCode * feat: Migrates React 21 tests * feat: Finishes migration of React 09 * fix(challenges): add react 45 tests 💀 * feat: Adds React 11 tests * feat: Migrates React 50 tests * feat: Re-enables original code in FCC editor, QAs challenges blocked by original code * feat: hacks head tail code in editor test environment * feat: updates React 20 head code * feat: QAs React Redux 07 in UI * fix(challenges): add React 29 tests * fix(challenges): add React 30 tests * feat: updates async tests * feat: Migrates React 12, gets ReactDOM challenges working and QAs them * feat: Migrates React 13 tests * feat: Migrates tests for React 14 and updates challenge description formatting * feat: Refactors 2nd test for Redux 02 * feat: Migrates React 33 * feat: Removes React 26 and 43 * feat: Adds React 34 from Kevin * fix(challenges): add React 31 & 35 tests (thanks Kevin) * feat: Migrate Redux challenge 10 - pass both UI QA and terminal test * fix(challenge): add react 40 tests * feat: Migrates React Redux 02 tests * feat: Migrates React Redux 08 and fixes async syntax in React challenge * fix(challenge): add react 49 tests with caveat * feat: fixes React 49 tests and adds first tests for React Redux 09 * feat: Migrate Redux 11 - pass both terminal test and UI test * feat: Migrate Redux 12 - passing both UI test and terminal test * feat: Migrate Redux 13 - passing both terminal and UI tests * feat: Adding in code tags for previous redux challenges - terminal and UI tests pass * feat: Migrates React Redux 09 and React 44 (thanks Kevin) * feat: fix code tag issues - passed UI and terminal tests * feat: Migrates Redux 14 tests * feat: Migrates Redux 14 * feat: Migrates Redux 15 * feat: Migrates Redux 17 * feat: Final migration and QA of Redux, except for Redux 9 * feat: migrates React 36 and QAs * feat: Rewrites Redux 09 and migrates * feat: refactors pull request and cleans up code * style(challenges): QA React challenges * style(challenges): QA react challenges * fix(challenges): fix react 41 and 45 tests * style(challenges): QA redux challenges * style(challenges): QA react and redux challenges * fix(seed/react): Move head/tail to files * fix(seed/redux): Move head/tail to file level * chore(packages): Move jsdom to dev deps * fix(seed/react/redux): Async funcs make async func defined * fix(seed): %s/editor.getUserCode/getUserInput/gc * fix(Challenges/build): Make sure head/tail is bundled and transformed * feat(Challenges.react): Add tail to render component * chore(seed): Disable modern challenge testing for now We will put these on beta while we update the auto testing framework
2017-12-18 21:04:03 +00:00
}