npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@rbxts/reflex

v4.3.1

Published

A state container for side effects

Downloads

1,142

Readme

GitHub Workflow Status npm version npm downloads GitHub license


 

♻️ Reflex

Reflex is a simple state container inspired by Rodux and Silo, designed to be an all-in-one solution for managing and reacting to state in Roblox games.

You can use Reflex with Roact on the client with @rbxts/roact-reflex, or use it to manage your game's state on the server.

 

📦 Installation

This package is available for Roblox TypeScript and Wally.

npm install @rbxts/reflex
yarn add @rbxts/reflex
pnpm add @rbxts/reflex

 

📚 Quick Start

Take me to the documentation →

⚡️ Start using Reflex

Where Rodux uses stores, reducers, and actions, Reflex revolves around actions and producers. Create a producer with an initial state and a set of actions, and you're ready to go.

import { createProducer } from "@rbxts/reflex";

interface State {
	count: number;
}

const initialState: State = {
	count: 0,
};

const producer = createProducer(initialState, {
	increment: (state) => ({ ...state, count: state.count + 1 }),
	reset: (state) => ({ ...state, count: 0 }),
});

✨ Use your producer anywhere

Reflex was designed to make managing your state simple and straightforward. Dispatch actions by calling the action directly, and read & subscribe to state with selectors.

const selectCount = (state: State) => state.count;

producer.subscribe(selectCount, (count) => {
	print(`The count is now ${count}`);
});

producer.increment(); // The count is now 1

 

⚛️ Roact Reflex

The official bindings for Reflex and Roact Hooked are available under @rbxts/roact-reflex. Currently, there is no support for Luau projects.

See the source code on GitHub →

⚙️ Components

Roact Reflex allows you to use your root producer from Roact function components. It exposes a component that you can use to specify the producer for Hooks to use:

Roact.mount(
	<ReflexProvider producer={producer}>
		<App />
	</ReflexProvider>,
	playerGui,
);

🪝 Context Hooks

You can use Hooks to read and subscribe to state, or to dispatch actions. Use these Hooks in function components that are wrapped in a <ReflexProvider>.

Use these Hooks to access the root producer and dispatch actions:

  • useProducer lets components read and dispatch actions to the root producer.
function Button() {
    const { increment } = useProducer();
    // ...

🪝 State Hooks

Use these Hooks to read and subscribe to state:

function Counter() {
    const count = useSelector((state) => state.count);
    // ...

 

📝 License

Reflex is licensed under the MIT License.