Skip to content

Instantly share code, notes, and snippets.

View LironHazan's full-sized avatar
🎸
666 -> 🦀

LironH LironHazan

🎸
666 -> 🦀
View GitHub Profile
@LironHazan
LironHazan / vue-plugins-in-10-min.js
Last active October 22, 2018 21:18
quick gist for a short talk about vue plugins
//Vue Plugins:
// Link to live stackblitz: https://stackblitz.com/edit/vue-plugins-demo-ts?file=index.ts
// How:
// Add global methods: Vue.myGlobalFn (e.g vue-custom-element)
// Add global assets (directives/filters/mixin..)
// Add instance methods Vue.prototype.someFn
// API of all of the above (e.g vue-router)
  • On default changeDetection, every async task will trigger changed detection (as dirty checking - comparing new value to old and decides if to update the view)

  • On onPush the component depends by its @Input() and changeDetection will be triggred when:

  1. Input reference changed (which is awsome cause it forces you to work with immutable objects).
  2. If a componnent custom/dom event is triggred (or its child event).
  3. When explicitly running the detectChanges() of ChangeDetectorRef or by ApplicationRef.tick() which will run change detection upon all application.
import {Component, Inject, OnInit} from '@angular/core';
import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material";
import {SelectedValueModel} from "../../incident.model";
import {UsersShareService} from "../../../../../services/store/users-share.service";
import {Subscription} from "rxjs/internal/Subscription";
import {IncidentService} from "../../incident.service";
@Component({
selector: 'app-more-info-dialog',
styleUrls: ['./more-info-dialog.component.scss'],
@LironHazan
LironHazan / partial-sec-component.ts
Created October 15, 2018 09:45
reactive-forms-angular
// component part
// 1. declare formgroup which contains wanted form control
public securityForm: FormGroup = new FormGroup({
classificationItem: new FormControl()
});
private classification: ClassificationModel;
private fb: FormBuilder;
ngOnInit() {
@LironHazan
LironHazan / theme.const.ts
Last active October 29, 2018 06:57
for a medium post about css vars
export const themes = {
oceanBlueThemProps : {
'--background' : 'aliceblue',
'--text-color': '#0F0F0F',
'--tasks-background': 'cornflowerblue'
},
deepPurpleThemProps: {
'--background' : 'purple',
'--text-color': 'whitesmoke',
'--tasks-background': 'rebeccapurple'
@LironHazan
LironHazan / theme.direcive-snippet.ts
Last active October 29, 2018 06:52
for a medium post
ngOnInit() {
this.themServiceSubscription = this.themService.observeActiveThemeChane()
.subscribe(themeName => {
this.themeName = themeName ;
this.updateTheme(this.themeName);
});
}
updateTheme(themeName) {
const element = this.elementRef.nativeElement;
@LironHazan
LironHazan / multiple-requests-rxjs6.ts
Created November 4, 2018 11:38
using forkJoin rxjs 6
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import {IncidentsDTO} from './incidents.model';
import {Observable} from "rxjs/internal/Observable";
import {forkJoin} from 'rxjs';
import {catchError} from "rxjs/operators";
@Injectable({
@LironHazan
LironHazan / grab-git-info.js
Created November 5, 2018 10:02
used for grabbing the commit hash etc..
const { gitDescribeSync } = require('git-describe');
const { writeFileSync } = require('fs');
const path = require('path');
const info = gitDescribeSync();
const infoJson = JSON.stringify(info, null, 2);
writeFileSync(path.join(__dirname, '/src/git-version.json'), infoJson);
@LironHazan
LironHazan / typings.d.ts
Created November 6, 2018 09:53
typings
declare module '*.json' {
const value: any;
export default value;
}
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class LocalStorageWrapperService {
constructor() { }
private localStorage = localStorage;