0.1.4 • Published 3 years ago

@naporin0624/simple-store v0.1.4

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

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);
0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.0

3 years ago

0.1.1

3 years ago

0.0.7

3 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago