Last active
August 22, 2019 07:18
Redux
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void SetInitialState() | |
{ | |
var state = new State | |
{ | |
// Set values from database | |
}; | |
Hidden_InitialState.Value = JsonConvert.SerializeObject(state); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as redux from 'redux'; | |
import { appReducer } from '../reduxStates/stateHelper'; | |
let store = null; | |
function setInitialState(): void { | |
const stateData = $('[id$=Hidden_InitialState]').val(); | |
if (stateData && stateData.length > 0) { | |
const initialState = JSON.parse(stateData); | |
store = redux.createStore(stateHelper.appReducer, initialState); | |
} | |
} | |
$(window).load(() => { | |
setInitialState(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const arg1 = $('#someControl').val(); | |
store.dispatch(stateHelper.actionOne(arg1)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Getting the state object | |
const newState = store.getState(); | |
async function trySave(): Promise<void> { | |
const state = store.getState(); | |
// Send to handler | |
const res = await saveData(state); | |
if (res.status === 'success') { | |
// Success | |
} else { | |
// Error | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { IFluxAction } from '../reduxStates/reduxHelpers'; | |
import models = namespace.className; | |
export function appReducer(state: models.State = undefined, action: IAction): models.State { | |
switch (action.type) { | |
case actions.ACTION_ONE: | |
return Object.assign({}, state, { | |
// ... | |
}); | |
default: | |
return state; | |
} | |
} | |
export enum actions { | |
ACTION_ONE | |
} | |
export interface IAction extends IFluxAction { | |
type: actions, | |
payload: IPayload | |
} | |
export function actionOne(arg1: string): IAction { | |
return { | |
type: actions.ACTION_ONE, | |
payload: { | |
prop1: arg1 | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment