-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(mini-rx-store, signal-store, common): streamline feature sto…
…res and component stores
- Loading branch information
Showing
10 changed files
with
75 additions
and
128 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,19 @@ | ||
import { Action, Reducer } from './models'; | ||
import { Action, ComponentStoreExtension, MetaReducer, Reducer } from './models'; | ||
import { isMiniRxAction } from './is-mini-rx-action'; | ||
import { calcNextState } from './calc-next-state'; | ||
import { combineMetaReducers } from './combine-meta-reducers'; | ||
|
||
export function createComponentStoreReducer<StateType>( | ||
initialState: StateType | ||
initialState: StateType, | ||
extensions: ComponentStoreExtension[] | ||
): Reducer<StateType> { | ||
return (state: StateType = initialState, action: Action) => { | ||
const reducer = (state: StateType = initialState, action: Action) => { | ||
return isMiniRxAction<StateType>(action) | ||
? calcNextState(state, action.stateOrCallback) | ||
: state; | ||
}; | ||
|
||
const metaReducers: MetaReducer<StateType>[] = extensions.map((ext) => ext.init()); | ||
const combinedMetaReducer = combineMetaReducers(metaReducers); | ||
return combinedMetaReducer(reducer); | ||
} |
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,5 @@ | ||
import { generateId } from './generate-id'; | ||
|
||
export function generateFeatureKey(featureKey: string, multi?: boolean) { | ||
return multi ? featureKey + '-' + generateId() : featureKey; | ||
} |
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
Oops, something went wrong.