Skip to content
This repository has been archived by the owner on Jan 10, 2018. It is now read-only.

Commit

Permalink
Support factory function for _initialState parameter of provideStore
Browse files Browse the repository at this point in the history
ngc does not support function call now. It will be good to support passing a function parameter to provideStore.
  • Loading branch information
iron9light committed Sep 19, 2016
1 parent f04c544 commit 9cf8dbc
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/ng2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ export function _initialStateFactory(initialState, reducer) {
if (!initialState) {
return reducer(undefined, { type: Dispatcher.INIT });
}

if (typeof initialState === 'function') {
initialState = initialState();
}

return initialState;
}

Expand All @@ -41,7 +46,7 @@ export function _reducerFactory(dispatcher, reducer) {
/**
* @deprecated, use StoreModule.provideStore instead!
*/
export function provideStore(_reducer: any, _initialState?: any): any[] {
export function provideStore(_reducer: any, _initialState?: any | (() => any)): any[] {
return [
Dispatcher,
{ provide: Store, useFactory: _storeFactory, deps: [Dispatcher, Reducer, State] },
Expand All @@ -57,7 +62,7 @@ export function provideStore(_reducer: any, _initialState?: any): any[] {

@NgModule({})
export class StoreModule {
static provideStore(_reducer: any, _initialState?:any): ModuleWithProviders {
static provideStore(_reducer: any, _initialState?: any | (() => any)): ModuleWithProviders {
return {
ngModule: StoreModule,
providers: provideStore(_reducer, _initialState)
Expand Down

0 comments on commit 9cf8dbc

Please sign in to comment.