Git Product home page Git Product logo

redux-create-store's Issues

render() needs to be fixed.

state isn't accessible with the example render function below.
function render() {
let container = document.getElementById('container');
container.textContent = store.getState.count;
};

instead I had to invoke store.getState function first then access .count to render current state to DOM.

Thank you!

The errors in this lab really should be fixed

there seems to be some errors here and apparently the lab hasn't been updated even though problems have been noted since at least September. Below might not be the perfect solution but this is how I get the lab to actually run.

Line 13: dispatch({type: '@@init'}) leaving this here throws a store not defined error - the store is created on Line 37 so calling this for the first time within createStore seems to throw an error that I think is calling dispatch on a store that hasn't initialized yet.

To fix this error i called store.dispatch({type: '@@init'}) outside of the createStore function, directly on line 38 (after the store = createStore function) This allows for the DOM to show a state of zero on a page reload.

But for the DOM to display at all we need to fix the Render function. It doesn't render anything because you need to call the function on line 34 - it should be store.getState() which would give you {count: number}...so store.getState().count gives you the number for the DOM

function createStore(reducer) {
let state;

function dispatch(action) {
state = reducer(state, action);
render();
}

function getState() {
return state;
};

return {
dispatch,
getState
};
};

function changeCount(state = { count: 0 }, action) {
switch (action.type) {
case 'INCREASE_COUNT':
return { count: state.count + 1 };

default:
  return state;

}
}

function render() {
let container = document.getElementById('container');
container.textContent = store.getState().count;
};

let store = createStore(changeCount) // createStore takes the changeCount reducer as an argument
store.dispatch({type: '@@init'})

let button = document.getElementById('button');

button.addEventListener('click', function() {
store.dispatch({ type: 'INCREASE_COUNT' });
});

Code still doesn't work

The solution code passes the test but doesn't work in the browser. When I paste in the solution code and run open index.html, the console presents me with this error Uncaught SyntaxError: Unexpected identifier. Please provide a better lab.

the code is not working

I was following alone and the final code is giving an error:
ReferenceError: store is not defined
at render (reducer_old.js:34)
at dispatch (reducer_old.js:6)
at createStore (reducer_old.js:13)
at reducer_old.js:37

Please fix.

Learn Submit Doesn't Work....

Not necessarily a big deal since you can just commit and push with regular Git commands, but for some reason the 'learn submit' command doesn't work. Not sure why this might be since all the previous codealongs in this section work fine and look the same. Only thing that I see that's different is the version in the package.json file (this one is 0.1.0 vs. 1.0.0 in the previous). Here's the error message on attempting to submit:

Screen Shot 2020-05-30 at 10 26 26 PM

This code does not work

I copied and pasted the code and get the error that within render() store is not defined.

Main code file referenced incorrectly.

Use js/reducer.js to follow along. Open index.html to try out the code.

reducer.js should be createStore.js, as that is the main code file in the repo.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.