restructure redux files

This commit is contained in:
catarak 2016-06-22 15:58:23 -04:00
parent 3a26cdd491
commit 81aabddeb1
21 changed files with 92 additions and 91 deletions

View file

@ -0,0 +1,9 @@
import * as ActionTypes from '../../../constants';
export function updateFile(name, content) {
return {
type: ActionTypes.CHANGE_SELECTED_FILE,
name: name,
content: content
}
}

View file

@ -0,0 +1,19 @@
import * as ActionTypes from '../../../constants';
export function toggleSketch() {
return {
type: ActionTypes.TOGGLE_SKETCH
}
}
export function startSketch() {
return {
type: ActionTypes.START_SKETCH
}
}
export function stopSketch() {
return {
type: ActionTypes.STOP_SKETCH
}
}

View file

@ -0,0 +1,25 @@
import * as ActionTypes from '../../../constants';
export function openPreferences() {
return {
type: ActionTypes.OPEN_PREFERENCES
}
}
export function closePreferences() {
return {
type: ActionTypes.CLOSE_PREFERENCES
}
}
export function increaseFont() {
return {
type: ActionTypes.INCREASE_FONTSIZE
}
}
export function decreaseFont() {
return {
type: ActionTypes.DECREASE_FONTSIZE
}
}

View file

