-
-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TASK: refactor System reducer to use TypeScript (#2215)
- Loading branch information
Showing
8 changed files
with
114 additions
and
1,952 deletions.
There are no files selected for viewing
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
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import produce from 'immer'; | ||
import {$get} from 'plow-js'; | ||
import {action as createAction, ActionType} from 'typesafe-actions'; | ||
|
||
// | ||
// Export the subreducer state shape interface | ||
// | ||
export interface State { | ||
readonly authenticationTimeout: boolean; | ||
} | ||
|
||
const defaultState: State = { | ||
authenticationTimeout: false | ||
}; | ||
|
||
// | ||
// Export the action types | ||
// | ||
export const actionTypes = { | ||
BOOT: '@neos/neos-ui/System/BOOT', | ||
INIT: '@neos/neos-ui/System/INIT', | ||
READY: '@neos/neos-ui/System/READY', | ||
AUTHENTICATION_TIMEOUT: '@neos/neos-ui/System/AUTHENTICATION_TIMEOUT', | ||
REAUTHENTICATION_SUCCEEDED: '@neos/neos-ui/System/REAUTHENTICATION_SUCCEEDED' | ||
}; | ||
|
||
// | ||
// Export the actions | ||
// | ||
export const actions = { | ||
boot: () => createAction(actionTypes.BOOT), | ||
init: (state: State) => createAction(actionTypes.INIT, state), | ||
ready: () => createAction(actionTypes.READY), | ||
authenticationTimeout: () => createAction(actionTypes.AUTHENTICATION_TIMEOUT), | ||
reauthenticationSucceeded: () => createAction(actionTypes.REAUTHENTICATION_SUCCEEDED) | ||
}; | ||
|
||
// | ||
// Export the union type of all actions | ||
// | ||
export type Action = ActionType<typeof actions>; | ||
|
||
// | ||
// Export the reducer | ||
// | ||
export const reducer = (state: State = defaultState, action: Action) => { | ||
return produce(state, draft => { | ||
switch (action.type) { | ||
case actionTypes.INIT: | ||
draft.authenticationTimeout = false; | ||
break; | ||
case actionTypes.AUTHENTICATION_TIMEOUT: | ||
draft.authenticationTimeout = true; | ||
break; | ||
case actionTypes.REAUTHENTICATION_SUCCEEDED: | ||
draft.authenticationTimeout = false; | ||
break; | ||
} | ||
}); | ||
}; | ||
|
||
// | ||
// Export the selectors | ||
// | ||
export const selectors = { | ||
authenticationTimeout: (state: any) => $get(['system'], state).authenticationTimeout | ||
}; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Temporary Plow typings | ||
// TODO: move to Plow | ||
declare module 'plow-js' { | ||
export function $get<K1 extends keyof S, S>(path: [K1], state: S): S[K1]; | ||
export function $get<K1 extends keyof S, K2 extends keyof S[K1], S>(path: [K1, K2], state: S): S[K1][K2]; | ||
export function $get<K1 extends keyof S, K2 extends keyof S[K1], K3 extends keyof S[K1][K2], S>(path: [K1, K2, K3], state: S): S[K1][K2][K3]; | ||
|
||
export function $set<K1 extends keyof S, V extends S[K1], S>(path: [K1], value: V, state: S): S; | ||
export function $set<K1 extends keyof S, K2 extends keyof S[K1], V extends S[K1][K2], S>(path: [K1, K2], value: V, state: S): S; | ||
export function $set<K1 extends keyof S, K2 extends keyof S[K1], K3 extends keyof S[K1][K2], V extends S[K1][K2][K3], S>(path: [K1, K2, K3], value: V, state: S): S; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
declare module '@neos-project/utils-redux' { | ||
export function handleActions<S>(handlers: Object): (state: S, action: string) => S; | ||
} |
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
Oops, something went wrong.