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
// ******************************* | |
// 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, |
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
// Holds a state (currentUser), end expose | |
// methods to alter it | |
class Auth { | |
constructor() { | |
this.currentUser = null; | |
} | |
signIn() { | |
this.currentUser = {name: "Nir"}; | |
} |
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
function renderElement(element) { | |
const {type, props, children} = element; | |
// component support | |
if(typeof type === 'function') { | |
return renderElement(type(props)); | |
} | |
const domElement = document.createElement(type); |
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
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> | |
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
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; |
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
let hooks = []; | |
let idx = 0; | |
export function useState(initialState) { | |
let state = hooks[idx] || initialState; | |
let _idx = idx; | |
function setState(newState) { | |
hooks[_idx] = newState; | |
render(); |
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
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)), |
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
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; | |
} |
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
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({ |
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
import {Component} from '@angular/core'; | |
import {FormControl} from "@angular/forms"; | |
@Component({ | |
selector: 'app-root', | |
template: ` | |
<h1>Angular Playground</h1> | |
<input type="password" | |
[formControl]="inputControl" | |
nkStrongPassword |