Security News
The Unpaid Backbone of Open Source: Solo Maintainers Face Increasing Security Demands
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
@rbxts/reflex
Advanced tools
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.
This package is available for Roblox TypeScript and Wally.
npm install @rbxts/reflex
yarn add @rbxts/reflex
pnpm add @rbxts/reflex
Take me to the documentation →
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 }),
});
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
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 →
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:
<ReflexProvider>
enables Reflex Hooks for a producer.Roact.mount(
<ReflexProvider producer={producer}>
<App />
</ReflexProvider>,
playerGui,
);
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();
// ...
Use these Hooks to read and subscribe to state:
useSelector
lets a component subscribe to a Reflex producer.useSelectorCreator
lets you call useSelector
with a selector factory.function Counter() {
const count = useSelector((state) => state.count);
// ...
Reflex is licensed under the MIT License.
FAQs
A state container for side effects
The npm package @rbxts/reflex receives a total of 257 weekly downloads. As such, @rbxts/reflex popularity was classified as not popular.
We found that @rbxts/reflex demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.
Security News
A developer is accusing Tencent of violating the GPL by modifying a Python utility and changing its license to BSD, highlighting the importance of copyleft compliance.