This repository has been archived by the owner on May 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ca29e62
commit 12955e4
Showing
15 changed files
with
158 additions
and
11 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 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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import { State as UserState } from '@front/domain/user/reducer' | ||
|
||
export interface State { | ||
a: string // TODO: remove | ||
user: UserState | ||
} |
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 |
---|---|---|
@@ -1,3 +1,9 @@ | ||
import { combineReducers } from 'redux' | ||
|
||
import { reducer as userReducer } from '@front/domain/user/reducer' | ||
|
||
import { State } from './State' | ||
|
||
export const reducer = (s: State | undefined) => s as State | ||
export const reducer = combineReducers<State>({ | ||
user: userReducer, | ||
}) |
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,20 @@ | ||
import { isObject, mapValues } from 'lodash' | ||
import { Option } from 'tsoption' | ||
|
||
import { OPTION_MARK } from './objectTaps/OPTION_MARK' | ||
|
||
const mapValuesDeep = (obj: any, callback: (value: any) => any): any => | ||
isObject(obj) && !isOption(obj) | ||
? mapValues(obj, (value: any) => mapValuesDeep(value, callback)) | ||
: callback(obj) | ||
|
||
const isOption = (obj: any): boolean => obj instanceof Option | ||
|
||
export const markOptions = (obj: any) => | ||
mapValuesDeep(obj, (v: any) => { | ||
if (isOption(v)) { | ||
v[OPTION_MARK] = true | ||
} | ||
|
||
return v | ||
}) |
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 @@ | ||
export const OPTION_MARK = '__OPTION_MARK__' |
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,4 @@ | ||
export interface ObjectTaper { | ||
supports(object: any): boolean | ||
tap(object: any): any | ||
} |
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,14 @@ | ||
import { Option } from 'tsoption' | ||
|
||
import { ObjectTaper } from './ObjectTaper' | ||
import { OPTION_MARK } from './OPTION_MARK' | ||
|
||
export class OptionTaper implements ObjectTaper { | ||
public supports(object: any): boolean { | ||
return !!object[OPTION_MARK] | ||
} | ||
|
||
public tap(object: any) { | ||
return Option.of(object.value) | ||
} | ||
} |
File renamed without changes.
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,25 @@ | ||
import { ClearAction, createClearRedux } from 'redux-clear' | ||
import { Option } from 'tsoption' | ||
|
||
interface State { | ||
token: Option<string> | ||
} | ||
|
||
interface Actions { | ||
setToken: ClearAction<[string]> | ||
} | ||
|
||
const { reducer, actions } = createClearRedux<State, Actions>( | ||
{ | ||
setToken: state => token => ({ | ||
...state, | ||
token: Option.of(token), | ||
}), | ||
}, | ||
{ | ||
token: Option.of(null), | ||
}, | ||
'user', | ||
) | ||
|
||
export { reducer, actions, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { combineReducers } from 'redux' | ||
|
||
import { reducer as dataReducer, State as DataState } from './data' | ||
import { reducer as signInReducer, State as SignInState } from './signIn' | ||
|
||
interface State { | ||
signIn: SignInState | ||
data: DataState | ||
} | ||
|
||
const reducer = combineReducers<State>({ | ||
signIn: signInReducer, | ||
data: dataReducer, | ||
}) | ||
|
||
export { reducer, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { ClearAction, createClearRedux } from 'redux-clear' | ||
import { Option } from 'tsoption' | ||
|
||
interface State { | ||
error: Option<string> | ||
loading: boolean | ||
} | ||
|
||
interface Actions { | ||
request: ClearAction | ||
failure: ClearAction<[string]> | ||
} | ||
|
||
const { reducer, actions } = createClearRedux<State, Actions>( | ||
{ | ||
request: state => () => ({ | ||
...state, | ||
error: Option.of(null), | ||
loading: true, | ||
}), | ||
failure: state => error => ({ | ||
...state, | ||
error: Option.of(error), | ||
loading: false, | ||
}), | ||
}, | ||
{ | ||
loading: false, | ||
error: Option.of(null), | ||
}, | ||
'user', | ||
) | ||
|
||
export { reducer, actions, 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