Skip to content

Instantly share code, notes, and snippets.

View nirkaufman's full-sized avatar
🎯
Focusing

Nir Kaufman nirkaufman

🎯
Focusing
View GitHub Profile
@nirkaufman
nirkaufman / tiny-observable.js
Created December 28, 2020 15:24
Adventures in JavaScript
// *******************************
// Just a wrapper around callbacks,
// So we can use the same API - and state of mind
// *******************************
// helper to create observable
function createObservable(subscribe) {
return {
subscribe,
// Holds a state (currentUser), end expose
// methods to alter it
class Auth {
constructor() {
this.currentUser = null;
}
signIn() {
this.currentUser = {name: "Nir"};
}
function renderElement(element) {
const {type, props, children} = element;
// component support
if(typeof type === 'function') {
return renderElement(type(props));
}
const domElement = document.createElement(type);
import {Component} from '@angular/core';
import {Card, CardTypes} from "./cards/cards.types";
@Component({
selector: 'app-root',
template: `
<div class="container m-5">
<ng-container *cardDeck="let card for cards; primary customPrimary"></ng-container>
import {
ChangeDetectorRef,
Component,
ComponentFactory,
ComponentFactoryResolver,
ElementRef,
Injector,
OnInit,
Renderer2,
ViewChild,
@nirkaufman
nirkaufman / chain_start.ts
Last active September 13, 2020 15:50
DP Starters
enum Status {Received, Pending, InProcess, Sent, Delivered }
enum Priority { Low, Medium, High, Urgent }
interface Order {
id: number;
itemCount: number;
ordered: string;
expectedDelivery: string;
status: Status,
priority: Priority;
let hooks = [];
let idx = 0;
export function useState(initialState) {
let state = hooks[idx] || initialState;
let _idx = idx;
function setState(newState) {
hooks[_idx] = newState;
render();
const website = `nir.life`
const btn = document.createElement('button');
function map(transformFn) {
return function(inputValueProvider) {
return createObservable(
function (onValue, onError, onComplete) {
inputValueProvider.subscribe(
(value) => onValue(transformFn(value)),
import {BehaviorSubject, Observable} from "rxjs";
import {Inject, Injectable, InjectionToken} from "@angular/core";
export interface Action {
type: string;
}
export interface ActionHandler {
handleAction(currentState: any, action: Action): any;
}
import {AfterViewInit, Component, QueryList, ViewChildren} from '@angular/core';
import {NgComponentOutlet} from "@angular/common";
// Something to loop over
@Component({
template: `<p>Component Type A</p>`
})
class ComponentA {}
@Component({