This repository has been archived by the owner on Jan 10, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 311
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support factory function for _initialState parameter of provideStore
ngc does not support function call now. It will be good to support passing a function parameter to provideStore.
- Loading branch information
1 parent
6a526ae
commit 5358c43
Showing
6 changed files
with
82 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { NgModule, Component } from '@angular/core'; | ||
import { platformDynamicServer } from '@angular/platform-server'; | ||
import { BrowserModule } from '@angular/platform-browser'; | ||
import { Store, StoreModule } from '../../'; | ||
import { counterReducer, INCREMENT, DECREMENT } from '../fixtures/counter'; | ||
import { Observable } from 'rxjs/Observable'; | ||
|
||
export interface AppState { | ||
count: number; | ||
} | ||
|
||
export const storeConfig = {count: counterReducer}; | ||
export function initialState() { | ||
return { count : 0 }; | ||
} | ||
|
||
@Component({ | ||
selector: 'ngc-spec-component', | ||
template: ` | ||
<button (click)="increment()"> + </button> | ||
<span> Count : {{ count | async }} </span> | ||
<button (click)="decrement()"> + </button> | ||
` | ||
}) | ||
export class NgcSpecComponent { | ||
count: Observable<number>; | ||
constructor(public store:Store<AppState>){ | ||
this.count = store.select(state => state.count); | ||
} | ||
increment(){ | ||
this.store.dispatch({ type: INCREMENT }); | ||
} | ||
decrement(){ | ||
this.store.dispatch({ type: DECREMENT }); | ||
} | ||
} | ||
|
||
@NgModule({ | ||
imports: [ | ||
BrowserModule, | ||
StoreModule.provideStore(storeConfig, initialState) | ||
], | ||
declarations: [NgcSpecComponent], | ||
bootstrap: [NgcSpecComponent] | ||
}) | ||
export class NgcSpecModule {} |
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,17 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES5", | ||
"emitDecoratorMetadata": true, | ||
"experimentalDecorators": true, | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"outDir": "./output", | ||
"lib": ["es2015", "dom"] | ||
}, | ||
"files": [ | ||
"main.ts" | ||
], | ||
"angularCompilerOptions": { | ||
"genDir": "ngfactory" | ||
} | ||
} |
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