Skip to content

Instantly share code, notes, and snippets.

@AprilArcus
Last active January 7, 2016 03:17
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/7024adb7ec765f669e41 to your computer and use it in GitHub Desktop.
Save AprilArcus/7024adb7ec765f669e41 to your computer and use it in GitHub Desktop.
custom element errors
element.js:
------------------------------
/* @flow */
declare class HTMLParagraphElement extends HTMLElement {
align: string
}
type CustomElementCallbacks = {
createdCallback?: () => void;
attachedCallback?: () => void;
detachedCallback?: () => void;
attributeChangedCallback?: (
attributeLocalName: string,
oldAttributeValue: ?string,
newAttributeValue: ?string,
attributeNamespace: ?string
) => void;
}
// http://w3c.github.io/webcomponents/spec/custom/#types-of-callbacks
type ElementRegistrationOptions = {
prototype?: HTMLElement & CustomElementCallbacks;
extends?: string;
}
declare class Document extends Node {
registerElement(type: string, options?: ElementRegistrationOptions): void;
}
declare var document: Document;
document.registerElement(
'jus-ti-fied',
{
extends: 'p',
prototype: Object.create(
HTMLParagraphElement.prototype,
{
createdCallback: {
value: function createdCallback() {
console.log('here I am ^_^ ');
console.log('with content: ', this.textContent);
}
},
attachedCallback: {
value: function attachedCallback() {
console.log('live on DOM ;-) ');
}
},
detachedCallback: {
value: function detachedCallback() {
console.log('leaving the DOM :-( )');
}
},
attributeChangedCallback: {
value: function attributeChangedCallback(name, previousValue, value) {
if (previousValue === null || previousValue === undefined) {
console.log(
'got a new attribute ', name,
' with value ', value
);
} else if (value === null || value === undefined) {
console.log(
'somebody removed ', name,
' its value was ', previousValue
);
} else {
console.log(
name,
' changed from ', previousValue,
' to ', value
);
}
}
}
}
)
}
);
------------------------------
Errors:
------------------------------
src/element.js:0
0:
^ inconsistent use of library definitions
67: detachEvent?: (type: string, listener: EventListener) => void;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ undefined. This type is incompatible with. See: /private/tmp/flow/flowlib_224c089c/dom.js:67
67: detachEvent?: (type: string, listener: EventListener) => void;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function type. See: /private/tmp/flow/flowlib_224c089c/dom.js:67
src/element.js:0
0:
^ inconsistent use of library definitions
68: attachEvent?: (type: string, listener: EventListener) => void;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ undefined. This type is incompatible with. See: /private/tmp/flow/flowlib_224c089c/dom.js:68
68: attachEvent?: (type: string, listener: EventListener) => void;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function type. See: /private/tmp/flow/flowlib_224c089c/dom.js:68
src/element.js:0
0:
^ inconsistent use of library definitions
387: innerText?: string;
^^^^^^ undefined. This type is incompatible with. See: /private/tmp/flow/flowlib_224c089c/dom.js:387
387: innerText?: string;
^^^^^^ string. See: /private/tmp/flow/flowlib_224c089c/dom.js:387
src/element.js:0
0:
^ inconsistent use of library definitions
390: outerText?: string;
^^^^^^ undefined. This type is incompatible with. See: /private/tmp/flow/flowlib_224c089c/dom.js:390
390: outerText?: string;
^^^^^^ string. See: /private/tmp/flow/flowlib_224c089c/dom.js:390
src/element.js:0
0:
^ inconsistent use of library definitions
409: insertAdjacentElement?: (position: ('beforebegin' | 'afterbegin' | 'beforeend' | 'afterend'), node: Node) => void;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ undefined. This type is incompatible with. See: /private/tmp/flow/flowlib_224c089c/dom.js:409
409: insertAdjacentElement?: (position: ('beforebegin' | 'afterbegin' | 'beforeend' | 'afterend'), node: Node) => void;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function type. See: /private/tmp/flow/flowlib_224c089c/dom.js:409
Found 5 errors
------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment