Created
November 6, 2017 23:13
-
-
Save daniel-williams/e1367a1095d19eebfcdbb6e6f4976fec to your computer and use it in GitHub Desktop.
My Angular Snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Angular Component": { | |
"prefix": "ngc", | |
"body": [ | |
"import { Component } from '@angular/core';", | |
"", | |
"@Component({", | |
" selector: '${2:$TM_FILENAME_BASE}',", | |
" templateUrl: './${2:$TM_FILENAME_BASE}.component.html',", | |
" styleUrls: ['./${2:$TM_FILENAME_BASE}.component.scss']", | |
"})", | |
"export class ${1:class} {$0}", | |
"" | |
], | |
"description": "Simple Angular component." | |
}, | |
"Redux Action for NgRedux": { | |
"prefix": "redux.a", | |
"body": [ | |
"import { Injectable } from '@angular/core';", | |
"import { NgRedux, select } from '@angular-redux/store';", | |
"", | |
"import { IAppState } from '../';", | |
"", | |
"", | |
"@Injectable()", | |
"export class ${1}Actions {", | |
" static TOGGLE_PANEL = 'TOGGLE_PANEL';", | |
"", | |
" constructor(private ngRedux: NgRedux<IAppState>) {}", | |
"", | |
" togglePanel(): void {", | |
" this.ngRedux.dispatch({", | |
" type: ${1}Actions.TOGGLE_PANEL,", | |
" });", | |
" }", | |
"}" | |
], | |
"description": "Simple NgRedux Action class." | |
}, | |
"Redux Reducer for NgRedux": { | |
"prefix": "redux.r", | |
"body": [ | |
"import { Action } from '../Action';", | |
"", | |
"import { ${1}Actions as Actions } from './${2}.actions';", | |
"", | |
"", | |
"export interface I${1}State {", | |
" showPanel?: boolean;", | |
"}", | |
"", | |
"export const initial${1}State: I${1}State = {", | |
" showPanel: false,", | |
"};", | |
"", | |
"export function ${2}Reducer(state: I${1}State = initial${1}State, action: Action) {", | |
" const { type, payload } = action;", | |
"", | |
" switch(type) {", | |
" case Actions.TOGGLE_PANEL: {", | |
" return mergeState(state, {", | |
" showPanel: !state.showPanel,", | |
" });", | |
" }", | |
" default: {", | |
" return state;", | |
" }", | |
" }", | |
"}", | |
"", | |
"const mergeState = (currentState: I${1}State, mergeState: I${1}State) => Object.assign({}, currentState, mergeState);" | |
], | |
"description": "Simple NgRedux Action class." | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment