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 / 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);
}
@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>
<input type="text" value="Alexey">
<button>Increment</button>
@alexzuza
alexzuza / ivy-elref-template.ts
Last active May 19, 2018 12:58
Ivy elRef template
@Component({
...,
template: '<ng-template #foo></ng-template>'
})
class SomeComponent {
@ViewChild('foo', {read: ElementRef}) query;
}
@alexzuza
alexzuza / one-time-ivy.ts
Created May 19, 2018 12:56
One time ivy
var _c0 = ["color", "#efefef"];
AppComponent.ngComponentDef = i0.ɵdefineComponent({
type: AppComponent,
selectors: [["my-app"]],
...
template: function AppComponent_Template(rf, ctx) {
// create mode
if (rf & 1) {
i0.ɵE(0, "child", _c0); <========== used only in create mode
i0.ɵe();
<comp color="#efefef"></comp>
@alexzuza
alexzuza / one-time-engine.ts
Last active May 19, 2018 12:54
One time initialization engine
function updateDirectives(_ck,_v) {
var currVal_0 = '#efefef';
_ck(_v,1,0,currVal_0);
@alexzuza
alexzuza / ivy.example.ts
Last active May 19, 2018 18:07
Example ivy
@Component({
selector: 'my-app',
template: `
<h2>Parent</h2>
<child [prop1]="x"></child>
`
})
export class AppComponent {
x = 1;
}
@alexzuza
alexzuza / idom.test.js
Created April 1, 2018 14:52
IDOM test
function render(data) {
elementOpen('h1');
{
text('Hello, ' + data.user)
}
elementClose('h1');
elementOpen('ul')
{
elementOpen('li');
{
@alexzuza
alexzuza / IDOM.patch.js
Last active April 4, 2018 20:26
IDOM patch
function patch(node, fn, data) {
currentNode = node;
enterNode();
fn(data);
exitNode();
};