Skip to content

Instantly share code, notes, and snippets.

@AprilArcus
Created January 7, 2016 01:39
Show Gist options
  • Save AprilArcus/bc0b7090f52ccc075c75 to your computer and use it in GitHub Desktop.
Save AprilArcus/bc0b7090f52ccc075c75 to your computer and use it in GitHub Desktop.
element.js
/* @flow */
declare class HTMLParagraphElement extends HTMLElement {
align: string
}
declare class Document extends Node {
registerElement(type: string, options?: ElementRegistrationOptions): void;
}
// http://w3c.github.io/webcomponents/spec/custom/#types-of-callbacks
type ElementRegistrationOptions = {
prototype?: HTMLElement;
extends?: string;
}
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
);
}
}
}
}
)
}
);
ril at Zephyr in ~/justified on master [!?]
$ npm run flow
> justified@ flow /Users/ril/justified
> flow
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_28978572/dom.js:67
67: detachEvent?: (type: string, listener: EventListener) => void;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function type. See: /private/tmp/flow/flowlib_28978572/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_28978572/dom.js:68
68: attachEvent?: (type: string, listener: EventListener) => void;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function type. See: /private/tmp/flow/flowlib_28978572/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_28978572/dom.js:387
387: innerText?: string;
^^^^^^ string. See: /private/tmp/flow/flowlib_28978572/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_28978572/dom.js:390
390: outerText?: string;
^^^^^^ string. See: /private/tmp/flow/flowlib_28978572/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_28978572/dom.js:409
409: insertAdjacentElement?: (position: ('beforebegin' | 'afterbegin' | 'beforeend' | 'afterend'), node: Node) => void;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function type. See: /private/tmp/flow/flowlib_28978572/dom.js:409
Found 5 errors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment