0.2.0 ā€¢ Published 5 years ago

statefully v0.2.0

Weekly downloads
5
License
MIT
Repository
github
Last release
5 years ago

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

0.2.0

5 years ago

0.1.9

5 years ago

0.1.7

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.1

5 years ago