Blazing fast and lightweight state management framework ๐Ÿ‘“

Overview

Banner


StateX is a blazing fast and lightweight framework for managing state in a Javascript app.

Features

  • ๐Ÿ’จ Fast โˆ’ Our APIs just run lightning fast, no more slowdowns.
  • ๐Ÿ”‹ Efficient - To reduce the consumption of energy, we have optimised it.
  • โ›‘ Type Safe - To prevent type errors and bugs, we have made the framework type-safe.
  • ๐Ÿ›ณ Portable - This framework works accorss web and Node environments. You can use this library together with React or any other Javascript UI libraries.
  • ๐Ÿ˜ต Tiny (>2kb) - Too much lightweight, no more large bundle sizes
  • ๐Ÿค“ Extensible - Extend the State class to create your own custom state object.
  • ๐Ÿซฅ Asynchronous - If you are fed-up with how messy it is to save state inside a asynchronous operation, say goodbye to it.

Installation

This will be available when the package is published.

Documentation

APIs

createState()

Creates a new state object and return an array with it's first value as the getter and second value as an setter and the third as the instance of the state. Instead of creating a new new instance of State, this function should be used. Expects a default value in the first parameter.

Usage:

const [isPrivate, setPrivacy] = createState(false);

const value = isPrivate();

setPrivacy(true);

With Initial Effect:

const [isPrivate, setPrivacy] = createState(false, initialValue => /* do something with the value */);

registerEffect()

Registers an effect for the state object specified in the argument. This function also supports specifying multiple state objects as arguments when you want to have a common state for multiple state objects.

This hook needs to be registered before making any changes in the state, if you wanna trigger all the changes every happened. The best practice is to make sure this function is registered right after creating the state.

registerEffect(newValue => {
	// callback when the state is set
}, state);

Example

import { createState, registerEffect } from 'statex';

/**
 * Creates a new state object and returns an array of three elements with
 * the first one as the getter and second one as the setter and the third
 * one is the instane of the state object, this might be needed in
 * scenarios when you need to use `registerEffect()` hook
 * Expects a default value in the first parameter. The secon
 * parameter is an optional initial effect callback. I
 * passes in the initial value passed in to the `createState
 * function. This was created in order to fix the
 * accessing the value before it was initialised error.
 *
 * The getter is a function, so you would you have to call it to get the
 * state.
 *
 * The setter is also a function which you need to provide a new value to
 * be passed in to the function. If the new value passed in is the same as
 * the old one is used and the new unchanged value is ignored.
 * This function is type-safe and if the new value's type is not the same
 * as the new one, it will throw an error.
 *
 * The instance is a object that has the value of the state object created
 * by registerEfffect() hook.
 */
const [username, setUsername, usernameInstance] = createState('anonymous');

/**
 * Registers an hook to trigger whenever a change is made. If you need to
 * detect changes from the creation of the state, you would need to register
 * it right after creating the state. This means that the changes would only
 * be detected after this hook is registered and not from the beginning.
 * So it would improve perfomance as it would help the developer optimise
 * triggering changes according to their apps.
 *
 * The first parameter is the callback when a new value is triggered. This
 * function also passes in the new value.
 *
 * The second parameter is instance of the state object. You can get the
 * instance from the createState() hook.
 */
registerEffect(newValue => {
	console.log(newValue);
}, usernameInstance);

// retrieving the value from the state.
username();

// setting the state, the callback inside the registerEffect() hook
// is triggered
setUsername('hello-world');

License

StateX is licensed under MIT and the copyright is owned by Haneen Mahdin.

