diff --git a/CHANGELOG.md b/CHANGELOG.md index cd703ab..dcda849 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,92 @@ +# 4.0.0-beta.6 + +### Fixes / Features + +Sorry for the delay on this, was hoping to get AoT working for decorators also - but there seems to be some challenges around that. + +* Update build to use ngc - metadata.json is now produced +* Fix `Unexpected value 'NgReduxModule' imported` +* NgReduxModule + +### Using NgReduxModule + +```js +import { BrowserModule } from '@angular/platform-browser'; +import { NgModule } from '@angular/core'; +import { AppComponent } from './app.component'; +import { NgReduxModule, NgRedux } from 'ng2-redux'; +import { IAppState } from './appstate'; +import { rootReducer } from './store'; +@NgModule({ + declarations: [ + AppComponent + ], + imports: [ + NgReduxModule.forRoot(), + BrowserModule, + ], + providers: [], + bootstrap: [AppComponent] +}) +export class AppModule { + constructor(ngRedux: NgRedux) { + + ngRedux.configureStore(rootReducer,{}); + } +} + +``` + +### Dev Tools + +The DevTools provider is not provider by default with the `NgReduxModule`, as you may not want to include this for production builds. To use `DevToolsExtension`, it is the same as before - and still need to include it in your providers. + +```js +import { NgReduxModule, DevToolsExtension } + +@NgModule({ + providerS: [DevToolsExtension] +}) +export class AppModule { + constructor(ngRedux:NgRedux, devTools:DevToolsExtension) { + // config as before + } +} +``` + +**IMPORTANT NOTE ABOUT AOT** + +If using the ngc compiler and AoT compilation - `@select` decorators will not work. If you want to use the ngc compiler (either directly, or via angular-cli), and want to use the `@select` - you will need to use the `--aot false` flag. + +If you want to use AoT - the build process will work, but decorators will silently stop working. If you want to use AoT. + +**before** + +```js +import { select } from 'ng2-redux'; +export class MyComponent { + @select() thing$:Observable; +} +``` + +**after** + +```js +import { NgRedux } from 'ng2-redux'; +export class MyComponent { + thing$:Observable; + constructor(private ngRedux:NgRedux) { + + } + ngOnInit() { + this.thing$ = this.ngRedux.select (n => n.thing); + } +} +``` + +We are big fans of how the `@select` works - and high priority to get this working, but it seems to possibly be a limitation of the compiler. Any feedback / help / suggestions to try and get this working with AoT would be greatly appreciated. + + # 3.3.9 ### Fixes diff --git a/examples/counter/components/counter-info.component.ts b/examples/counter/components/counter-info.component.ts index 62fea54..174c1ec 100644 --- a/examples/counter/components/counter-info.component.ts +++ b/examples/counter/components/counter-info.component.ts @@ -1,8 +1,10 @@ import { Component, Input } from '@angular/core'; import { Observable } from 'rxjs/Observable'; -import { select } from 'ng2-redux'; +import { select as select } from 'ng2-redux'; import 'rxjs/add/operator/combineLatest'; - +//let select = select_x; +export let x = state => state.counter; +export let y = state => state.counter * 2; interface ICoord { x: number; y: number; @@ -21,9 +23,9 @@ interface ICoord { }) export class CounterInfo { - @select(state => state.counter) funcCounter$: Observable; + @select(x) funcCounter$: Observable; @select('counter') stringKey$: Observable; - @select(state => state.counter * 2) counterX2$: Observable; + @select(y) counterX2$: Observable; foo: ICoord; ngOnInit() { diff --git a/examples/counter/components/counter.component.ts b/examples/counter/components/counter.component.ts index 4f319b5..1b66dfb 100644 --- a/examples/counter/components/counter.component.ts +++ b/examples/counter/components/counter.component.ts @@ -25,5 +25,5 @@ export class Counter { @select([ 'pathDemo', 'foo' ]) foo$: Observable; @select([ 'pathDemo', 'foo', 'bar', 0 ]) bar$: Observable; - constructor(private actions: CounterActions) {} + constructor(public actions: CounterActions) {} } diff --git a/examples/counter/components/search.component.ts b/examples/counter/components/search.component.ts index d66dd51..670e3e3 100644 --- a/examples/counter/components/search.component.ts +++ b/examples/counter/components/search.component.ts @@ -28,7 +28,7 @@ export class Search { keyword: string; constructor( - private actions: SearchActions, + public actions: SearchActions, private ngRedux: NgRedux) { } ngOnInit() { diff --git a/examples/counter/package.json b/examples/counter/package.json index bc2518b..f798c7d 100644 --- a/examples/counter/package.json +++ b/examples/counter/package.json @@ -44,7 +44,7 @@ "awesome-typescript-loader": "^2.2.1", "cross-env": "^1.0.7", "node-libs-browser": "^0.5.2", - "typescript": "2.0.0", + "typescript": "2.0.2", "webpack": "^1.9.11", "webpack-dev-server": "^1.9.0" } diff --git a/examples/counter/store/index.ts b/examples/counter/store/index.ts index 2ddc11f..e5c1f1c 100644 --- a/examples/counter/store/index.ts +++ b/examples/counter/store/index.ts @@ -4,7 +4,7 @@ import { counterReducer } from './counter.reducer'; import { IPathDemoData, pathDemoReducer } from './path-demo.reducer'; import { ISearchState, searchReducer } from './search.reducer'; -export interface IAppState { +export class IAppState { counter?: number; pathDemo?: IPathDemoData; search?: ISearchState; diff --git a/package.json b/package.json index 2bc0c04..63dc25c 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,12 @@ { "name": "ng2-redux", - "version": "4.0.0-beta.3", + "version": "4.0.0-beta.6-pre-1", "description": "Angular 2 bindings for Redux", "main": "./lib/index.js", "scripts": { - "build": "rimraf ./lib; npm uninstall @types/chai @types/sinon-chai; tsc; npm install @types/chai@3.4.31 @types/sinon-chai@2.7.26", + "prebuild": "rimraf ./lib; npm uninstall @types/chai @types/sinon-chai;", + "postbuild": "npm install @types/chai@3.4.31 @types/sinon-chai@2.7.26; rimraf \"src/**/*.ngfactory.ts\"", + "build": "ngc -p tsconfig.json;", "test": "rimraf coverage && npm run lint && npm run cover", "mocha": "mocha --opts mocha.opts", "lint": "tslint 'src/**/*.ts' 'examples/counter/**.ts' --exclude 'examples/counter/node_modules'", @@ -48,12 +50,18 @@ "homepage": "https://github.com/angular-redux/ng2-redux#readme", "devDependencies": { "@angular/core": "^2.0.0", + "@angular/common": "^2.0.0", "@types/chai": "^3.4.31", "@types/es6-shim": "0.0.30", "@types/mocha": "^2.2.30", "@types/node": "^6.0.36", "@types/sinon": "^1.16.28", "@types/sinon-chai": "^2.7.26", + "@angular/compiler": "^2.0.0", + "@angular/compiler-cli": "^0.6.0", + "@angular/platform-browser": "^2.0.0", + "@angular/platform-browser-dynamic": "^2.0.0", + "@angular/platform-server": "^2.0.0", "awesome-typescript-loader": "^2.2.1", "chai": "^3.5.0", "es6-shim": "^0.35.0", @@ -69,7 +77,7 @@ "symbol-observable": "^1.0.1", "ts-node": "^1.3.0", "tslint": "^3.11.0", - "typescript": "^2.0.0", + "typescript": "^2.0.2", "zone.js": "^0.6.21" }, "peerDependencies": { @@ -103,4 +111,4 @@ "functions": 60, "statements": 60 } -} +} \ No newline at end of file diff --git a/src/components/ng-redux.module.ts b/src/components/ng-redux.module.ts deleted file mode 100644 index 088593f..0000000 --- a/src/components/ng-redux.module.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { NgModule } from '@angular/core'; -import { NgRedux } from './ng-redux'; - -@NgModule({ - providers: [NgRedux] -}) -export class NgReduxModule { - -} diff --git a/src/index.ts b/src/index.ts index ac00b4e..61f48ba 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,11 +2,19 @@ import { NgModule } from '@angular/core'; import { NgRedux } from './components/ng-redux'; import { DevToolsExtension } from './components/dev-tools'; import { select } from './decorators/select'; +import { ModuleWithProviders } from '@angular/core'; @NgModule({ - providers: [ NgRedux, DevToolsExtension ], + }) -class NgReduxModule {} +class NgReduxModule { + static forRoot(): ModuleWithProviders { + return { + ngModule: NgReduxModule, + providers: [NgRedux] + }; + } +} export { NgReduxModule, diff --git a/src/utils/wrap-action-creators.ts b/src/utils/wrap-action-creators.ts index e14cbe8..ca3743e 100644 --- a/src/utils/wrap-action-creators.ts +++ b/src/utils/wrap-action-creators.ts @@ -3,7 +3,9 @@ import { ActionCreator, bindActionCreators as bac, Dispatch } from 'redux'; -export default function wrapActionCreator +function wrapActionCreator | ActionCreatorsMapObject>(actionCreators) { return (dispatch: Dispatch): T => bac(actionCreators, dispatch); } +export default wrapActionCreator; + diff --git a/tsconfig.json b/tsconfig.json index 3d6a22e..a62970f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -19,5 +19,8 @@ "lib", "examples", "**/*.spec.ts" - ] + ], + "angularCompilerOptions": { + "strictMetadataEmit": true + } }