From b280d54f77af1ff6c9171e41009b43a5f0a35d71 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Fri, 29 Mar 2024 00:50:46 +0000 Subject: [PATCH 1/9] Add Nix Flake with nodejs and just --- .envrc | 1 + flake.lock | 27 +++++++++++++++++++++++++++ flake.nix | 19 +++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 .envrc create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..a5dbbcb --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake . diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..eecb9ae --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1711523803, + "narHash": "sha256-UKcYiHWHQynzj6CN/vTcix4yd1eCu1uFdsuarupdCQQ=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "2726f127c15a4cc9810843b96cad73c7eb39e443", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..b4edc66 --- /dev/null +++ b/flake.nix @@ -0,0 +1,19 @@ +{ + description = "An example application that uses Stimulus with esbuild."; + + inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + + outputs = { nixpkgs, ... }: + let + system = "x86_64-linux"; + pkgs = nixpkgs.legacyPackages.${system}; + + inherit (pkgs) mkShell; + in { + devShells.${system}.default = mkShell { + buildInputs = with pkgs; [ just nodejs simple-http-server ]; + }; + + formatter.${system} = pkgs.nixfmt; + }; +} From d379fdb73dfd9e0aaac4acff9641c25e09cb1e55 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Fri, 29 Mar 2024 00:50:46 +0000 Subject: [PATCH 2/9] Add index.html with Stimulus hello controller --- .gitignore | 2 + .tmuxinator.yaml | 11 + assets/esbuild.config.mjs | 32 ++ assets/js/app.js | 5 + assets/js/controllers/hello_controller.js | 7 + justfile | 8 + package-lock.json | 437 ++++++++++++++++++++++ package.json | 9 + public/index.html | 13 + 9 files changed, 524 insertions(+) create mode 100644 .gitignore create mode 100644 .tmuxinator.yaml create mode 100644 assets/esbuild.config.mjs create mode 100644 assets/js/app.js create mode 100644 assets/js/controllers/hello_controller.js create mode 100644 justfile create mode 100644 package-lock.json create mode 100644 package.json create mode 100644 public/index.html diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ad09d97 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/node_modules/ +/public/build/ diff --git a/.tmuxinator.yaml b/.tmuxinator.yaml new file mode 100644 index 0000000..7bbc415 --- /dev/null +++ b/.tmuxinator.yaml @@ -0,0 +1,11 @@ +name: stimulus-esbuild-example +root: . + +windows: + - vim: nvim + - server: + layout: tiled + panes: + - just serve + - just build + - shell: diff --git a/assets/esbuild.config.mjs b/assets/esbuild.config.mjs new file mode 100644 index 0000000..7977d97 --- /dev/null +++ b/assets/esbuild.config.mjs @@ -0,0 +1,32 @@ +import * as esbuild from 'esbuild'; +import { stimulusPlugin } from 'esbuild-plugin-stimulus'; + +let minify = false; +let sourcemap = true; +let watch = true; + +if (process.env.NODE_ENV === 'production') { + minify = true; + sourcemap = false; + watch = false; +} + +const config = { + bundle: true, + entryPoints: ['./assets/js/app.js'], + minify, + outdir: './public/build', + plugins: [stimulusPlugin()], + sourcemap, +} + +if (watch) { + let context = await esbuild.context({ + ...config, + logLevel: 'info', + }); + + await context.watch() +} else { + esbuild.build(config) +} diff --git a/assets/js/app.js b/assets/js/app.js new file mode 100644 index 0000000..ce2fbaf --- /dev/null +++ b/assets/js/app.js @@ -0,0 +1,5 @@ +import { Application } from "@hotwired/stimulus"; +import { definitions } from "stimulus:./controllers"; + +const app = Application.start(); +app.load(definitions); diff --git a/assets/js/controllers/hello_controller.js b/assets/js/controllers/hello_controller.js new file mode 100644 index 0000000..ac4ebe2 --- /dev/null +++ b/assets/js/controllers/hello_controller.js @@ -0,0 +1,7 @@ +import { Controller } from "@hotwired/stimulus"; + +export default class extends Controller { + connect() { + console.log("hello#connect"); + } +} diff --git a/justfile b/justfile new file mode 100644 index 0000000..b15719c --- /dev/null +++ b/justfile @@ -0,0 +1,8 @@ +_default: + just --list + +build: + node assets/esbuild.config.mjs + +serve: + simple-http-server public --index diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..c9f39eb --- /dev/null +++ b/package-lock.json @@ -0,0 +1,437 @@ +{ + "name": "stimulus-esbuild-example", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "dependencies": { + "@hotwired/stimulus": "^3.2.2" + }, + "devDependencies": { + "esbuild": "^0.20.2", + "esbuild-plugin-stimulus": "^0.1.5" + } + }, + "node_modules/@esbuild/aix-ppc64": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.20.2.tgz", + "integrity": "sha512-D+EBOJHXdNZcLJRBkhENNG8Wji2kgc9AZ9KiPr1JuZjsNtyHzrsfLRrY0tk2H2aoFu6RANO1y1iPPUCDYWkb5g==", + "cpu": [ + "ppc64" + ], + "dev": true, + "optional": true, + "os": [ + "aix" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/android-arm": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.20.2.tgz", + "integrity": "sha512-t98Ra6pw2VaDhqNWO2Oph2LXbz/EJcnLmKLGBJwEwXX/JAN83Fym1rU8l0JUWK6HkIbWONCSSatf4sf2NBRx/w==", + "cpu": [ + "arm" + ], + "dev": true, + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/android-arm64": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.20.2.tgz", + "integrity": "sha512-mRzjLacRtl/tWU0SvD8lUEwb61yP9cqQo6noDZP/O8VkwafSYwZ4yWy24kan8jE/IMERpYncRt2dw438LP3Xmg==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/android-x64": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.20.2.tgz", + "integrity": "sha512-btzExgV+/lMGDDa194CcUQm53ncxzeBrWJcncOBxuC6ndBkKxnHdFJn86mCIgTELsooUmwUm9FkhSp5HYu00Rg==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/darwin-arm64": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.20.2.tgz", + "integrity": "sha512-4J6IRT+10J3aJH3l1yzEg9y3wkTDgDk7TSDFX+wKFiWjqWp/iCfLIYzGyasx9l0SAFPT1HwSCR+0w/h1ES/MjA==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/darwin-x64": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.20.2.tgz", + "integrity": "sha512-tBcXp9KNphnNH0dfhv8KYkZhjc+H3XBkF5DKtswJblV7KlT9EI2+jeA8DgBjp908WEuYll6pF+UStUCfEpdysA==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/freebsd-arm64": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.20.2.tgz", + "integrity": "sha512-d3qI41G4SuLiCGCFGUrKsSeTXyWG6yem1KcGZVS+3FYlYhtNoNgYrWcvkOoaqMhwXSMrZRl69ArHsGJ9mYdbbw==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/freebsd-x64": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.20.2.tgz", + "integrity": "sha512-d+DipyvHRuqEeM5zDivKV1KuXn9WeRX6vqSqIDgwIfPQtwMP4jaDsQsDncjTDDsExT4lR/91OLjRo8bmC1e+Cw==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-arm": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.20.2.tgz", + "integrity": "sha512-VhLPeR8HTMPccbuWWcEUD1Az68TqaTYyj6nfE4QByZIQEQVWBB8vup8PpR7y1QHL3CpcF6xd5WVBU/+SBEvGTg==", + "cpu": [ + "arm" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-arm64": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.20.2.tgz", + "integrity": "sha512-9pb6rBjGvTFNira2FLIWqDk/uaf42sSyLE8j1rnUpuzsODBq7FvpwHYZxQ/It/8b+QOS1RYfqgGFNLRI+qlq2A==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-ia32": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.20.2.tgz", + "integrity": "sha512-o10utieEkNPFDZFQm9CoP7Tvb33UutoJqg3qKf1PWVeeJhJw0Q347PxMvBgVVFgouYLGIhFYG0UGdBumROyiig==", + "cpu": [ + "ia32" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-loong64": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.20.2.tgz", + "integrity": "sha512-PR7sp6R/UC4CFVomVINKJ80pMFlfDfMQMYynX7t1tNTeivQ6XdX5r2XovMmha/VjR1YN/HgHWsVcTRIMkymrgQ==", + "cpu": [ + "loong64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-mips64el": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.20.2.tgz", + "integrity": "sha512-4BlTqeutE/KnOiTG5Y6Sb/Hw6hsBOZapOVF6njAESHInhlQAghVVZL1ZpIctBOoTFbQyGW+LsVYZ8lSSB3wkjA==", + "cpu": [ + "mips64el" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-ppc64": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.20.2.tgz", + "integrity": "sha512-rD3KsaDprDcfajSKdn25ooz5J5/fWBylaaXkuotBDGnMnDP1Uv5DLAN/45qfnf3JDYyJv/ytGHQaziHUdyzaAg==", + "cpu": [ + "ppc64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-riscv64": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.20.2.tgz", + "integrity": "sha512-snwmBKacKmwTMmhLlz/3aH1Q9T8v45bKYGE3j26TsaOVtjIag4wLfWSiZykXzXuE1kbCE+zJRmwp+ZbIHinnVg==", + "cpu": [ + "riscv64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-s390x": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.20.2.tgz", + "integrity": "sha512-wcWISOobRWNm3cezm5HOZcYz1sKoHLd8VL1dl309DiixxVFoFe/o8HnwuIwn6sXre88Nwj+VwZUvJf4AFxkyrQ==", + "cpu": [ + "s390x" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-x64": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.20.2.tgz", + "integrity": "sha512-1MdwI6OOTsfQfek8sLwgyjOXAu+wKhLEoaOLTjbijk6E2WONYpH9ZU2mNtR+lZ2B4uwr+usqGuVfFT9tMtGvGw==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/netbsd-x64": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.20.2.tgz", + "integrity": "sha512-K8/DhBxcVQkzYc43yJXDSyjlFeHQJBiowJ0uVL6Tor3jGQfSGHNNJcWxNbOI8v5k82prYqzPuwkzHt3J1T1iZQ==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/openbsd-x64": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.20.2.tgz", + "integrity": "sha512-eMpKlV0SThJmmJgiVyN9jTPJ2VBPquf6Kt/nAoo6DgHAoN57K15ZghiHaMvqjCye/uU4X5u3YSMgVBI1h3vKrQ==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/sunos-x64": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.20.2.tgz", + "integrity": "sha512-2UyFtRC6cXLyejf/YEld4Hajo7UHILetzE1vsRcGL3earZEW77JxrFjH4Ez2qaTiEfMgAXxfAZCm1fvM/G/o8w==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "sunos" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/win32-arm64": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.20.2.tgz", + "integrity": "sha512-GRibxoawM9ZCnDxnP3usoUDO9vUkpAxIIZ6GQI+IlVmr5kP3zUq+l17xELTHMWTWzjxa2guPNyrpq1GWmPvcGQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/win32-ia32": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.20.2.tgz", + "integrity": "sha512-HfLOfn9YWmkSKRQqovpnITazdtquEW8/SoHW7pWpuEeguaZI4QnCRW6b+oZTztdBnZOS2hqJ6im/D5cPzBTTlQ==", + "cpu": [ + "ia32" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/win32-x64": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.20.2.tgz", + "integrity": "sha512-N49X4lJX27+l9jbLKSqZ6bKNjzQvHaT8IIFUy+YIqmXQdjYCToGWwOItDrfby14c78aDd5NHQl29xingXfCdLQ==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@hotwired/stimulus": { + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/@hotwired/stimulus/-/stimulus-3.2.2.tgz", + "integrity": "sha512-eGeIqNOQpXoPAIP7tC1+1Yc1yl1xnwYqg+3mzqxyrbE5pg5YFBZcA6YoTiByJB6DKAEsiWtl6tjTJS4IYtbB7A==" + }, + "node_modules/esbuild": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.20.2.tgz", + "integrity": "sha512-WdOOppmUNU+IbZ0PaDiTst80zjnrOkyJNHoKupIcVyU8Lvla3Ugx94VzkQ32Ijqd7UhHJy75gNWDMUekcrSJ6g==", + "dev": true, + "hasInstallScript": true, + "bin": { + "esbuild": "bin/esbuild" + }, + "engines": { + "node": ">=12" + }, + "optionalDependencies": { + "@esbuild/aix-ppc64": "0.20.2", + "@esbuild/android-arm": "0.20.2", + "@esbuild/android-arm64": "0.20.2", + "@esbuild/android-x64": "0.20.2", + "@esbuild/darwin-arm64": "0.20.2", + "@esbuild/darwin-x64": "0.20.2", + "@esbuild/freebsd-arm64": "0.20.2", + "@esbuild/freebsd-x64": "0.20.2", + "@esbuild/linux-arm": "0.20.2", + "@esbuild/linux-arm64": "0.20.2", + "@esbuild/linux-ia32": "0.20.2", + "@esbuild/linux-loong64": "0.20.2", + "@esbuild/linux-mips64el": "0.20.2", + "@esbuild/linux-ppc64": "0.20.2", + "@esbuild/linux-riscv64": "0.20.2", + "@esbuild/linux-s390x": "0.20.2", + "@esbuild/linux-x64": "0.20.2", + "@esbuild/netbsd-x64": "0.20.2", + "@esbuild/openbsd-x64": "0.20.2", + "@esbuild/sunos-x64": "0.20.2", + "@esbuild/win32-arm64": "0.20.2", + "@esbuild/win32-ia32": "0.20.2", + "@esbuild/win32-x64": "0.20.2" + } + }, + "node_modules/esbuild-plugin-stimulus": { + "version": "0.1.5", + "resolved": "https://registry.npmjs.org/esbuild-plugin-stimulus/-/esbuild-plugin-stimulus-0.1.5.tgz", + "integrity": "sha512-ANav+mJxDJCIMuKfj4h7F2BemA1BcIaE5VmmGd6qDVQEaFEH3YeVRAHOWjgiUhGJBFi6wI8Q7RtZIZkNvbckZg==", + "dev": true, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/zombiezen" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..a9d0cfb --- /dev/null +++ b/package.json @@ -0,0 +1,9 @@ +{ + "devDependencies": { + "esbuild": "^0.20.2", + "esbuild-plugin-stimulus": "^0.1.5" + }, + "dependencies": { + "@hotwired/stimulus": "^3.2.2" + } +} diff --git a/public/index.html b/public/index.html new file mode 100644 index 0000000..d60157a --- /dev/null +++ b/public/index.html @@ -0,0 +1,13 @@ + + + + Stimulus esbuild example + + +
+

