Skip to content

Instantly share code, notes, and snippets.

View alexzuza's full-sized avatar
🎯
Focusing

Alexey Zuev alexzuza

🎯
Focusing
View GitHub Profile
@alexzuza
alexzuza / iv-need-to-render.html
Created May 19, 2018 13:00
Iv need to render
<h1>Hello, Alexey</h1>
<ul>
<li>
Counter: <span>1</span>
</li>
</ul>
@alexzuza
alexzuza / detect-changes.ts
Created May 19, 2018 13:01
Ivy detect changes
export function detectChanges<T>(component: T): void {
const hostNode = _getComponentHostLElementNode(component);
ngDevMode && assertNotNull(hostNode.data, 'Component host node should be attached to an LView');
const componentIndex = hostNode.tNode !.flags >> TNodeFlags.DirectiveStartingIndexShift;
const def = hostNode.view.tView.directives ![componentIndex] as ComponentDef<T>;
detectChangesInternal(hostNode.data as LView, hostNode, def, component);
}
export function tick<T>(component: T): void {
const rootView = getRootView(component);
const rootComponent = (rootView.context as RootContext).component;
const hostNode = _getComponentHostLElementNode(rootComponent);
ngDevMode && assertNotNull(hostNode.data, 'Component host node should be attached to an LView');
renderComponentOrTemplate(hostNode, rootView, rootComponent);
}
@alexzuza
alexzuza / ivy-schedule-tick.ts
Created May 19, 2018 13:04
IVy schedule tick
export function scheduleTick<T>(rootContext: RootContext) {
if (rootContext.clean == _CLEAN_PROMISE) {
let res: null|((val: null) => void);
rootContext.clean = new Promise<null>((r) => res = r);
rootContext.scheduler(() => {
tick(rootContext.component);
res !(null);
rootContext.clean = _CLEAN_PROMISE;
});
}
@alexzuza
alexzuza / ivy-mark-view-dirty.ts
Created May 19, 2018 13:05
Ivy mark view dirty
export function markViewDirty(view: LView): void {
let currentView: LView|null = view;
while (currentView.parent != null) {
currentView.flags |= LViewFlags.Dirty;
currentView = currentView.parent;
}
currentView.flags |= LViewFlags.Dirty;
ngDevMode && assertNotNull(currentView !.context, 'rootContext');
@alexzuza
alexzuza / ivy-mark-dirty.ts
Created May 19, 2018 13:07
IVy mark dirty
export function markDirty<T>(component: T) {
ngDevMode && assertNotNull(component, 'component');
const lElementNode = _getComponentHostLElementNode(component);
markViewDirty(lElementNode.view);
}
@alexzuza
alexzuza / ivy_child.component.html
Created May 19, 2018 18:17
IVy child component
<h2>Child {{ prop1 }}</h2>
<sub-child [item]="3"></sub-child>
<sub-child *ngFor="let item of items" [item]="item"></sub-child>
@alexzuza
alexzuza / lazy-load-script.service.ts
Created October 30, 2018 15:42
Load script on demand
import { Injectable, Inject } from '@angular/core';
import { ReplaySubject, Observable } from 'rxjs';
import { DOCUMENT } from '@angular/common';
@Injectable()
export class LazyLoadingScriptService {
_loadedLibraries: { [url: string]: ReplaySubject<any> } = {};
constructor(@Inject(DOCUMENT) private readonly document: any) { }
{
"name": "ivy8",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"postinstall": "ivy-ngcc",
"start": "ng serve",
"build": "ng build --prod",
"test": "ng test",
"lint": "ng lint",
@alexzuza
alexzuza / package.json
Created January 18, 2019 04:30
Angular CLI Ivy experiment
{
"name": "ivy8",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"postinstall": "ivy-ngcc",
"start": "ng serve",
"build": "ng build --prod",
"test": "ng test",
"lint": "ng lint",