View both-container.ts
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 | |
>; | |
} |
View third-iteration-1.ts
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, |
View fourth-iteration.ts
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, |
View third-iterations-2.ts
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, | |
}, |
View second-iteration.ts
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; | |
} |
View first-iteration-2.ts
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; | |
} |
View first-iteration-1.ts
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>; | |
... | |
} |
View genesis.js
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), |