This file contains hidden or 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
// Render a template string or function to a node | |
const render = (template, node) => { | |
if (!node) return; | |
node.innerHTML = (typeof template === 'function' ? template() : template); | |
// Dispatch event on render | |
const event = new CustomEvent('elementRenders', { bubbles: true }); | |
node.dispatchEvent(event); | |
return node; | |
}; |
This file contains hidden or 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
navigator.getUserMedia( { video: true, audio: true }, (stream) => { | |
localStream = stream; | |
const cameraBox = document.getElementById('camera-box'); | |
cameraBox.setAttribute('src', URL.createObjectURL( stream ) ); | |
init(); | |
}, (error) => { | |
alert('error accessing usermedia ' + error.toString() ); | |
}); |
This file contains hidden or 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
customElements.define('my-element', class extends HTMLElement { | |
constructor() { | |
super(); | |
const shadow = this.attachShadow({mode: 'open'}); | |
shadow.innerHTML = ` | |
<style> #custom-shadow { color: red; } ::slotted(h1) { font-size: 38px; } :host { width: 600px; }</style> | |
<slot id="headerSlot" name="header"></slot> | |
<div id="custom-shadow">My custom shadow element</div> | |
<slot id="footerSlot" name="footer"></slot> | |
`; |
This file contains hidden or 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 printer = (function() { | |
let printerInstance; | |
function create() { | |
function print() { | |
console.log("Printing document..."); | |
} | |
function turnOn() { | |
console.log("Turning on, checking for paper..."); |
This file contains hidden or 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 Subject() { | |
let context = this; | |
this.observers = []; | |
return { | |
subscribeObserver(observer) { | |
context.observers.push(observer); | |
}, | |
unsubscribeObserver(observer) { | |
const idx = context.observers.indexOf(observer); |
This file contains hidden or 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 Queue() { | |
this._storage = {}; | |
this._oldestIndex = 1; | |
this._newestIndex = 1; | |
} | |
Queue.prototype.size = function() { | |
return this._oldestIndex - this._newestIndex; | |
}; |
This file contains hidden or 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 Node(value) { | |
this.data = value; | |
this.previous = null; | |
this.next = null; | |
} | |
function DoublyList() { | |
this._length = 0; | |
this.head = null; | |
this.tail = null; |
This file contains hidden or 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 Node(data) { | |
this.data = data; | |
this.next = null; | |
} | |
function SinglyList() { | |
this._length = 0; | |
this.head = null; | |
} |
This file contains hidden or 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 Stack() { | |
this._size = 0; | |
this._storage = {}; | |
} | |
Stack.prototype.push = function(data) { | |
this._size += 1; | |
this._storage[this._size] = data; | |
}; |
This file contains hidden or 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 isObjectEqual(a, b) { | |
let aProps = Object.getOwnPropertyNames(a), | |
bProps = Object.getOwnPropertyNames(b); | |
if (aProps.length !== bProps.length) { | |
return false; | |
} | |
for (let i = 0; i < aProps.length; i++) { | |
let propName = aProps[i]; |