Skip to content

Instantly share code, notes, and snippets.

@AprilArcus
Created January 14, 2016 21:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AprilArcus/b081520da9bf5be23545 to your computer and use it in GitHub Desktop.
Save AprilArcus/b081520da9bf5be23545 to your computer and use it in GitHub Desktop.
/* @flow */
declare class SVGElement extends Element {}
declare class HTMLParagraphElement extends HTMLElement {
align: string;
}
type ElementRegistrationOptions<T> = {
prototype?: {
createdCallback?: () => void;
attachedCallback?: () => void;
detachedCallback?: () => void;
attributeChangedCallback?: (
attributeLocalName: string,
oldAttributeValue: ?string,
newAttributeValue: ?string,
attributeNamespace: ?string
) => void;
};
extends?: string;
}
declare class Document extends Node {
registerElement<T: HTMLElement|SVGElement>(
type: string,
options?: ElementRegistrationOptions<T>
): Class<T>;
}
declare var document: Document;
export const injectCallbacks = ({
createdCallback,
attachedCallback,
detachedCallback,
attributeChangedCallback
}: {
createdCallback: () => void,
attachedCallback: () => void,
detachedCallback: () => void,
attributeChangedCallback: (
attributeLocalName: string,
oldAttributeValue: ?string,
newAttributeValue: ?string,
attributeNamespace: ?string
) => void
}): Class<HTMLParagraphElement> => document.registerElement(
'jus-ti-fied', {
extends: 'p',
prototype: Object.create(
HTMLParagraphElement.prototype, {
createdCallback: { value: createdCallback },
attachedCallback: { value: attachedCallback },
detachedCallback: { value: detachedCallback },
attributeChangedCallback: { value: attributeChangedCallback }
}
)
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment