Skip to content

Commit

Permalink
chore(devtools): disabled redux-devtools for that it's still buggy an…
Browse files Browse the repository at this point in the history
…d causing issues
  • Loading branch information
Jeremy Lu committed Jul 28, 2015
1 parent 1cbb1da commit 6998c46
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
9 changes: 6 additions & 3 deletions js/boot.js
Expand Up @@ -28,13 +28,16 @@ if( window.reduxState ){
const composedReducers = combineReducers(reducers);

// 加掛上 reudx-devtools
var cs = compose(
// buggy, disabled for now @Jul 28, 2015 16:54
/*var cs = compose(
devTools(),
persistState(window.location.href.match(/[?&]debug_session=([^&]+)\b/)),
// persistState(window.location.href.match(/[?&]debug_session=([^&]+)\b/)),
createStore);
const finalCreateStore = applyMiddleware( promiseMiddleware )(cs);*/

// 由於要用 Promise middleware,因此改用 applyMiddleware()
const finalCreateStore = applyMiddleware( promiseMiddleware )(cs);
const finalCreateStore = applyMiddleware( promiseMiddleware )(createStore);

let store = finalCreateStore(composedReducers, state);

Expand Down
2 changes: 2 additions & 0 deletions js/components/AppWrap.jsx
Expand Up @@ -26,6 +26,8 @@ export default class AppWrap extends Component {
</DebugPanel>
}

tool = null;

// <Provider> 唯一功能就是將 store 放入 context 供 <Connector> 取用
return (
<div>
Expand Down
8 changes: 5 additions & 3 deletions js/reducers/carts.js
Expand Up @@ -13,6 +13,8 @@ const initialState = {

export default function carts( state = initialState, action ) {

// console.log( 'action.type: ', action.type );

switch ( action.type ) {

case ADD_TO_CART:
Expand All @@ -22,11 +24,11 @@ export default function carts( state = initialState, action ) {
var product = action.product;
var id = product.id;

if(id in state.products) {
state.products[id].quantity++;
if( state.products.indexOf(product) != -1) {
product.quantity++;
}else{
product.quantity = 1;
state.products[product.id] = product;
state.products.push(product);
}

product.inventory--;
Expand Down

2 comments on commit 6998c46

@gaearon
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's likely that the problem was caused by some anti-patterns in the reducer code: mutating state and action. #9

@roth1002
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.