Skip to content
This repository has been archived by the owner on Oct 26, 2024. It is now read-only.

Commit

Permalink
Adding support for Stimulus 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumebriday committed Dec 5, 2020
1 parent 1268885 commit a0779be
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 34 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [2.0.0] - 2020-12-05

### Added

- Support for Stimulus 2.0

### Changed

**Breaking** Using the new `values` static property.

```diff
- <time data-controller="timeago" data-timeago-datetime="2018-01-30T09:00" data-timeago-refresh-interval="1000" data-timeago-include-seconds="" data-timeago-add-suffix=""></time>
+ <time data-controller="timeago" data-timeago-datetime-value="2018-01-30T09:00" data-timeago-refresh-interval-value="1000" data-timeago-include-seconds-value="" data-timeago-add-suffix-value=""></time>
```

## [1.2.0] - 2020-11-11

### Added
Expand Down
8 changes: 4 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ <h1 class="text-4xl tracking-tight font-extrabold text-gray-900 sm:text-5xl md:t
Stimulus 1.0.0 was released
<time
data-controller="timeago"
data-timeago-datetime="2018-01-30T09:00"
data-timeago-refresh-interval="1000"
data-timeago-include-seconds=""
data-timeago-add-suffix=""
data-timeago-datetime-value="2018-01-30T09:00"
data-timeago-refresh-interval-value="1000"
data-timeago-include-seconds-value=""
data-timeago-add-suffix-value=""
></time
>.
</section>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
},
"dependencies": {
"date-fns": "^2.16.1",
"stimulus": "^1.1.1"
"stimulus": "^2.0.0"
},
"devDependencies": {
"@babel/core": "7.11.6",
Expand Down
17 changes: 12 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@ import { Controller } from 'stimulus'
import formatDistanceToNow from 'date-fns/formatDistanceToNow'

export default class extends Controller {
static values = {
datetime: String,
refreshInterval: Number,
includeSeconds: Boolean,
addSuffix: Boolean
}

initialize () {
this.isValid = true
}

connect () {
this.load()

if (this.data.has('refreshInterval') && this.isValid) {
if (this.hasRefreshIntervalValue && this.isValid) {
this.startRefreshing()
}
}
Expand All @@ -19,11 +26,11 @@ export default class extends Controller {
}

load () {
const datetime = this.data.get('datetime')
const datetime = this.datetimeValue
const date = Date.parse(datetime)
const options = {
includeSeconds: this.data.has('includeSeconds') || false,
addSuffix: this.data.has('addSuffix') || false,
includeSeconds: this.hasIncludeSecondsValue,
addSuffix: this.hasAddSuffixValue,
locale: this.locale
}

Expand All @@ -42,7 +49,7 @@ export default class extends Controller {
startRefreshing () {
this.refreshTimer = setInterval(() => {
this.load()
}, this.data.get('refreshInterval'))
}, this.refreshIntervalValue)
}

stopRefreshing () {
Expand Down
48 changes: 24 additions & 24 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1115,29 +1115,29 @@
execa "^4.0.3"
npm-run-path "^4.0.1"

"@stimulus/core@^1.1.1":
version "1.1.1"
resolved "https://registry.yarnpkg.com/@stimulus/core/-/core-1.1.1.tgz#42b0cfe5b73ca492f41de64b77a03980bae92c82"
integrity sha512-PVJv7IpuQx0MVPCBblXc6O2zbCmU8dlxXNH4bC9KK6LsvGaE+PCXXrXQfXUwAsse1/CmRu/iQG7Ov58himjiGg==
"@stimulus/core@^2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@stimulus/core/-/core-2.0.0.tgz#140c85318d6a8a8210c0faf182223b8459348877"
integrity sha512-ff70GafKtzc8zQ1/cG+UvL06GcifPWovf2wBEdjLMh9xO2GOYURO3y2RYgzIGYUIBefQwyfX2CLfJdZFJrEPTw==
dependencies:
"@stimulus/mutation-observers" "^1.1.1"
"@stimulus/mutation-observers" "^2.0.0"

"@stimulus/multimap@^1.1.1":
version "1.1.1"
resolved "https://registry.yarnpkg.com/@stimulus/multimap/-/multimap-1.1.1.tgz#b95e3fd607345ab36e5d5b55486ee1a12d56b331"
integrity sha512-26R1fI3a8uUj0WlMmta4qcfIQGlagegdP4PTz6lz852q/dXlG6r+uPS/bx+H8GtfyS+OOXVr3SkZ0Zg0iRqRfQ==
"@stimulus/multimap@^2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@stimulus/multimap/-/multimap-2.0.0.tgz#420cfa096ed6538df4a91dbd2b2842c1779952b2"
integrity sha512-pMBCewkZCFVB3e5mEMoyO9+9aKzHDITmf3OnPun51YWxlcPdHcwbjqm1ylK63fsoduIE+RowBpFwFqd3poEz4w==

"@stimulus/mutation-observers@^1.1.1":
version "1.1.1"
resolved "https://registry.yarnpkg.com/@stimulus/mutation-observers/-/mutation-observers-1.1.1.tgz#0f6c6f081308427fed2a26360dda0c173b79cfc0"
integrity sha512-/zCnnw1KJlWO2mrx0yxYaRFZWMGnDMdOgSnI4hxDLxdWVuL2HMROU8FpHWVBLjKY3T9A+lGkcrmPGDHF3pfS9w==
"@stimulus/mutation-observers@^2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@stimulus/mutation-observers/-/mutation-observers-2.0.0.tgz#3dbe37453bda47a6c795a90204ee8d77a799fb87"
integrity sha512-kx4VAJdPhIGBQKGIoUDC2tupEKorG3A+ckc2b1UiwInKTMAC1axOHU8ebcwhaJIxRqIrs8//4SJo9YAAOx6FEg==
dependencies:
"@stimulus/multimap" "^1.1.1"
"@stimulus/multimap" "^2.0.0"

"@stimulus/webpack-helpers@^1.1.1":
version "1.1.1"
resolved "https://registry.yarnpkg.com/@stimulus/webpack-helpers/-/webpack-helpers-1.1.1.tgz#eff60cd4e58b921d1a2764dc5215f5141510f2c2"
integrity sha512-XOkqSw53N9072FLHvpLM25PIwy+ndkSSbnTtjKuyzsv8K5yfkFB2rv68jU1pzqYa9FZLcvZWP4yazC0V38dx9A==
"@stimulus/webpack-helpers@^2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@stimulus/webpack-helpers/-/webpack-helpers-2.0.0.tgz#54296d2a2dffd4f962d2e802d99a3fdd84b8845f"
integrity sha512-D6tJWsAC024MwGEIKlUVYU8Ln87mlrmiwHvYAjipg+s8H4eLxUMQ3PZkWyPevfipH+oR3leuHsjYsK1gN5ViQA==

"@szmarczak/http-timer@^1.1.2":
version "1.1.2"
Expand Down Expand Up @@ -5051,13 +5051,13 @@ state-toggle@^1.0.0:
resolved "https://registry.yarnpkg.com/state-toggle/-/state-toggle-1.0.3.tgz#e123b16a88e143139b09c6852221bc9815917dfe"
integrity sha512-d/5Z4/2iiCnHw6Xzghyhb+GcmF89bxwgXG60wjIiZaxnymbyOmI8Hk4VqHXiVVp6u2ysaskFfXg3ekCj4WNftQ==

stimulus@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/stimulus/-/stimulus-1.1.1.tgz#53c2fded6849e7b85eed3ed8dd76e33abd74bec5"
integrity sha512-R0mBqKp48YnRDZOxZ8hiOH4Ilph3Yj78CIFTBkCwyHs4iGCpe7xlEdQ7cjIxb+7qVCSxFKgxO+mAQbsNgt/5XQ==
stimulus@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/stimulus/-/stimulus-2.0.0.tgz#713c8b91a72ef90914b90955f0e705f004403047"
integrity sha512-xipy7BS5TVpg4fX6S8LhrYZp7cmHGjmk09WSAiVx1gF5S5g43IWsuetfUhIk8HfHUG+4MQ9nY0FQz4dRFLs/8w==
dependencies:
"@stimulus/core" "^1.1.1"
"@stimulus/webpack-helpers" "^1.1.1"
"@stimulus/core" "^2.0.0"
"@stimulus/webpack-helpers" "^2.0.0"

string-argv@^0.3.0:
version "0.3.1"
Expand Down

0 comments on commit a0779be

Please sign in to comment.