Hello, World!

+
+ + + + From 7146a7f66d2095e934217fc34aaeaa4a840063ad Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Fri, 29 Mar 2024 00:50:46 +0000 Subject: [PATCH 3/9] Add count controller --- assets/js/controllers/count_controller.js | 35 +++++++++++++++++++++++ public/index.html | 9 ++++-- 2 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 assets/js/controllers/count_controller.js diff --git a/assets/js/controllers/count_controller.js b/assets/js/controllers/count_controller.js new file mode 100644 index 0000000..2123d88 --- /dev/null +++ b/assets/js/controllers/count_controller.js @@ -0,0 +1,35 @@ +import { Controller } from "@hotwired/stimulus"; + +export default class extends Controller { + static targets = ["result"]; + + static values = { + count: Number, + }; + + connect() { + console.log("count#connect"); + + this.resultTarget.textContent = this.countValue; + } + + countValueChanged() { + console.log("count#countValueChanged"); + + this.resultTarget.textContent = this.countValue; + } + + decrement() { + console.log("count#decrement"); + + if (this.countValue > 0) { + this.countValue = this.countValue - 1; + } + } + + increment() { + console.log("count#increment"); + + this.countValue = this.countValue + 1; + } +} diff --git a/public/index.html b/public/index.html index d60157a..41e4c05 100644 --- a/public/index.html +++ b/public/index.html @@ -4,8 +4,13 @@ Stimulus esbuild example -
-

