This file contains hidden or 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
| export class ObjectDiff { | |
| isObject(obj: Object): boolean { | |
| return typeof obj === 'object' && !Array.isArray(obj) | |
| } | |
| isArray(obj: Object): boolean { | |
| return Array.isArray(obj) | |
| } |
This file contains hidden or 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
| /** | |
| * Run file | |
| * | |
| * `tsc flatten.ts && node flatten.js` | |
| * | |
| * Given following object: | |
| { | |
| test: "test1", | |
| same: "same", | |
| nested: { |
This file contains hidden or 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
| #!/bin/bash | |
| ############################################### | |
| # To use: | |
| # wget https://raw.github.com/gist/4411254 | |
| # chmod 777 github-ubuntu.sh | |
| # ./github-ubuntu.sh | |
| ############################################### | |
| echo "*****************************************" | |
| echo " Step 1: Check your keys" | |
| echo "*****************************************" |
This file contains hidden or 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
| import { BehaviorSubject, Observable } from 'rxjs' | |
| import { distinctUntilChanged } from 'rxjs/operators' | |
| export class StateAtom<T> { | |
| value$: Observable<T> | |
| private store: BehaviorSubject<T> | |
| private value: T | |
| private initialValue: T |
This file contains hidden or 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
| @Injectable() | |
| export class ViewArticlePageStateService { | |
| private currentState: ViewArticlePageState = initialState | |
| private id: StateAtom<number> = new StateAtom(initialState.id) | |
| private article: StateAtom<Article> = new StateAtom(initialState.article) | |
| private loading: StateAtom<boolean> = new StateAtom(initialState.loading) | |
| private searchTerm: StateAtom<string> = new StateAtom(initialState.searchTerm) | |
| private comments: StateAtom<Comment[]> = new StateAtom(initialState.comments) | |
| private commentsPagination: StateAtom<Params> = new StateAtom(initialState.commentsPagination) |
This file contains hidden or 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
| export interface ViewArticlePageState { | |
| id: number | |
| article: Article | |
| comments: Comment[] | |
| searchTerm: string | |
| loading: boolean | |
| commentsPagination: { | |
| _limit: number | |
| _start: number | |
| _sort: string |
This file contains hidden or 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
| @Injectable() | |
| export class ViewArticlePageStateService { | |
| private currentState: ViewArticlePageState = initialState | |
| private id: StateAtom<number> = new StateAtom(initialState.id) | |
| private article: StateAtom<Article> = new StateAtom(initialState.article) | |
| private loading: StateAtom<boolean> = new StateAtom(initialState.loading) | |
| private searchTerm: StateAtom<string> = new StateAtom(initialState.searchTerm) | |
| private comments: StateAtom<Comment[]> = new StateAtom(initialState.comments) | |
| private commentsPagination: StateAtom<Params> = new StateAtom(initialState.commentsPagination) |
This file contains hidden or 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
| @Injectable() | |
| export class ViewArticlePageStateService { | |
| // ... class properties declaration, omitted for brevity | |
| constructor(private articleService: ArticleService, private commentService: CommentService) { | |
| this.handleEffects() | |
| } | |
| private handleEffects() { | |
| this.id.value$.pipe( |
This file contains hidden or 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
| <ng-container *ngIf="state$ | async as state"> | |
| <article *ngIf="state.article as article" class="article"> | |
| <h1>{{ article.title }}</h1> | |
| <p>{{ article.body }}</p> | |
| </article> | |
| <section class="comments"> | |
| <h1>Comments</h1> | |
| <div *ngIf="state.commentsPagination as pagination" class="pagination"> | |
| View |
This file contains hidden or 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
| import {Directive, ElementRef, Input, Renderer2} from '@angular/core'; | |
| @Directive({ selector: '[appHide]' }) | |
| export class HideDirective { | |
| @Input() set appHide(shouldHide: boolean) { | |
| (shouldHide) | |
| ? this.renderer2.setStyle(this.elRef.nativeElement, 'visibility', 'hidden') | |
| : this.renderer2.removeStyle(this.elRef.nativeElement, 'visibility'); | |
| } |
OlderNewer