Skip to content

Instantly share code, notes, and snippets.

View arv's full-sized avatar
👋
Reflecting...

Erik Arvidsson arv

👋
Reflecting...
View GitHub Profile
@arv
arv / x.md
Last active August 29, 2015 14:02
@@new and @@create
class B {
  constructor(x) {
    this.x = x;
  }
  static [Symbol.create]() {
    var o = super();
    weakMap.set(o, 123456789);  // Dom wrapper foo
    return o;
 }
@arv
arv / designer.html
Created June 3, 2014 15:59
designer
<link rel="import" href="../core-scaffold/core-scaffold.html">
<link rel="import" href="../core-header-panel/core-header-panel.html">
<link rel="import" href="../core-menu/core-menu.html">
<link rel="import" href="../core-item/core-item.html">
<link rel="import" href="../core-icon-button/core-icon-button.html">
<link rel="import" href="../core-toolbar/core-toolbar.html">
<link rel="import" href="../core-menu/core-submenu.html">
<link rel="import" href="../google-map/google-map.html">
<polymer-element name="my-element">
@arv
arv / createAttributeNS.js
Created March 13, 2014 14:55
Implementation of createAttributeNS and setAttributeNodeNS
if (!Document.prototype.createAttributeNS) {
Document.prototype.createAttributeNS = function(namespaceURI, qualifiedName) {
var dummy = this.createElement('dummy');
dummy.setAttributeNS(namespaceURI, qualifiedName, '');
var attr = dummy.attributes[0];
dummy.removeAttributeNode(attr);
return attr;
};
}
@arv
arv / Branded.js
Last active August 29, 2015 13:56
Secure shadow dom
(function() {
'use strict';
function uncurryThis(f) {
return f.call.bind(f);
}
var ShadowRoot = window.ShadowRoot;
var createShadowRoot = uncurryThis(Element.prototype.createShadowRoot);
var ownerDocumentGetter = uncurryThis(Object.getOwnPropertyDescriptor(Node.prototype, 'ownerDocument').get);
@arv
arv / Document.registor.md
Last active December 30, 2015 19:38
document.register with a functionThe main difference between this and the current LC is that it takes a Function object instead of an Object. The Function's @@create method is updated to create instances that are real elements.

Register

When called, the register method must run these steps:

Input

  • ENVIRONMENT, the unit of related similar-origin browsing contexts
  • DOCUMENT, the context object of the method
  • NAME, the custom element name of the element being registered
  • FUNCTION, the custom element constructor function, optional
@arv
arv / gist:6528418
Created September 11, 2013 19:17 — forked from sorvell/gist:6527156
<!DOCTYPE html>
<html>
<head>
<script src="../polymer/polymer.js"></script>
</head>
<body>
<template id="host-template">
<div>host shadowRoot</div>
<content></content>
</template>
@arv
arv / soduko.js
Last active December 18, 2015 08:28 — forked from BrendanEich/gist:5753666
ES6 syntax
// XXX should be standard (and named clone, after Java?)
Object.prototype.copy = function () {
let o = {}
for (let i in this)
o[i] = this[i]
return o
}
// Containment testing for arrays and strings that should be coherent with their iterator.
Array.prototype.contains = String.prototype.contains = function (e) {
@arv
arv / compile.sh
Last active December 17, 2015 04:59
Shows how you can build a smaller js binary to only parse (and print) some ES6 code.
traceur --out out.js parser.js
# Traceur does not strip dead code. Use Uglify2.
uglifyjs src/runtime/runtime.js out.js -cm -o out.min.js
@arv
arv / DOMImpl.js
Last active December 11, 2015 23:18
document.register with classes
// Create is defined in the latest ES6 spec. Foo[create]() is used to create the instance
// when you do "new Foo". This instance is then passed to Foo.call(instance, <args>)
import {create} from '@reflect';
Element[create] = function() {
return documemt.createElementNS(this.prototype.namespaceURI, this.prototype.localName)
};
Object.prototype.$super = function() {
var func = arguments.callee.caller;
var name = func.foundName_;
if (!name) {
for (var p in this) {
if (this[p] == func) {
name = p;
break;
}
}