Skip to content

Commit

Permalink
feat(state): add selectKind action
Browse files Browse the repository at this point in the history
  • Loading branch information
ayshiff authored and manekinekko committed Mar 23, 2021
1 parent 8491d27 commit 80af070
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions apps/xlayers/src/app/core/state/page.state.ts
Expand Up @@ -4,13 +4,17 @@ import {
CodeGenKind,
XlayersExporterNavBar,
} from '../../editor/code/editor-container/codegen/codegen.service';
import { SketchMSPageLayer } from '@xlayers/sketchtypes';
import { Injectable } from '@angular/core';

export interface CodeGenSettings {
content: XlayersNgxEditorModel[];
kind: CodeGenKind;
buttons: XlayersExporterNavBar;
content?: XlayersNgxEditorModel[];
buttons?: XlayersExporterNavBar;
}

export class SelectCodegenKind {
static readonly type = '[CodeGen] Select Kind';
constructor(public kind: CodeGenKind) {}
}

export class CodeGen {
Expand All @@ -22,8 +26,11 @@ export class CodeGen {
) {}
}

@State<SketchMSPageLayer>({
@State<CodeGenSettings>({
name: 'codegen',
defaults: {
kind: 1,
},
})
@Injectable()
export class CodeGenState {
Expand All @@ -32,6 +39,18 @@ export class CodeGenState {
return codegen;
}

@Action(SelectCodegenKind)
selectKind(
{ setState, getState }: StateContext<CodeGenSettings>,
action: SelectCodegenKind
) {
const state = getState();
setState({
...state,
kind: action.kind,
});
}

@Action(CodeGen)
selectCodegen({ setState }: StateContext<CodeGenSettings>, action: CodeGen) {
setState({
Expand Down

0 comments on commit 80af070

Please sign in to comment.