mirror of
https://github.com/aleleba/create-react-ssr.git
synced 2025-01-09 05:26:58 -06:00
PR-753737: Se Agregan los Actions de redux y se convierte todo el frontend a typescript.
This commit is contained in:
parent
fded666bc3
commit
76272cf3a8
4
client/custom.d.ts
vendored
Normal file
4
client/custom.d.ts
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
declare module "*.svg" {
|
||||
const content: any;
|
||||
export default content;
|
||||
}
|
9
client/src/frontend/actions/index.ts
Normal file
9
client/src/frontend/actions/index.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import test, { TTest } from './testAction';
|
||||
|
||||
export type TAction = TTest
|
||||
|
||||
const actions = {
|
||||
test
|
||||
}
|
||||
|
||||
export default actions
|
25
client/src/frontend/actions/testAction.ts
Normal file
25
client/src/frontend/actions/testAction.ts
Normal file
@ -0,0 +1,25 @@
|
||||
export enum ActionTypesTest {
|
||||
ChangeHello = 'CHANGE_HELLO'
|
||||
}
|
||||
|
||||
export interface IChangeHello {
|
||||
type: ActionTypesTest.ChangeHello
|
||||
payload: IChangeHelloPayload
|
||||
}
|
||||
|
||||
export interface IChangeHelloPayload {
|
||||
hello: any | undefined
|
||||
}
|
||||
|
||||
export type TTest = IChangeHello
|
||||
|
||||
const changeHello = (payload: string) => ({
|
||||
type: 'CREATE_USER',
|
||||
payload
|
||||
})
|
||||
|
||||
const actions = {
|
||||
changeHello
|
||||
}
|
||||
|
||||
export default actions
|
@ -5,7 +5,7 @@ import { BrowserRouter as Router } from 'react-router-dom';
|
||||
// Redux
|
||||
import { Provider } from 'react-redux';
|
||||
import { IInitialState } from './reducers/index';
|
||||
import setStore from './setStore.js';
|
||||
import setStore from './setStore';
|
||||
import { config } from '../../config';
|
||||
|
||||
import './styles/global.sass';
|
||||
@ -61,11 +61,6 @@ hydrateRoot(container,
|
||||
</Provider>
|
||||
); */
|
||||
|
||||
// If you want your app to work offline and load faster, you can change
|
||||
// unregister() to register() below. Note this comes with some pitfalls.
|
||||
// Learn more about service workers: http://bit.ly/CRA-PWA
|
||||
//serviceWorker.register();
|
||||
|
||||
if((env) && (env === 'production')){
|
||||
serviceWorkerRegistration();
|
||||
}
|
||||
|
@ -1,8 +1,9 @@
|
||||
import { combineReducers } from 'redux';
|
||||
import testReducer, { ITestReducer } from './testReducer';
|
||||
import testReducer from './testReducer';
|
||||
import { IChangeHelloPayload } from '../actions/testAction';
|
||||
|
||||
export interface IInitialState {
|
||||
testReducer?: ITestReducer | undefined
|
||||
testReducer?: IChangeHelloPayload | undefined
|
||||
}
|
||||
|
||||
const rootReducer = combineReducers({
|
||||
|
@ -1,2 +1,2 @@
|
||||
let initialState = {};
|
||||
const initialState = {};
|
||||
export default initialState;
|
@ -1,12 +1,10 @@
|
||||
export interface ITestReducer {
|
||||
hello: any | undefined
|
||||
}
|
||||
import { TAction } from '../actions';
|
||||
|
||||
const initialState = {
|
||||
hello: 'world'
|
||||
};
|
||||
|
||||
const testReducer = (state = initialState, action: { type: any; payload: { hello: any; }; }) => {
|
||||
const testReducer = (state = initialState, action: TAction) => {
|
||||
switch (action.type){
|
||||
case 'CHANGE_HELLO': {
|
||||
const newHello = action.payload.hello;
|
||||
|
@ -3,7 +3,8 @@ import { createStore } from 'redux'; //, applyMiddleware
|
||||
// import { Provider } from 'react-redux';
|
||||
import { composeWithDevTools as composeWithDevToolsWeb } from 'redux-devtools-extension';
|
||||
import { config } from '../../config';
|
||||
import reducer from './reducers';
|
||||
import reducer, { IInitialState } from './reducers';
|
||||
|
||||
|
||||
const { env } = config;
|
||||
|
||||
@ -11,7 +12,7 @@ const composeEnhancers = composeWithDevToolsWeb({
|
||||
// Specify here name, actionsBlacklist, actionsCreators and other options
|
||||
});
|
||||
|
||||
const setStore = ({ initialState }) => {
|
||||
const setStore = ({ initialState }: { initialState: IInitialState | undefined }) => {
|
||||
const store = env === 'development' ? createStore(
|
||||
reducer,
|
||||
initialState,
|
@ -17,7 +17,7 @@ import { StaticRouter } from 'react-router-dom/server';
|
||||
import routes from '../routes';
|
||||
//Redux
|
||||
import { Provider } from 'react-redux';
|
||||
import setStore from '../frontend/setStore.js';
|
||||
import setStore from '../frontend/setStore';
|
||||
import initialState from '../frontend/reducers/initialState';
|
||||
//Get Hashes
|
||||
import getHashManifest from './getHashManifest';
|
||||
|
Loading…
Reference in New Issue
Block a user