Skip to content

Instantly share code, notes, and snippets.

@alexnoise79
alexnoise79 / deep-patch.ts
Created March 5, 2023 09:03
deep patch functions to update from websockets
export function updateObject<T>(obj: T, partial: T): T {
if (!partial) {
return obj;
}
return Object.keys(partial).reduce((acc, key) => {
const value = partial[key];
if (Array.isArray(value)) {
// @ts-ignore
acc[key] = updateArray(obj[key], value);
} else if (typeof value === 'object' && value !== null) {
@alexnoise79
alexnoise79 / slide-toggle.component.html
Created March 14, 2019 15:43
Angular 2 Two and Tri state slide toggle component,
<ng-container [ngSwitch]="triState">
<ng-container *ngSwitchCase="true">
<input type="radio" id="mf" class="trigger mf" [value]="false" [(ngModel)]="model" (change)="update(model)" [disabled]="isDisabled">
<label for="mf"></label>
<input id="st_{{formControlName}}_off" [name]="formControlName" type="radio" class="trigger minus" [value]="-1" [(ngModel)]="model" (change)="update(model)" [disabled]="isDisabled">
<label for="st_{{formControlName}}_off">
<div class="pin">
<div class="ink"></div>
@alexnoise79
alexnoise79 / _date-selector.scss
Last active March 12, 2019 16:45
Angular2 date-selector component, made of 3 options
date-selector {
@include flexbox((display: flex));
width: 100%;
select {
width: auto;
&.month {
@include flex(1 0 auto);
margin: 0 6px;