Comments
  • [BUG]: Missing files in package

    [BUG]: Missing files in package

    Describe the bug The version v1.0.0-beta.0 seems to be missing some files inside the package after installed.

    To Reproduce Steps to reproduce the behavior:

    1. Install the package2.
    2. Try to use the package3.
    3. You might face some weird bugs.

    Expected behavior Stable package.

    Screenshots If applicable, add screenshots to help explain your problem.

    Desktop (please complete the following information):

    • Environment: Node
    • OS: macOS

    Additional context Add any other context about the problem here.

    bug help wanted 
    opened by haneenmahd 0
  • ๐Ÿ˜Ž: Dump react-like state management

    ๐Ÿ˜Ž: Dump react-like state management

    Simplify createState()

    Description

    This PR comes with a huge update ๐Ÿ™Œ! Instead of using the react-like array destructing state management, we are now just returning the instance, which is much more far better in terms of code readability and DX as the dev might need to destructure again to get the instance, which is a bad idea ๐Ÿ‘Ž

    Linked issues

    • None

    Does this PR introduce breaking changes?

    Yes.

    This PR changes the way we get and set the value of state and since now, it passes out a simple instance rather than providing the getter, setter and instance as a separate elements of an array.

    documentation enhancement 
    opened by haneenmahd 0
  • Extensibility

    Extensibility

    This PR adds support for extending the existing State class with your custom version. This brings up a lot of flexibility and customisability within your state. This feature was build to be re-usable and the custom instance can be used anywhere.

    enhancement 
    opened by haneenmahd 0
  • Type safety

    Type safety

    PR adds type safety to the state object. Ensure and validates if the type matches when setting the state. This functionality will be available in any context while using the State class or the APIs that depend on this.

    documentation enhancement 
    opened by haneenmahd 0
  • [BUG]: Doesn't support web environments

    [BUG]: Doesn't support web environments

    Describe the bug Doesn't support web environments which are crucial for web developers.

    To Reproduce Steps to reproduce the behavior:

    1. Use '@thq/dapper' package within any web environment or any frontend web libraries
    2. See error

    Expected behavior Work properly with both web and node environments.

    Screenshots Screenshot 2022-08-28 at 5 23 02 PM

    Desktop (please complete the following information):

    • Environment: Web
    • OS: macOS
    • Browser: Firefox
    • Version: 104

    Additional context We could fix this by checking for the environment and exporting necessarily or any other preferred workaround.

    bug help wanted 
    opened by haneenmahd 0
  • [BUG]: Package size is increased

    [BUG]: Package size is increased

    Describe the bug The package size has increased because we are probably exporting redux with too with it. Maybe we should move out test packages to another sub-project.

    To Reproduce Steps to reproduce the behavior:

    1. Install 'dapper' from any package manager
    2. See it installing other dependencies that are not really depended by dapper

    Expected behavior Fast, simple, dependency-less installation.

    Desktop (please complete the following information):

    • Environment: Node
    • OS: macOS
    • Version 12.5.1

    Additional context Add any other context about the problem here.

    bug help wanted 
    opened by haneenmahd 0
Releases(v1.0.0-beta.1)
  • v1.0.0-beta.1(Aug 19, 2022)

  • v1.0.0-beta.0(Aug 19, 2022)

    This version of Dapper was intended to be released as part of our development process to test out how this framework works together in other libraries, frameworks and environments.

    You are welcomed to test this software! Here's what you can do:

    • Identify potential bugs or issues
    • Contribute to the project's documentation
    • Request for a new feature
    • Open a PR for a new feature/bug fix.

    What's Changed

    • [๐Ÿฅธ๐Ÿค ๐Ÿฅณ]: Add new APIs by @haneenmahd in https://github.com/TruelinesHQ/statex/pull/1
    • ๐Ÿง Optimise codebase by @haneenmahd in https://github.com/TruelinesHQ/statex/pull/2
    • ๐Ÿฅธ : Optimise updating state by @haneenmahd in https://github.com/TruelinesHQ/statex/pull/3
    • ๐Ÿฅธ: Doesn't return a getter function (#4) by @haneenmahd in https://github.com/TruelinesHQ/statex/pull/5
    • Type safety by @haneenmahd in https://github.com/TruelinesHQ/statex/pull/6
    • Add support for initial effect by @haneenmahd in https://github.com/TruelinesHQ/statex/pull/7
    • Extensibility by @haneenmahd in https://github.com/TruelinesHQ/statex/pull/8
    • ๐Ÿ˜Ž: Dump react-like state management by @haneenmahd in https://github.com/TruelinesHQ/statex/pull/9

    New Contributors

    • @haneenmahd made their first contribution in https://github.com/TruelinesHQ/statex/pull/1

    Full Changelog: https://github.com/TruelinesHQ/statex/commits/v1.0.0-beta.0

    Source code(tar.gz)
    Source code(zip)
Owner
Truelines
Building Tools that help in improving Developer Experience!
Truelines
โšก A blazing fast, lightweight, and open source comment system for your static website, blogs powered by Supabase

SupaComments โšก A blazing fast, lightweight, and open source comment system for your static website, blogs ?? Demo You can visit the Below demo blog po

MC Naveen 112 Dec 27, 2022
Gatsby-blog-cosmicjs - ๐Ÿš€โšก๏ธ Blazing fast blog built with Gatsby and the Cosmic Headless CMS ๐Ÿ”ฅ

Gatsby + Cosmic This repo contains an example blog website that is built with Gatsby, and Cosmic. See live demo hosted on Netlify Uses the Cosmic Gats

Priya Chakraborty 0 Jan 29, 2022
An open-source, blazing fast code editor for Windows, Mac, and Linux.

Thermite An open-source, blazing fast code editor for Windows, Mac, and Linux. About Thermite is a Blazing Fast, Open-Source, Cross-Platform Code Edit

