@naporin0624/simple-store
TypeScript icon, indicating that this package has built-in type declarations

0.1.4 • Public • Published

simple-store

Simple state management using Set objects.

Image from Gyazo

Usage

import { createStore } from "@naporin0624/simple-store";

const store = createStore<string, number>();
const counter = document.createElement("p");
counter.innerText = `count: ${0}`;

store.subscribe(() => {
  const count = store.get("count") ?? 0;
  counter.innerText = `count: ${count}`;
});

const increment = document.createElement("button");
increment.onclick = () => {
  const count = store.get("count") ?? 0;
  store.set("count", count + 1);
};
increment.innerText = "increment";

const decrement = document.createElement("button");
decrement.onclick = () => {
  const count = store.get("count") ?? 0;
  store.set("count", count - 1);
};
decrement.innerText = "decrement";

const app = document.getElementById("app");
if (!app) throw new Error();

app.innerHTML = `
  <h1>Hello Simple Store</h1>
`;
app.appendChild(counter);
app.appendChild(increment);
app.appendChild(decrement);

Readme

Keywords

Package Sidebar

Install

npm i @naporin0624/simple-store

Weekly Downloads

14

Version

0.1.4

License

MIT

Unpacked Size

4.51 kB

Total Files

5

Last publish

Collaborators

  • naporin0624