Skip to content

Instantly share code, notes, and snippets.

View siddharthpal's full-sized avatar
🎯
Focusing

siddharthpal

🎯
Focusing
View GitHub Profile
@siddharthpal
siddharthpal / app.js
Created October 13, 2019 17:44
Invoking custom element method
const todoAngularElement = document.getElementsByTagName("todo-root-angular-element")[0];
if (todoAngularElement) {
todoAngularElement.pushTodoItem(newTodo);
}
@siddharthpal
siddharthpal / todo.component.ts
Last active October 13, 2019 17:40
Wrapping @input method inside ngZone run method
@Input() public pushTodoItem = todo => {
this.ngZone.run(() => {
this.todos.push(todo);
});
};
@siddharthpal
siddharthpal / todo-wrapper.module.ts
Last active October 13, 2019 18:55
Registering Custom Element
@NgModule({
imports: [BrowserModule, TodoModule],
entryComponents: [TodoComponent]
})
export class TodoWrapperModule {
constructor(private injector: Injector) {
const todoElement = createCustomElement(TodoComponent, {
injector: this.injector
});
customElements.define('todo-root-angular-element', todoElement);
@siddharthpal
siddharthpal / app.html
Last active October 13, 2019 17:11
Listening to custom element events in AngularJS
<div>
<todo-root-angular-element class="todo-app" ng-on-add_todo_emitter="add($event)" ng-on-remove_todo_emitter="remove($event)"></todo-root-angular-element>
</div>
@siddharthpal
siddharthpal / todo-wrapper.module.ts
Last active October 13, 2019 16:46
Compiling Angular Component to Custom Element
@NgModule({
imports: [BrowserModule, TodoModule],
entryComponents: [TodoComponent]
})
export class TodoWrapperModule {
constructor(private injector: Injector) {
const todoElement = createCustomElement(TodoComponent, {
injector: this.injector
});
customElements.define('todo-root-angular-element', todoElement);
@siddharthpal
siddharthpal / polling.ts
Last active November 9, 2019 14:33
Polling multiple resources with exponential back-off strategy and 3 times retry for failed http requests. #pool-polling #rxjs6 #reactive-programming
import { timer as observableTimer, Subscription, interval, of, concat, SchedulerLike, asyncScheduler, Observable } from 'rxjs';
import { takeWhile, tap, take, switchMap, repeat, retryWhen, scan, mapTo, expand, exhaustMap } from 'rxjs/operators';
import { Injectable, Inject } from '@angular/core';
import { HttpClient } from '@angular/common/http';
export interface IntervalBackoffConfig {
initialInterval: number;
maxInterval?: number;