diff --git a/assets/js/controllers/count_controller.js b/assets/js/controllers/count_controller.js index 2123d88..2d93cbb 100644 --- a/assets/js/controllers/count_controller.js +++ b/assets/js/controllers/count_controller.js @@ -4,6 +4,7 @@ export default class extends Controller { static targets = ["result"]; static values = { + canBeNegative: Boolean, count: Number, }; @@ -22,9 +23,11 @@ export default class extends Controller { decrement() { console.log("count#decrement"); - if (this.countValue > 0) { - this.countValue = this.countValue - 1; + if (this.canBeNegativeValue === false && this.countValue === 0) { + return; } + + this.countValue = this.countValue - 1; } increment() { diff --git a/public/index.html b/public/index.html index 41e4c05..b11de50 100644 --- a/public/index.html +++ b/public/index.html @@ -4,7 +4,16 @@ Stimulus esbuild example -
+
+

Count:

+ +
+ + +
+
+ +

Count: