Skip to content

Commit

Permalink
fix(module): make withConfig AOT compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
CaerusKaru authored and ThomasBurleson committed Jul 2, 2018
1 parent 28bc2ae commit 85e3145
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/apps/demo-app/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const PRINT_BREAKPOINTS = [{
BrowserAnimationsModule,
RoutingModule,
DemoMaterialModule,
FlexLayoutModule,
FlexLayoutModule.withConfig({useColumnBasisZero: false}),
],
providers: [{provide: BREAKPOINT, useValue: PRINT_BREAKPOINTS, multi: true}],
bootstrap: [AppComponent]
Expand Down
3 changes: 2 additions & 1 deletion src/lib/flex/flex/flex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,9 @@ export class FlexDirective extends BaseDirective implements OnInit, OnChanges, O
protected _validateValue(grow: number|string,
shrink: number|string,
basis: string|number|FlexBasisAlias) {
let addFlexToParent = this.layoutConfig.addFlexToParent !== false;
// The flex-direction of this element's flex container. Defaults to 'row'.
let layout = this._getFlexFlowDirection(this.parentElement, this.layoutConfig.addFlexToParent);
let layout = this._getFlexFlowDirection(this.parentElement, addFlexToParent);
let direction = (layout.indexOf('column') > -1) ? 'column' : 'row';

let max = isFlowHorizontal(direction) ? 'max-width' : 'max-height';
Expand Down
42 changes: 18 additions & 24 deletions src/lib/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ import {
NgModule,
Optional,
PLATFORM_ID,
Provider,
} from '@angular/core';
import {isPlatformServer} from '@angular/common';
import {
SERVER_TOKEN,
DEFAULT_CONFIG,
LayoutConfigOptions,
LAYOUT_CONFIG,
BreakPoint,
Expand Down Expand Up @@ -50,30 +48,26 @@ export class FlexLayoutModule {
*/
static withConfig(configOptions: LayoutConfigOptions,
breakpoints?: BreakPoint|BreakPoint[]): ModuleWithProviders {
const config = Object.assign({}, DEFAULT_CONFIG);
const moduleProviders: Provider[] = [];

for (const key in configOptions) {
// If the setting is different and not undefined or null, change it
if (configOptions[key] !== config[key] &&
(configOptions[key] === false || configOptions[key] === true)) {
config[key] = configOptions[key];
}
}

if (configOptions.serverLoaded) {
moduleProviders.push({provide: SERVER_TOKEN, useValue: true});
}

if (Array.isArray(breakpoints)) {
moduleProviders.push({provide: BREAKPOINT, useValue: breakpoints, multi: true});
}

moduleProviders.push({provide: LAYOUT_CONFIG, useValue: config});

return {
ngModule: FlexLayoutModule,
providers: moduleProviders
providers: Array.isArray(breakpoints) ?
configOptions.serverLoaded ?
[
{provide: LAYOUT_CONFIG, useValue: configOptions},
{provide: BREAKPOINT, useValue: breakpoints, multi: true},
{provide: SERVER_TOKEN, useValue: true},
] : [
{provide: LAYOUT_CONFIG, useValue: configOptions},
{provide: BREAKPOINT, useValue: breakpoints, multi: true},
]
:
configOptions.serverLoaded ?
[
{provide: LAYOUT_CONFIG, useValue: configOptions},
] :
[
{provide: LAYOUT_CONFIG, useValue: configOptions},
]
};
}

Expand Down

0 comments on commit 85e3145

Please sign in to comment.