File

projects/wvr-elements/src/lib/wvr-theme/wvr-theme.component.ts

Implements

OnChanges

Metadata

Index

Properties
Methods
Inputs
Accessors

Constructor

constructor(store: Store)
Parameters :
Name Type Optional
store Store<RootState> No

Inputs

active
Type : boolean
Default value : false
name
Type : string
variants
Type : string

Methods

ngOnChanges
ngOnChanges(changes: SimpleChanges)
Parameters :
Name Type Optional
changes SimpleChanges No
Returns : void

Properties

Private _variants
Type : ThemeVariants

Accessors

variants
setvariants(value: string)
Parameters :
Name Type Optional
value string No
Returns : void
import { ChangeDetectionStrategy, Component, Input, OnChanges, SimpleChanges } from '@angular/core';
import { Store } from '@ngrx/store';
import * as JSON5 from 'json5';
import { RootState } from '../core/store';
import * as ThemeActions from '../core/theme/theme.actions';
import { ThemeVariants } from '../shared/theme';

@Component({
  selector: 'wvr-theme-component',
  template: '<ng-content></ng-content>',
  changeDetection: ChangeDetectionStrategy.Default
})
export class WvrThemeComponent implements OnChanges {

  private _variants: ThemeVariants;

  // tslint:disable-next-line: prefer-readonly
  @Input() private name: string;

  // tslint:disable-next-line: prefer-readonly
  @Input() private active = false;

  // tslint:disable-next-line: prefer-readonly
  @Input() set variants(value: string) {
    this._variants = JSON5.parse(value);
  }

  constructor(private readonly store: Store<RootState>) {

  }

  ngOnChanges(changes: SimpleChanges): void {
    if (this.name && this._variants) {
      this.store.dispatch(ThemeActions.add({
        name: this.name,
        theme: this._variants
      }));
    }

    if (this.name && this.active) {
      this.store.dispatch(ThemeActions.select({
        name: this.name
      }));
    }

  }

}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""