-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Chore: Migrate Redux to Typescript PoC #3565
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 18 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
3b97c34
chore: migrate activeUsers reducer and action to TS
dnlsilva 34e6ece
chore: init types folder and set redux and BaseScreen interface
dnlsilva 9d7450b
chore: remove mapDispatchToProps to use dispatch prop and clear some …
dnlsilva 003f9fc
chore: type selectedUsers action and reducer and improvement in the c…
dnlsilva 010676a
chore: move IUser to base types
dnlsilva dc83f76
chore: move state props to ISelectedUsersViewProps
dnlsilva f169f6e
chore: create mocketStore
dnlsilva 69f2743
chore: remove applyAppStateMiddleware
dnlsilva b80c063
test: create activeUser and selectedUser tests
dnlsilva b5bda75
test: add more selectedUsers tests
dnlsilva b56f604
chore: fix action type
dnlsilva ff0925c
chore: move types to definition folder and fix imports
dnlsilva ef0d2bf
chore: remove unused const
dnlsilva d12b28b
chore: migrate redux tests to reducer folder and add eslint jest plugin
dnlsilva f0977dd
chore: exprot initial state and then import on tests
dnlsilva bad5643
chore: move interfaces to reducer and import on screen
dnlsilva 928fac1
chore: set eslint-plugin-jest version to 24.7.0
dnlsilva c471195
chore: fix IUser import
dnlsilva 48e4640
chore: update interfaces and types names
dnlsilva 0cf9765
chore: update definitions
dnlsilva bc92a4f
chore: update IBaseScreen definitions
dnlsilva 4fe8dab
Merge branch 'develop' into chore/poc-redux-ts
diegolmello File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,15 @@ | ||
| import { Action } from 'redux'; | ||
|
|
||
| import { IActiveUsers } from '../reducers/activeUsers'; | ||
| import { SET_ACTIVE_USERS } from './actionsTypes'; | ||
|
|
||
| export interface SetActiveUsers extends Action { | ||
| activeUsers: IActiveUsers; | ||
| } | ||
|
|
||
| export type IActionActiveUsers = SetActiveUsers; | ||
|
dnlsilva marked this conversation as resolved.
Outdated
|
||
|
|
||
| export const setActiveUsers = (activeUsers: IActiveUsers): SetActiveUsers => ({ | ||
| type: SET_ACTIVE_USERS, | ||
| activeUsers | ||
| }); | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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,43 @@ | ||
| import { Action } from 'redux'; | ||
|
|
||
| import { ISelectedUser } from '../reducers/selectedUsers'; | ||
| import * as types from './actionsTypes'; | ||
|
|
||
| type User = { | ||
|
dnlsilva marked this conversation as resolved.
Outdated
|
||
| user: ISelectedUser; | ||
| }; | ||
|
|
||
| type IAction = Action & User; | ||
|
dnlsilva marked this conversation as resolved.
Outdated
|
||
|
|
||
| interface SetLoading extends Action { | ||
|
dnlsilva marked this conversation as resolved.
Outdated
|
||
| loading: boolean; | ||
| } | ||
|
|
||
| export type IActionSelectedUsers = IAction & SetLoading; | ||
|
dnlsilva marked this conversation as resolved.
Outdated
|
||
|
|
||
| export function addUser(user: ISelectedUser): IAction { | ||
| return { | ||
| type: types.SELECTED_USERS.ADD_USER, | ||
| user | ||
| }; | ||
| } | ||
|
|
||
| export function removeUser(user: ISelectedUser): IAction { | ||
| return { | ||
| type: types.SELECTED_USERS.REMOVE_USER, | ||
| user | ||
| }; | ||
| } | ||
|
|
||
| export function reset(): Action { | ||
| return { | ||
| type: types.SELECTED_USERS.RESET | ||
| }; | ||
| } | ||
|
|
||
| export function setLoading(loading: boolean): SetLoading { | ||
| return { | ||
| type: types.SELECTED_USERS.SET_LOADING, | ||
| loading | ||
| }; | ||
| } | ||
This file contains hidden or 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,10 @@ | ||
| import { StackNavigationProp } from '@react-navigation/stack'; | ||
| import { Dispatch } from 'redux'; | ||
|
|
||
| export interface BaseScreen { | ||
|
dnlsilva marked this conversation as resolved.
Outdated
|
||
| navigation: StackNavigationProp<any>; | ||
|
dnlsilva marked this conversation as resolved.
Outdated
|
||
| dispatch: Dispatch; | ||
| theme: string; | ||
|
dnlsilva marked this conversation as resolved.
|
||
| } | ||
|
|
||
| export * from './redux'; | ||
This file contains hidden or 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,31 @@ | ||
| import { IActionSelectedUsers } from '../../actions/selectedUsers'; | ||
| import { IActionActiveUsers } from '../../actions/activeUsers'; | ||
| // REDUCERS | ||
| import { IActiveUsers } from '../../reducers/activeUsers'; | ||
| import { ISelectedUsers } from '../../reducers/selectedUsers'; | ||
|
|
||
| export interface ApplicationState { | ||
|
dnlsilva marked this conversation as resolved.
Outdated
|
||
| settings: any; | ||
| login: any; | ||
| meteor: any; | ||
| server: any; | ||
| selectedUsers: ISelectedUsers; | ||
| createChannel: any; | ||
| app: any; | ||
| room: any; | ||
| rooms: any; | ||
| sortPreferences: any; | ||
| share: any; | ||
| customEmojis: any; | ||
| activeUsers: IActiveUsers; | ||
| usersTyping: any; | ||
| inviteLinks: any; | ||
| createDiscussion: any; | ||
| inquiry: any; | ||
| enterpriseModules: any; | ||
| encryption: any; | ||
| permissions: any; | ||
| roles: any; | ||
| } | ||
|
|
||
| export type ApplicationActions = IActionActiveUsers & IActionSelectedUsers; | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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 { setActiveUsers } from '../actions/activeUsers'; | ||
| import { IActiveUsers, initialState } from './activeUsers'; | ||
| import { mockedStore } from './mockedStore'; | ||
|
|
||
| describe('test reducer', () => { | ||
| it('should return initial state', () => { | ||
| const state = mockedStore.getState().activeUsers; | ||
| expect(state).toEqual(initialState); | ||
| }); | ||
| it('should return modified store after action', () => { | ||
| const activeUsers: IActiveUsers = { any: { status: 'online', statusText: 'any' } }; | ||
| mockedStore.dispatch(setActiveUsers(activeUsers)); | ||
| const state = mockedStore.getState().activeUsers; | ||
| expect(state).toEqual({ ...activeUsers }); | ||
| }); | ||
| }); |
This file contains hidden or 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,26 @@ | ||
| import { ApplicationActions } from '../definitions'; | ||
| import { SET_ACTIVE_USERS } from '../actions/actionsTypes'; | ||
|
|
||
| type UserStatus = 'online' | 'offline'; | ||
|
dnlsilva marked this conversation as resolved.
Outdated
|
||
| export interface ActiveUser { | ||
|
dnlsilva marked this conversation as resolved.
Outdated
|
||
| status: UserStatus; | ||
| statusText?: string; | ||
| } | ||
|
|
||
| export interface IActiveUsers { | ||
| [key: string]: ActiveUser; | ||
| } | ||
|
|
||
| export const initialState: IActiveUsers = {}; | ||
|
|
||
| export default function activeUsers(state = initialState, action: ApplicationActions): IActiveUsers { | ||
| switch (action.type) { | ||
| case SET_ACTIVE_USERS: | ||
| return { | ||
| ...state, | ||
| ...action.activeUsers | ||
| }; | ||
| default: | ||
| return state; | ||
| } | ||
| } | ||
This file contains hidden or 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,7 @@ | ||
| import { applyMiddleware, compose, createStore } from 'redux'; | ||
| import createSagaMiddleware from 'redux-saga'; | ||
|
|
||
| import reducers from '.'; | ||
|
|
||
| const enhancers = compose(applyMiddleware(createSagaMiddleware())); | ||
| export const mockedStore = createStore(reducers, enhancers); |
This file contains hidden or 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,36 @@ | ||
| import { addUser, reset, setLoading, removeUser } from '../actions/selectedUsers'; | ||
| import { mockedStore } from './mockedStore'; | ||
| import { initialState } from './selectedUsers'; | ||
|
|
||
| describe('test selectedUsers reducer', () => { | ||
| it('should return initial state', () => { | ||
| const state = mockedStore.getState().selectedUsers; | ||
| expect(state).toEqual(initialState); | ||
| }); | ||
|
|
||
| it('should return modified store after addUser', () => { | ||
| const user = { _id: 'xxx', name: 'xxx', fname: 'xxx' }; | ||
| mockedStore.dispatch(addUser(user)); | ||
| const state = mockedStore.getState().selectedUsers.users; | ||
| expect(state).toEqual([user]); | ||
| }); | ||
|
|
||
| it('should return empty store after remove user', () => { | ||
| const user = { _id: 'xxx', name: 'xxx', fname: 'xxx' }; | ||
| mockedStore.dispatch(removeUser(user)); | ||
| const state = mockedStore.getState().selectedUsers.users; | ||
| expect(state).toEqual([]); | ||
| }); | ||
|
|
||
| it('should return initial state after reset', () => { | ||
| mockedStore.dispatch(reset()); | ||
| const state = mockedStore.getState().selectedUsers; | ||
| expect(state).toEqual(initialState); | ||
| }); | ||
|
|
||
| it('should return loading after call action', () => { | ||
| mockedStore.dispatch(setLoading(true)); | ||
| const state = mockedStore.getState().selectedUsers.loading; | ||
| expect(state).toEqual(true); | ||
| }); | ||
| }); |
19 changes: 17 additions & 2 deletions
19
app/reducers/selectedUsers.js → app/reducers/selectedUsers.ts
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.