Keston 4 Oct 25, 2022
๐Ÿ”ฅ Blazing Fast API which scrapes Mydramalist.com made using Fastify and Cheerio.

mydramalist API ?? Blazing Fast API which scrapes Mydramalist.com made using Fastify and Cheerio. Setup pnpm install node index.js available at http:/

Paranjay Singh 6 Dec 4, 2022
โšก๏ธA minimalistic and sweet router for blazing fast bun

Melonpan is a simple and minimalistic web-router designed to work with Bun, keeping performance in mind. ?? Why Melonpan? no/minimal learning curve De

Hemanth Krishna 66 Jan 6, 2023
๐Ÿš€ Blazing Fast S3 Powered CDN โœจ Powered By Fastify, S3 Buckets & Docker!

?? WasiCDN Blazing Fast S3 Powered CDN, Powered By Fastify, S3 Compatible Buckets & Docker! Core DockerHub: https://hub.docker.com/r/maximking19/wasic

Maxim 5 Aug 31, 2022
Blazing fast ๐Ÿ”ฅ Discord Desktop Client.

Fastcord Faster Discord Desktop Client Made with Rust & React Motivation Discord is cool but electron is not. Discord Desktop consumes too much memory

fishuke 12 Nov 21, 2022
โšก Take a snapshot of all NFT/ERC721 collection holders. Blazing fast โšก

โšก Instant NFT / ERC721 Snapshot This small command line tool let's you create a blazing fast snapshot of all the owners of a NFT collection. For a 10k

Nico Elzer 38 Dec 4, 2022
๐Ÿป Trying out the bear necessities for complex state management.

?? Zustand Demos My practice repository for the Zustand library--the bear necessities for complex state management. You can find some examples of how

Carlo Taleon 2 Jul 2, 2022
The Frontend of Escobar's Inventory Management System, Employee Management System, Ordering System, and Income & Expense System

Usage Create an App # with npx $ npx create-nextron-app my-app --example with-javascript # with yarn $ yarn create nextron-app my-app --example with-

Viver Bungag 4 Jan 2, 2023
chain-syncer is a module which allows you to synchronize your app with any ethereum-compatible blockchain/contract state. Fast. Realtime. Reliable.

Chain Syncer Chain Syncer is a JS module which allows you to synchronize your app with any ethereum-compatible blockchain/contract state. Fast. Realti

Miroslaw Shpak 10 Dec 15, 2022
JavaScript framework for creating beautiful, fast and lightweight websites based on flutter way of coding โ˜œ(๏พŸใƒฎ๏พŸโ˜œ)

Welcome to Flutjs project ?? Flutjs is a javascript framework for creating beautiful, fast and lightweight websites. As the name suggests, Flutejs is

Filipe Lukebana 25 Nov 9, 2022
Lightweight, fast and framework-agnostic sse service for NodeJS

SSE service Lightweight, fast and framework-agnostic sse service for NodeJS Written on TS. Features Could be embedded to Express, Fastify, Nest, etc.

null 9 Dec 9, 2022
A Node.js framework for development of fast, simple, lightweight website.

MiuJS Web Framework A simple and minimal web framework using the JavaScript and Node.js. Featuring: builtin server multiple deploy target node vercel

TKNF 14 Jun 19, 2022
A form management library for SolidJS that is very lightweight and simple!

solform A form management library for SolidJS that is very lightweight and simple! Why solform Very easy, fast, lightweight and powerful! It has built

Okan YILDIRIM 16 Nov 15, 2022
๐ŸŒ— 1 line of code to apply auto dark / light theme and support custom theme for your website. Super fast and lightweight theme library.

themes.js A super lightweight and fast Theme library with auto system color scheme detection in JavaScript. Features Auto detect Dark / Light mode by

SerKo 4 Nov 29, 2022
A dependency-free JavaScript ES6 slider and carousel. Itโ€™s lightweight, flexible and fast. Designed to slide. No less, no more

Glide.js is a dependency-free JavaScript ES6 slider and carousel. Itโ€™s lightweight, flexible and fast. Designed to slide. No less, no more What can co

null 6.7k Jan 3, 2023
An event-driven architecture wrapper for Wechaty that applies the CQS principle by using separate Query and Command messages to retrieve and modify the bot state, respectively.

CQRS Wechaty An event-driven architecture wrapper for Wechaty that applies the CQS principle by using separate Query and Command messages to retrieve

Wechaty 3 Mar 23, 2022
jQuery UI widget for structured queries like "Contacts where Firstname starts with A and Birthday before 1/1/2000 and State in (CA, NY, FL)"...

Structured-Filter ยท Structured-Filter is a generic Web UI for building structured search or filter queries. With it you can build structured search co

Olivier Giulieri 238 Jan 6, 2023