-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
internal: Code cleanup and readability (#9)
* Migrate more internals to the internals directory * Code cleanup and standardization
- Loading branch information
Showing
17 changed files
with
109 additions
and
78 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
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,19 @@ | ||
import { set as setPath } from 'immutable-path/dist/immutable-object-path'; | ||
|
||
import { ChangeEntry, ReduxState } from './types'; | ||
|
||
const applyChangesToObject = (state: ReduxState, changes: Array<ChangeEntry>): ReduxState => { | ||
let newState = state; | ||
for (let i = 0; i < changes.length; i++) { | ||
const [path, value] = changes[i]; | ||
if (path) { | ||
newState = setPath(newState, path, value); | ||
} else { | ||
newState = value; | ||
} | ||
} | ||
|
||
return newState; | ||
}; | ||
|
||
export default applyChangesToObject; |
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,4 +1,13 @@ | ||
export { default as internalStateAtom } from './internalStateAtom'; | ||
export * from './internalStateAtom'; | ||
export { default as applyChangesToObject } from './applyChangesToObject'; | ||
export * from './applyChangesToObject'; | ||
|
||
export { default as reduxStateAtom } from './reduxStateAtom'; | ||
export * from './reduxStateAtom'; | ||
|
||
export { default as reduxStoreRef } from './reduxStoreRef'; | ||
export * from './reduxStoreRef'; | ||
|
||
export { default as syncChangesFromRecoilAction } from './syncChangesFromRecoilAction'; | ||
export * from './syncChangesFromRecoilAction'; | ||
|
||
export * from './types'; |
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,8 @@ | ||
import { Store } from 'redux'; | ||
|
||
// This acts like a React ref, but it's not | ||
const reduxStoreRef: { c: Store | null } = { | ||
c: null, | ||
}; | ||
|
||
export default reduxStoreRef; |
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 { ChangeEntry } from './types'; | ||
|
||
const SYNC_CHANGES_FROM_RECOIL = 'SYNC_CHANGES_FROM_RECOIL'; | ||
|
||
export interface SyncFromRecoilAction { | ||
type: typeof SYNC_CHANGES_FROM_RECOIL; | ||
payload: Array<ChangeEntry>; | ||
} | ||
|
||
const syncChangesFromRecoilAction = (changes: Array<ChangeEntry>): SyncFromRecoilAction => ({ | ||
type: SYNC_CHANGES_FROM_RECOIL, | ||
payload: changes, | ||
}); | ||
|
||
export default syncChangesFromRecoilAction; | ||
export { SYNC_CHANGES_FROM_RECOIL }; |
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
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,45 +1,15 @@ | ||
import { set as setPath } from 'immutable-path'; | ||
import { Reducer } from 'redux'; | ||
|
||
import { ReduxState } from './internals/types'; | ||
|
||
const SYNC_CHANGES_FROM_RECOIL = 'SYNC_CHANGES_FROM_RECOIL'; | ||
|
||
export type ChangeEntry = [string, ReduxState]; | ||
|
||
export interface SyncFromRecoilAction { | ||
type: typeof SYNC_CHANGES_FROM_RECOIL; | ||
payload: Array<ChangeEntry>; | ||
} | ||
|
||
const syncChangesFromRecoilAction = (changes: Array<ChangeEntry>): SyncFromRecoilAction => ({ | ||
type: SYNC_CHANGES_FROM_RECOIL, | ||
payload: changes, | ||
}); | ||
|
||
const applyChangesToState = (state: ReduxState, changes: Array<ChangeEntry>): ReduxState => { | ||
let newState = state; | ||
for (let i = 0; i < changes.length; i++) { | ||
const [path, value] = changes[i]; | ||
if (path) { | ||
newState = setPath(newState, path, value); | ||
} else { | ||
newState = value; | ||
} | ||
} | ||
|
||
return newState; | ||
}; | ||
import { SYNC_CHANGES_FROM_RECOIL, applyChangesToObject } from './internals'; | ||
|
||
const syncChangesFromRecoil = (rootReducer: Reducer): Reducer => { | ||
return (state, action) => { | ||
if (action.type === SYNC_CHANGES_FROM_RECOIL) { | ||
return applyChangesToState(state, action.payload); | ||
return applyChangesToObject(state, action.payload); | ||
} else { | ||
return rootReducer(state, action); | ||
} | ||
}; | ||
}; | ||
|
||
export default syncChangesFromRecoil; | ||
export { applyChangesToState, syncChangesFromRecoilAction }; |
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
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