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 { Map } from "immutable"; | |
// reducers | |
const INITIAL_STATE = Map({ post: null, isLoading: false }); | |
function postReducer(state = INITIAL_STATE, action) { | |
switch (action.type) { | |
case "FETCHED": { | |
return state.withMutations(currentState => | |
currentState.set("post", action.payload.post).set("isLoading", false), |
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
interface Keyed<K, V> extends Collection<K, V>, Iterable.Keyed<K, V> { ... } | |
interface Map<K, V> extends Keyed<K, V> { | |
set(key: K, value: V): Map<K, V>; | |
setIn(keyPath: Array<any>, value: any): Map<K, 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
// scaffolding | |
interface IPostStateImmutable { | |
get(key: "post"): IPostImmutable | null; // IPostImmutable is also another hacky interface like IPostStateImmutable. | |
get(key: "isLoading"): boolean; | |
set(key: "post", value: IPostImmutable | null): IPostStateImmutable; | |
set(key: "isLoading", value: boolean): IPostStateImmutable; | |
withMutations( | |
mutator: (mutable: IPostStateImmutable) => IPostStateImmutable, | |
): IPostStateImmutable; | |
} |
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 { TypedRecord, recordify } from "typed-immutable-record"; | |
// scaffolding | |
interface IPostState { | |
post: IPost | null; | |
isLoading: boolean; | |
} | |
interface IPostStateRecordPart { | |
post: IPostRecord; // this interface is created in a similar fashion. | |
isLoading: boolean; | |
} |
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
return { | |
...state, | |
post: { | |
...state.post, | |
author: { | |
...state.post.author, | |
relation: { | |
...state.post.author.relation, | |
following: true, | |
}, |
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
// post reducer | |
interface IPostState | |
extends Readonly<{ | |
postId: number | null; | |
isLoading: boolean; | |
}> {} | |
const INITIAL_STATE: IPostState = { | |
postId: null, | |
isLoading: false, |
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
// scaffolding | |
interface IPostState | |
extends Readonly<{ | |
post: IPost | null; | |
isLoading: boolean; | |
}> {} // this has to be a Readonly interface as well. | |
// reducers | |
const INITIAL_STATE: IPostState = { | |
post: null, |
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
interface Connect { | |
<TStateProps = {}, TDispatchProps = {}, TOwnProps = {}, State = {}>( | |
mapStateToProps: MapStateToPropsParam<TStateProps, TOwnProps, State>, | |
mapDispatchToProps: MapDispatchToPropsParam<TDispatchProps, TOwnProps>, | |
): InferableComponentEnhancerWithProps< | |
TStateProps & TDispatchProps & TOwnProps, | |
TOwnProps | |
>; | |
} |