Skip to content

Commit

Permalink
refactor file structure
Browse files Browse the repository at this point in the history
  • Loading branch information
jarvisaoieong committed Feb 24, 2016
1 parent 912cef9 commit ec95f17
Show file tree
Hide file tree
Showing 43 changed files with 51 additions and 44 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Redux is awesome. In order to make redux architecture fractal. We only need two

2. Don't use `bindActionCreators`, just pass `dispatch` as the parameter to the components.

What the component needed is model (the data) and dispatch (a way to communicate with the rest architecture). It doesnt need the action callback as the parameters. It is an implementation detail that encapsulated by the reducer. IMO, a truly reusable component module was made by View, action, reducer, effect, init. Not just the component view.
What the component needed is model (the data) and dispatch (a way to communicate with the rest architecture). It doesnt need the action callback as the parameters.

This repo is port of the elm architecture examples in redux with redux-loop to show the benefits of hierarchical composition everywhere. In this example, I used my fork of [redux-loop](https://github.com/jarvisaoieong/redux-loop) and [redux-logger](https://github.com/jarvisaoieong/redux-logger) to demonstrate how to log the high order action and async action. (Please open the console in the [live demo](http://jarvisaoieong.github.io/redux-architecture/).)

Expand Down
2 changes: 1 addition & 1 deletion src/containers/CounterContainer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {connect} from 'react-redux';
import Counter from 'components/counter/Counter';
import Counter from 'modules/counter/Counter';

export default connect(
(state) => ({
Expand Down
2 changes: 1 addition & 1 deletion src/containers/CounterFancyContainer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {connect} from 'react-redux';
import CounterFancy from 'components/counterFancy/CounterFancy';
import CounterFancy from 'modules/counterFancy/CounterFancy';

export default connect(
(state) => ({
Expand Down
2 changes: 1 addition & 1 deletion src/containers/CounterListContainer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {connect} from 'react-redux';
import CounterList from 'components/counterList/CounterList';
import CounterList from 'modules/counterList/CounterList';

export default connect(
(state) => ({
Expand Down
2 changes: 1 addition & 1 deletion src/containers/CounterPairContainer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {connect} from 'react-redux';
import CounterPair from 'components/counterPair/CounterPair';
import CounterPair from 'modules/counterPair/CounterPair';

export default connect(
(state) => ({
Expand Down
2 changes: 1 addition & 1 deletion src/containers/RandomGifContainer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {connect} from 'react-redux';
import RandomGif from 'components/randomGif/RandomGif';
import RandomGif from 'modules/randomGif/RandomGif';

export default connect(
(state) => ({
Expand Down
2 changes: 1 addition & 1 deletion src/containers/RandomGifListContainer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {connect} from 'react-redux';
import RandomGifList from 'components/randomGifList/RandomGifList';
import RandomGifList from 'modules/randomGifList/RandomGifList';

export default connect(
(state) => ({
Expand Down
2 changes: 1 addition & 1 deletion src/containers/RandomGifPairContainer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {connect} from 'react-redux';
import RandomGifPair from 'components/randomGifPair/RandomGifPair';
import RandomGifPair from 'modules/randomGifPair/RandomGifPair';

export default connect(
(state) => ({
Expand Down
6 changes: 3 additions & 3 deletions src/initialState.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {loop, Effects} from '@jarvisaoieong/redux-loop';

import randomGifInit from 'components/randomGif/randomGifInit';
import randomGifPairInit from 'components/randomGifPair/randomGifPairInit';
import randomGifListInit from 'components/randomGifList/randomGifListInit';
import randomGifInit from 'modules/randomGif/randomGifInit';
import randomGifPairInit from 'modules/randomGifPair/randomGifPairInit';
import randomGifListInit from 'modules/randomGifList/randomGifListInit';

const {
model: randomGifModel,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, {Component} from 'react';

import Counter from 'components/counter/Counter'
import Counter from 'modules/counter/Counter'
import {remove, modify} from './counterFancyActions';

export default class CounterWithRemoveButton extends Component {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import counterInit from 'components/counter/counterInit';
import counterInit from 'modules/counter/counterInit';

export default (count) => ({
counters: [{id: 0, data: counterInit(count)}],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {ADD, REMOVE, MODIFY} from './counterFancyActions';
import _ from 'lodash';
import counterReducer, {initialState as counterInitialState} from 'components/counter/counterReducer';
import counterInit from 'components/counter/counterInit';
import counterReducer, {initialState as counterInitialState} from 'modules/counter/counterReducer';
import counterInit from 'modules/counter/counterInit';

export const initialState = {
counters: [{id: 0, data: counterInitialState}],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, {Component} from 'react';
import _ from 'lodash';

import Counter from 'components/counter/Counter'
import Counter from 'modules/counter/Counter'
import {add, modify, remove} from './counterListActions';

export default class CounterList extends Component {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import counterInit from 'components/counter/counterInit';
import counterInit from 'modules/counter/counterInit';

export default (count) => ({
counters: [{id: 0, data: counterInit(count)}],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {ADD, REMOVE, MODIFY} from './counterListActions';
import _ from 'lodash';
import counterReducer, {initialState as counterInitialState} from 'components/counter/counterReducer';
import counterInit from 'components/counter/counterInit';
import counterReducer, {initialState as counterInitialState} from 'modules/counter/counterReducer';
import counterInit from 'modules/counter/counterInit';

export const initialState = {
counters: [{id: 0, data: counterInitialState}],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, {Component} from 'react';

import Counter from 'components/counter/Counter'
import Counter from 'modules/counter/Counter'
import {modifyFirst, modifySecond} from './counterPairActions';

export default class CounterPair extends Component {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import counterInit from 'components/counter/counterInit';
import counterInit from 'modules/counter/counterInit';

export default (first, second) => ({
first: counterInit(first),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {MODIFY_FIRST, MODIFY_SECOND} from './counterPairActions';
import counterReducer, {initialState as counterInitialState} from 'components/counter/counterReducer';
import counterReducer, {initialState as counterInitialState} from 'modules/counter/counterReducer';

export const initialState = {
first: counterInitialState,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, {Component} from 'react';
import _ from 'lodash';

import RandomGif from 'components/randomGif/RandomGif'
import RandomGif from 'modules/randomGif/RandomGif'
import {create, modify} from './randomGifListActions';

export default class RandomGifList extends Component {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import _ from 'lodash';
import {loop, Effects} from '@jarvisaoieong/redux-loop';
import randomGifInit from 'components/randomGif/randomGifInit';
import randomGifInit from 'modules/randomGif/randomGifInit';
import {modify} from './randomGifListActions';

export default (topicList = []) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import _ from 'lodash';
import {loop, Effects} from '@jarvisaoieong/redux-loop';
import randomGifReducer, {initialState as randomGifInitialState} from 'components/randomGif/randomGifReducer';
import randomGifReducer, {initialState as randomGifInitialState} from 'modules/randomGif/randomGifReducer';
import {CREATE, MODIFY, modify} from './randomGifListActions';
import randomGifInit from 'components/randomGif/randomGifInit';
import randomGifInit from 'modules/randomGif/randomGifInit';

export const initialState = {
gifList: [{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, {Component} from 'react';

import RandomGif from 'components/randomGif/RandomGif'
import RandomGif from 'modules/randomGif/RandomGif'
import {modifyFirst, modifySecond} from './randomGifPairActions';

export default class RandomGifPair extends Component {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {loop, Effects} from '@jarvisaoieong/redux-loop';

import randomGifInit from 'components/randomGif/randomGifInit';
import randomGifInit from 'modules/randomGif/randomGifInit';
import {modifyFirst, modifySecond} from './randomGifPairActions';

export default (firstTopic, secondTopic) => {
Expand All @@ -9,7 +9,6 @@ export default (firstTopic, secondTopic) => {
effect: firstEffect,
} = randomGifInit(firstTopic);


const {
model: secondModel,
effect: secondEffect,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {

import randomGifReducer, {
initialState as randomGifInitialState,
} from 'components/randomGif/randomGifReducer';
} from 'modules/randomGif/randomGifReducer';

const initialState = {
first: randomGifInitialState,
Expand Down
7 changes: 0 additions & 7 deletions src/reducers/index.js

This file was deleted.

11 changes: 4 additions & 7 deletions src/store/configureStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,17 @@ import {createStore, applyMiddleware, compose} from 'redux';
import {combineReducers, install} from '@jarvisaoieong/redux-loop';
import createLogger from '@jarvisaoieong/redux-logger';

import * as reducers from '../reducers';
import reducer from './reducer';

export default function configureStore({initialState}) {
const reducer = combineReducers(reducers);

const store = createStore(reducer, initialState, compose(
install(),
applyMiddleware(createLogger({collapsed: true}))
applyMiddleware(createLogger({collapsed: true})),
));

if (process.env.NODE_ENV === 'development' && module.hot) {
module.hot.accept('../reducers', () => {
const nextReducers = require('../reducers');
const nextReducer = combineReducers(nextReducers);
module.hot.accept('./reducer', () => {
const nextReducer = require('./reducer');
store.replaceReducer(nextReducer);
});
}
Expand Down
18 changes: 18 additions & 0 deletions src/store/reducer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {combineReducers} from '@jarvisaoieong/redux-loop';
import counter from 'modules/counter/counterReducer';
import counterPair from 'modules/counterPair/counterPairReducer';
import counterList from 'modules/counterList/counterListReducer';
import counterFancy from 'modules/counterFancy/counterFancyReducer';
import randomGif from 'modules/randomGif/randomGifReducer';
import randomGifPair from 'modules/randomGifPair/randomGifPairReducer';
import randomGifList from 'modules/randomGifList/randomGifListReducer';

export default combineReducers({
counter,
counterPair,
counterList,
counterFancy,
randomGif,
randomGifPair,
randomGifList,
});

0 comments on commit ec95f17

Please sign in to comment.