Hello, World!

+
+

Count:

+ +
+ + +
From ed81ff1bfc85bd023df006b46b3fb1dc53ae8564 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Fri, 29 Mar 2024 00:50:46 +0000 Subject: [PATCH 4/9] Add a counter than cannot be negative --- assets/js/controllers/count_controller.js | 7 +++++-- public/index.html | 11 ++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) 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:

From e8f4ff5c9d11e13baf8d2b707c5d3a8817f8d835 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Fri, 29 Mar 2024 00:50:46 +0000 Subject: [PATCH 5/9] Set a maximum count number for each counter --- assets/js/controllers/count_controller.js | 7 +++++++ public/index.html | 11 +++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/assets/js/controllers/count_controller.js b/assets/js/controllers/count_controller.js index 2d93cbb..97f29d6 100644 --- a/assets/js/controllers/count_controller.js +++ b/assets/js/controllers/count_controller.js @@ -6,6 +6,7 @@ export default class extends Controller { static values = { canBeNegative: Boolean, count: Number, + maximumCountNumber: Number, }; connect() { @@ -33,6 +34,12 @@ export default class extends Controller { increment() { console.log("count#increment"); + const maximumCountNumber = this.maximumCountNumberValue || 10; + + if (this.countValue === maximumCountNumber) { + return; + } + this.countValue = this.countValue + 1; } } diff --git a/public/index.html b/public/index.html index b11de50..edf95f8 100644 --- a/public/index.html +++ b/public/index.html @@ -4,7 +4,11 @@ Stimulus esbuild example -
+

Count:

@@ -13,7 +17,10 @@
-
+

Count:

From 818d686e90bb0298496b37829a534f654f33c2bc Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Fri, 29 Mar 2024 00:50:46 +0000 Subject: [PATCH 6/9] Add README --- README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..0531e1a --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# stimulus-esbuild-example + +An example of using [Stimulus](https://stimulus.hotwired.dev) with [esbuild](https://esbuild.github.io), and [esbuild-plugin-stimulus](https://github.com/zombiezen/esbuild-plugin-stimulus) to automatically register Stimulus controllers. From 423dcea8db61abd9d7bc6af18ebc7172bbfacef6 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Tue, 2 Apr 2024 10:22:38 +0100 Subject: [PATCH 7/9] Run `npm install` --- justfile | 1 + 1 file changed, 1 insertion(+) diff --git a/justfile b/justfile index b15719c..97d8d28 100644 --- a/justfile +++ b/justfile @@ -2,6 +2,7 @@ _default: just --list build: + npm install node assets/esbuild.config.mjs serve: From 4c850b3b40c1d3cb6362347a4b61cdeeadbc02ba Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Tue, 2 Apr 2024 10:22:45 +0100 Subject: [PATCH 8/9] Add `clean` recipe --- justfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/justfile b/justfile index 97d8d28..3fdc20f 100644 --- a/justfile +++ b/justfile @@ -5,5 +5,8 @@ build: npm install node assets/esbuild.config.mjs +clean: + rm -fr node_modules public/build + serve: simple-http-server public --index From 7588eb0c98bf360eb30062ac1b0bb36c9d24a973 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Mon, 29 Sep 2025 22:53:27 +0100 Subject: [PATCH 9/9] Move all files to stimulus-esbuild/ --- .envrc => stimulus-esbuild/.envrc | 0 .gitignore => stimulus-esbuild/.gitignore | 0 .tmuxinator.yaml => stimulus-esbuild/.tmuxinator.yaml | 0 README.md => stimulus-esbuild/README.md | 0 {assets => stimulus-esbuild/assets}/esbuild.config.mjs | 0 {assets => stimulus-esbuild/assets}/js/app.js | 0 .../assets}/js/controllers/count_controller.js | 0 .../assets}/js/controllers/hello_controller.js | 0 flake.lock => stimulus-esbuild/flake.lock | 0 flake.nix => stimulus-esbuild/flake.nix | 0 justfile => stimulus-esbuild/justfile | 0 package-lock.json => stimulus-esbuild/package-lock.json | 0 package.json => stimulus-esbuild/package.json | 0 {public => stimulus-esbuild/public}/index.html | 0 14 files changed, 0 insertions(+), 0 deletions(-) rename .envrc => stimulus-esbuild/.envrc (100%) rename .gitignore => stimulus-esbuild/.gitignore (100%) rename .tmuxinator.yaml => stimulus-esbuild/.tmuxinator.yaml (100%) rename README.md => stimulus-esbuild/README.md (100%) rename {assets => stimulus-esbuild/assets}/esbuild.config.mjs (100%) rename {assets => stimulus-esbuild/assets}/js/app.js (100%) rename {assets => stimulus-esbuild/assets}/js/controllers/count_controller.js (100%) rename {assets => stimulus-esbuild/assets}/js/controllers/hello_controller.js (100%) rename flake.lock => stimulus-esbuild/flake.lock (100%) rename flake.nix => stimulus-esbuild/flake.nix (100%) rename justfile => stimulus-esbuild/justfile (100%) rename package-lock.json => stimulus-esbuild/package-lock.json (100%) rename package.json => stimulus-esbuild/package.json (100%) rename {public => stimulus-esbuild/public}/index.html (100%) diff --git a/.envrc b/stimulus-esbuild/.envrc similarity index 100% rename from .envrc rename to stimulus-esbuild/.envrc diff --git a/.gitignore b/stimulus-esbuild/.gitignore similarity index 100% rename from .gitignore rename to stimulus-esbuild/.gitignore diff --git a/.tmuxinator.yaml b/stimulus-esbuild/.tmuxinator.yaml similarity index 100% rename from .tmuxinator.yaml rename to stimulus-esbuild/.tmuxinator.yaml diff --git a/README.md b/stimulus-esbuild/README.md similarity index 100% rename from README.md rename to stimulus-esbuild/README.md diff --git a/assets/esbuild.config.mjs b/stimulus-esbuild/assets/esbuild.config.mjs similarity index 100% rename from assets/esbuild.config.mjs rename to stimulus-esbuild/assets/esbuild.config.mjs diff --git a/assets/js/app.js b/stimulus-esbuild/assets/js/app.js similarity index 100% rename from assets/js/app.js rename to stimulus-esbuild/assets/js/app.js diff --git a/assets/js/controllers/count_controller.js b/stimulus-esbuild/assets/js/controllers/count_controller.js similarity index 100% rename from assets/js/controllers/count_controller.js rename to stimulus-esbuild/assets/js/controllers/count_controller.js diff --git a/assets/js/controllers/hello_controller.js b/stimulus-esbuild/assets/js/controllers/hello_controller.js similarity index 100% rename from assets/js/controllers/hello_controller.js rename to stimulus-esbuild/assets/js/controllers/hello_controller.js diff --git a/flake.lock b/stimulus-esbuild/flake.lock similarity index 100% rename from flake.lock rename to stimulus-esbuild/flake.lock diff --git a/flake.nix b/stimulus-esbuild/flake.nix similarity index 100% rename from flake.nix rename to stimulus-esbuild/flake.nix diff --git a/justfile b/stimulus-esbuild/justfile similarity index 100% rename from justfile rename to stimulus-esbuild/justfile diff --git a/package-lock.json b/stimulus-esbuild/package-lock.json similarity index 100% rename from package-lock.json rename to stimulus-esbuild/package-lock.json diff --git a/package.json b/stimulus-esbuild/package.json similarity index 100% rename from package.json rename to stimulus-esbuild/package.json diff --git a/public/index.html b/stimulus-esbuild/public/index.html similarity index 100% rename from public/index.html rename to stimulus-esbuild/public/index.html