statefully
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

Statefully

Travis (.org) size size dependencies

📦 A tiny state container for your javascript apps

  • 💡 Simple: Easy to learn & use APIs
  • 📦 Small: Zero dependencies + 1kb minified size only
  • 🔌 Pluggable: Use anywhere you want
  • 🔒 Type-Safe: Great type support with TypeScript & Flow

⚠ NOTE: This project is under active development!


🔧 Installation

NodeJS

# Using npm 
npm install statefully
 
# Using yarn 
yarn add statefully

HTML

<script src="https://unpkg.com/statefully@latest/dist/index.min.js"></script>

📦 Usage

Create container

// Using ES Module
import { createContainer } from "statefully";
// Using CommonJS
const { createContainer } = require("statefully");
 
// Create container with initial value
const store = createContainer({ greeting: "John" });

Get container state

store.getState(); // { greeting: "John" }

Actions

// Create action
const setGreeting = store.action((state, { name }) => ({ greeting: name }));
 
// Call action
setGreeting({ name: "Doe" });
 
store.getState(); // { greeting: "Doe" }

Subscribe container

store.subscribe(() => {
  console.log("Store changed: ", store.getState());
});

📝 Guide

With TypeScript

// Create container
type State = { greeting: string };
const store = createContainer<State>({ greeting: "John" });
 
// Create action
type SetGreetingProps = { name: string };
const setGreeting = store.action<SetGreetingProps>((state, { name }) => ({
  greeting: name,
}));
 
// Call action
setGreeting({ name: "Doe" });

🌟 Features

  • ✅ Actions
  • ❌ Merge actions
  • ✅ Subscription
  • ✅ TypeScript Support
  • ❌ Flow Support
  • ❌ React binding

🔑 License

MIT

Package Sidebar

Install

npm i statefully

Weekly Downloads

0

Version

0.2.0

License

MIT

Unpacked Size

10.1 kB

Total Files

6

Last publish

Collaborators

  • rahmandev