Skip to content

feat(aot): Support AoT - #223 - #226

Merged
e-schultz merged 1 commit into
masterfrom
feat-support-aot
Oct 19, 2016
Merged

e-schultz merged 1 commit into
masterfrom
feat-support-aot

Conversation

@e-schultz

Copy link
Copy Markdown
Member
  • Start adding support for AoT
  • Add dev dependencies for angular compiler
  • Update tsconfig to tell ngc to emit metadata

@e-schultz

Copy link
Copy Markdown
Member Author

@SethDavenport @dagstuan haven't a chance to test this yet, just starting to get the files generated for AoT

@spock123

Copy link
Copy Markdown

I'm tempted to try this out :)

@SethDavenport

Copy link
Copy Markdown
Member

@bennett000 has been messing around with AoT quite a bit recently, he might have some insight.

@bennett000

Copy link
Copy Markdown
Collaborator

IIRC there is an issue (I think @angular/compiler-cli team is working on fixing) with meta functions being passed to @select but that should only affect consumer builds?

* Start adding support for AoT
* Add dev dependencies for angular compiler
* Update tsconfig to tell ngc to emit metadata

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

```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<IAppState>) {

    ngRedux.configureStore(rootReducer,{});
  }
}

```

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<IAppState>, 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<string>;
}
```

**after**

```js
import { NgRedux } from 'ng2-redux';
export class MyComponent {
  thing$:Observable<string>;
  constructor(private ngRedux:NgRedux<MyAppState>) {

  }
  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.
@e-schultz
e-schultz merged commit 130f93b into master Oct 19, 2016
@SethDavenport
SethDavenport deleted the feat-support-aot branch December 27, 2016 04:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants