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 / idom.match.js
Last active April 1, 2018 14:46
IDOM match
const matches = function(matchNode, name/*, key */) {
const data = getData(matchNode);
return name === data.name // && key === data.key;
};
function renderDOM(name) {
if (currentNode && matches(currentNode, name/*, key */)) {
return currentNode;
}
@alexzuza
alexzuza / idom.text.js
Created April 1, 2018 14:49
IDOM text
function text(value) {
nextNode();
const node = renderDOM('#text');
// update
// checks for text updates
const data = getData(node);
if (data.text !== value) {
data.text = (value);
node.data = value;
@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();
};
@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 / 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 / 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);
<comp color="#efefef"></comp>
@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();
@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;
}
<input type="text" value="Alexey">
<button>Increment</button>