@ -1,17 +1,9 @@
import * as ActionTypes from '../constants/constants' import * as ActionTypes from '../../../constants';
import { browserHistory } from 'react-router' import { browserHistory } from 'react-router'
import axios from 'axios' import axios from 'axios'
const ROOT_URL = location.href.indexOf('localhost') > 0 ? 'http://localhost:8000/api' : '/api'; const ROOT_URL = location.href.indexOf('localhost') > 0 ? 'http://localhost:8000/api' : '/api';
export function updateFile(name, content) {
return {
type: ActionTypes.CHANGE_SELECTED_FILE,
name: name,
content: content
}
}
export function getProject(id) { export function getProject(id) {
return function(dispatch) { return function(dispatch) {
axios.get(`${ROOT_URL}/projects/${id}`, {withCredentials: true}) axios.get(`${ROOT_URL}/projects/${id}`, {withCredentials: true})

View file

@ -6,8 +6,10 @@ import Preferences from '../components/Preferences'
import Nav from '../../../components/Nav' import Nav from '../../../components/Nav'
import { bindActionCreators } from 'redux' import { bindActionCreators } from 'redux'
import { connect } from 'react-redux' import { connect } from 'react-redux'
import * as IndexActions from '../../../redux/actions' import * as FileActions from '../actions/files'
import * as ProjectActions from '../../../redux/actions/project' import * as IDEActions from '../actions/ide'
import * as PreferencesActions from '../actions/preferences'
import * as ProjectActions from '../actions/project'
class IDEView extends React.Component { class IDEView extends React.Component {
componentDidMount() { componentDidMount() {
@ -65,7 +67,7 @@ function mapStateToProps(state) {
} }
function mapDispatchToProps(dispatch) { function mapDispatchToProps(dispatch) {
return bindActionCreators(Object.assign({}, IndexActions, ProjectActions), dispatch); return bindActionCreators(Object.assign({}, FileActions, ProjectActions, IDEActions, PreferencesActions), dispatch);
} }
export default connect(mapStateToProps, mapDispatchToProps)(IDEView); export default connect(mapStateToProps, mapDispatchToProps)(IDEView);

View file

@ -1,4 +1,4 @@
import * as ActionTypes from '../constants/constants'; import * as ActionTypes from '../../../constants';
const initialState = { const initialState = {
name: "sketch.js", name: "sketch.js",

View file

@ -1,4 +1,4 @@
import * as ActionTypes from '../constants/constants'; import * as ActionTypes from '../../../constants';
const initialState = { const initialState = {
isPlaying: false isPlaying: false

View file

@ -1,4 +1,4 @@
import * as ActionTypes from '../constants/constants'; import * as ActionTypes from '../../../constants';
const initialState = { const initialState = {
isPreferencesShowing: false, isPreferencesShowing: false,

View file

@ -1,4 +1,4 @@
import * as ActionTypes from '../constants/constants'; import * as ActionTypes from '../../../constants';
const initialState = { const initialState = {
name: "Hello p5.js" name: "Hello p5.js"

View file

@ -1,4 +1,4 @@
import * as ActionTypes from '../constants/constants' import * as ActionTypes from '../../constants'
import { browserHistory } from 'react-router' import { browserHistory } from 'react-router'
import axios from 'axios' import axios from 'axios'

View file

@ -1,7 +1,7 @@
import React from 'react' import React from 'react'
import { bindActionCreators } from 'redux' import { bindActionCreators } from 'redux'
import {reduxForm} from 'redux-form' import {reduxForm} from 'redux-form'
import * as UserActions from '../../../redux/actions/user' import * as UserActions from '../actions'
import LoginForm from '../components/LoginForm' import LoginForm from '../components/LoginForm'
class LoginView extends React.Component { class LoginView extends React.Component {

View file

@ -1,7 +1,7 @@
import React from 'react' import React from 'react'
import { bindActionCreators } from 'redux' import { bindActionCreators } from 'redux'
import { connect } from 'react-redux' import { connect } from 'react-redux'
import * as UserActions from '../../../redux/actions/user' import * as UserActions from '../actions'
import { reduxForm } from 'redux-form' import { reduxForm } from 'redux-form'
import SignupForm from '../components/SignupForm' import SignupForm from '../components/SignupForm'

View file

@ -1,4 +1,4 @@
import * as ActionTypes from '../constants/constants' import * as ActionTypes from '../../constants'
const user = (state = {authenticated: false}, action) => { const user = (state = {authenticated: false}, action) => {
switch (action.type) { switch (action.type) {

18
client/reducers.js Normal file
View file

@ -0,0 +1,18 @@
import { combineReducers } from 'redux'
import file from './modules/IDE/reducers/files'
import ide from './modules/IDE/reducers/ide'
import preferences from './modules/IDE/reducers/preferences'
import project from './modules/IDE/reducers/project'
import user from './modules/User/reducers'
import { reducer as form } from 'redux-form'
const rootReducer = combineReducers({
form,
ide,
file,
preferences,
user,
project
})
export default rootReducer

View file

@ -1,46 +0,0 @@
import * as ActionTypes from '../constants/constants';
import axios from 'axios'
const ROOT_URL = location.href.indexOf('localhost') > 0 ? 'http://localhost:8000/api' : '/api';
export function toggleSketch() {
return {
type: ActionTypes.TOGGLE_SKETCH
}
}
export function startSketch() {
return {
type: ActionTypes.START_SKETCH
}
}
export function stopSketch() {
return {
type: ActionTypes.STOP_SKETCH
}
}
export function openPreferences() {
return {
type: ActionTypes.OPEN_PREFERENCES
}
}
export function closePreferences() {
return {
type: ActionTypes.CLOSE_PREFERENCES
}
}
export function increaseFont() {
return {
type: ActionTypes.INCREASE_FONTSIZE
}
}
export function decreaseFont() {
return {
type: ActionTypes.DECREASE_FONTSIZE
}
}

View file

@ -1,18 +0,0 @@
import { combineReducers } from 'redux'
import file from './files'
import ide from './ide'
import preferences from './preferences'
import user from './user'
import project from './project'
import { reducer as form } from 'redux-form'
const rootReducer = combineReducers({
form,
file,
ide,
preferences,
user,
project
})
export default rootReducer

View file

@ -2,9 +2,9 @@ import { Route, IndexRoute } from 'react-router'
import React from 'react' import React from 'react'
import App from './modules/App/App' import App from './modules/App/App'
import IDEView from './modules/IDE/pages/IDEView' import IDEView from './modules/IDE/pages/IDEView'
import LoginView from './modules/Auth/pages/LoginView' import LoginView from './modules/User/pages/LoginView'
import SignupView from './modules/Auth/pages/SignupView' import SignupView from './modules/User/pages/SignupView'
import { getUser } from './redux/actions/user' import { getUser } from './modules/User/actions'
const routes = (store) => { const routes = (store) => {
return ( return (

View file

@ -1,6 +1,6 @@
import { createStore, applyMiddleware, compose } from 'redux' import { createStore, applyMiddleware, compose } from 'redux'
import thunk from 'redux-thunk' import thunk from 'redux-thunk'
import rootReducer from './redux/reducers' import rootReducer from './reducers'
export default function configureStore(initialState) { export default function configureStore(initialState) {
const store = createStore( const store = createStore(
@ -11,8 +11,8 @@ export default function configureStore(initialState) {
if (module.hot) { if (module.hot) {
// Enable Webpack hot module replacement for reducers // Enable Webpack hot module replacement for reducers
module.hot.accept('./redux/reducers', () => { module.hot.accept('./reducers', () => {
const nextRootReducer = require('./redux/reducers').default const nextRootReducer = require('./reducers').default
store.replaceReducer(nextRootReducer) store.replaceReducer(nextRootReducer)
}) })
} }