From 0736ceda4c9b84e33d683e30cef477134187577a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Oddsson?= Date: Tue, 14 May 2019 12:29:52 +0100 Subject: [PATCH 1/4] add missing flow annotations --- src/relative-time-element.js | 2 +- src/time-ago-element.js | 2 +- src/time-until-element.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/relative-time-element.js b/src/relative-time-element.js index e0c6d7f..b2d1c5d 100644 --- a/src/relative-time-element.js +++ b/src/relative-time-element.js @@ -4,7 +4,7 @@ import RelativeTime from './relative-time' import ExtendedTimeElement from './extended-time-element' export default class RelativeTimeElement extends ExtendedTimeElement { - getFormattedDate() { + getFormattedDate(): ?string { if (this._date) { return new RelativeTime(this._date).toString() } diff --git a/src/time-ago-element.js b/src/time-ago-element.js index 7a5c286..e82afa5 100644 --- a/src/time-ago-element.js +++ b/src/time-ago-element.js @@ -4,7 +4,7 @@ import RelativeTime from './relative-time' import RelativeTimeElement from './relative-time-element' export default class TimeAgoElement extends RelativeTimeElement { - getFormattedDate() { + getFormattedDate(): ?string { const format = this.getAttribute('format') if (!this._date) return if (format === 'micro') { diff --git a/src/time-until-element.js b/src/time-until-element.js index ed7942d..4be22c6 100644 --- a/src/time-until-element.js +++ b/src/time-until-element.js @@ -4,7 +4,7 @@ import RelativeTime from './relative-time' import RelativeTimeElement from './relative-time-element' export default class TimeUntilElement extends RelativeTimeElement { - getFormattedDate() { + getFormattedDate(): ?string { const format = this.getAttribute('format') if (!this._date) return if (format === 'micro') { From aa613ffe3f308178185eac7d79804eae6f10bc95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Oddsson?= Date: Tue, 14 May 2019 12:34:18 +0100 Subject: [PATCH 2/4] add flow definition file for the element API --- package.json | 2 +- src/index.js.flow | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/index.js.flow diff --git a/package.json b/package.json index 51e87f7..791a177 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "scripts": { "clean": "rm -rf ./dist ./node_modules", "lint": "github-lint", - "build": "rollup -c", + "build": "rollup -c && cp src/index.js.flow dist/time-elements.js.flow && cp src/index.js.flow dist/time-elements-legacy.js.flow", "prepublishOnly": "npm run pretest", "pretest": "npm run lint && npm run build", "test": "karma start ./test/karma.config.js" diff --git a/src/index.js.flow b/src/index.js.flow new file mode 100644 index 0000000..5be4535 --- /dev/null +++ b/src/index.js.flow @@ -0,0 +1,25 @@ +/* flow strict */ + +declare module 'time-elements' { + declare class ExtendedTimeElement extends HTMLElement { + _date: ?Date; + getFormattedTitle(): ?string; + getFormattedDate(): ?string; + } + + declare export class LocalTimeElement extends ExtendedTimeElement { + getFormattedDate(): ?string; + } + + declare export class RelativeTimeElement extends ExtendedTimeElement { + getFormattedDate(): ?string; + } + + declare export class TimeAgoElement extends RelativeTimeElement { + getFormattedDate(): ?string; + } + + declare export class TimeUntilElement extends RelativeTimeElement { + getFormattedDate(): ?string; + } +} From 4b9d345c46c3e8768aec381d2e125209ab8a49eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Oddsson?= Date: Tue, 14 May 2019 12:35:34 +0100 Subject: [PATCH 3/4] make sure to run clean before building --- package.json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 791a177..c6c8ad4 100644 --- a/package.json +++ b/package.json @@ -5,11 +5,13 @@ "module": "dist/time-elements.js", "license": "MIT", "scripts": { - "clean": "rm -rf ./dist ./node_modules", + "clean": "rm -rf dist", "lint": "github-lint", + "prebuild": "npm run clean && npm run lint && mkdir dist", "build": "rollup -c && cp src/index.js.flow dist/time-elements.js.flow && cp src/index.js.flow dist/time-elements-legacy.js.flow", "prepublishOnly": "npm run pretest", - "pretest": "npm run lint && npm run build", + "pretest": "npm run build", + "prepublishOnly": "npm run build", "test": "karma start ./test/karma.config.js" }, "repository": "github/time-elements", From be1f35488bf32973f0b5af12a0317c40b078a466 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Oddsson?= Date: Thu, 16 May 2019 09:31:34 +0100 Subject: [PATCH 4/4] remove faux private field from flow definition --- src/index.js.flow | 1 - 1 file changed, 1 deletion(-) diff --git a/src/index.js.flow b/src/index.js.flow index 5be4535..35d6cd9 100644 --- a/src/index.js.flow +++ b/src/index.js.flow @@ -2,7 +2,6 @@ declare module 'time-elements' { declare class ExtendedTimeElement extends HTMLElement { - _date: ?Date; getFormattedTitle(): ?string; getFormattedDate(): ?string; }