Skip to content

omarluq/stimulus-store

Repository files navigation

Stimulus Store Logo

GitHub package.json version GitHub Actions Netlify Status Last Commit Commit Activity All Contributors Pull Requests Closed Pull Requests GitHub issues PRs Welcome GitHub stars GitHub forks GitHub watchers Type Definitions BiomeJS Maintainability Test Coverage npm version npm downloads Bundle Size Bundle Min Tree-shaking size Top Language GitHub code size in bytes Maintenance Dependabot Made with Love


Ultra lightweight state management for your Stimulus powered web applications.


  • Create and manage global state with ease. πŸ”„
  • Share state between different controllers effortlessly using a unified, atomic Store class. πŸ”€
  • 1.04KB Minified and Brotlied πŸͺΆ

Installation

With a build system

Install with npm:

npm install stimulus-store

Install with yarn:

yarn add stimulus-store

UMD

If you prefer not to use a build system, you can load stimulus-store in a <script> tag and it will be globally available through the window.StimulusStore object.

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <script src="https://unpkg.com/stimulus/dist/stimulus.umd.js"></script>
    <script src="https://unpkg.com/stimulus-store/dist/bundle.umd.js"></script>
    <script>
      (() => {
        const application = Stimulus.Application.start();

        const helloStore = StimulusStore.createStore({
          name: "helloStore",
          type: String,
          initialValue: "Hello World!",
        });

        application.register(
          "hello",
          class extends Stimulus.Controller {
            static stores = [helloStore];

            connect() {
              StimulusStore.useStore(this);
              this.element.innerHtml = `<p>${this.helloStoreValue}</p>`;
            }
          }
        );
      })();
    </script>
  </head>
  <body>
    <div data-controller="hello">…</div>
  </body>
</html>

Documentation

complete documentation on Stimulus Store, including guides, API details, and more can be found on www.stimulus-store.com.

Contributors ✨

Thanks goes to these wonderful people (emoji key):

Tomas Caraccia
Tomas Caraccia

πŸ’» ⚠️ πŸ“– 🚧 πŸ‘€ πŸ’¬
Omar Luq
Omar Luq

πŸ’» ⚠️ πŸ“– 🚧 πŸ‘€ πŸ’¬
Add your contributions

This project follows the all-contributors specification. Contributions of any kind welcome!


License

This project is licensed under the MIT License - see the LICENSE.md file for details.