repo stringclasses 350
values | file_path stringlengths 29 200 | language stringclasses 2
values | file_type stringclasses 4
values | code stringlengths 2 1.01M | tokens int64 2 598k |
|---|---|---|---|---|---|
christopher-buss/roblox-ts-project-template | christopher-buss-roblox-ts-project-template-d9624aa/src/client/ui/components/object-viewport.tsx | roblox-ts | .tsx | import { useMountEffect } from "@rbxts/pretty-react-hooks";
import React, { useRef } from "@rbxts/react";
import Make from "shared/modules/make";
export interface ObjectViewportProps extends React.PropsWithChildren {
/** Additional depth to push the camera back. */
ExtraCameraDepth?: number;
/** The native props t... | 574 |
christopher-buss/roblox-ts-project-template | christopher-buss-roblox-ts-project-template-d9624aa/src/client/ui/components/primitive/button.tsx | roblox-ts | .tsx | import React from "@rbxts/react";
import type { FrameProps } from "./frame";
export interface ButtonProps extends FrameProps<TextButton> {
/** The default properties of a `TextButton` component. */
Native?: Partial<React.InstanceProps<TextButton>>;
/** A callback that is triggered when the button is clicked. */
o... | 563 |
christopher-buss/roblox-ts-project-template | christopher-buss-roblox-ts-project-template-d9624aa/src/client/ui/components/primitive/canvas-group.tsx | roblox-ts | .tsx | import React, { forwardRef } from "@rbxts/react";
import type { FrameProps } from "./frame";
export type CanvasGroupProps = FrameProps<CanvasGroup>;
/**
* A wrapper around the `CanvasGroup` component, a GuiObject that renders
* descendants as a group with color and transparency applied to the render
* result.
*
... | 305 |
christopher-buss/roblox-ts-project-template | christopher-buss-roblox-ts-project-template-d9624aa/src/client/ui/components/primitive/frame.tsx | roblox-ts | .tsx | import type { Ref } from "@rbxts/react";
import React, { forwardRef } from "@rbxts/react";
import type { BindingValue } from "types/util/react";
export interface FrameProps<T extends Instance = Frame> extends React.PropsWithChildren {
/** An optional helper that rounds the corners of the frame. */
CornerRadius?: Bi... | 410 |
christopher-buss/roblox-ts-project-template | christopher-buss-roblox-ts-project-template-d9624aa/src/client/ui/components/primitive/group.tsx | roblox-ts | .tsx | import React, { forwardRef } from "@rbxts/react";
interface GroupProps extends React.PropsWithChildren {
/** All the default properties of a `Frame` component. */
Native?: Partial<Omit<React.InstanceProps<Frame>, "BackgroundTransparency">>;
}
/**
* A container for grouping multiple components together.
*
* @exam... | 306 |
christopher-buss/roblox-ts-project-template | christopher-buss-roblox-ts-project-template-d9624aa/src/client/ui/components/primitive/image.tsx | roblox-ts | .tsx | import React, { forwardRef } from "@rbxts/react";
import type { BindingValue } from "types/util/react";
import type { AssetId } from "types/util/roblox";
import type { FrameProps } from "./frame";
export interface ImageProps extends FrameProps<ImageLabel> {
/** The image to display. */
Image: BindingValue<AssetId>... | 352 |
christopher-buss/roblox-ts-project-template | christopher-buss-roblox-ts-project-template-d9624aa/src/client/ui/components/primitive/layer.tsx | roblox-ts | .tsx | import React from "@rbxts/react";
import { $NODE_ENV } from "rbxts-transform-env";
import { IS_EDIT } from "shared/constants";
import { UltraWideContainer } from "../ultra-wide-container";
import { Group } from "./group";
export interface LayerProps extends React.PropsWithChildren {
/**
* Whether or not to constr... | 498 |
christopher-buss/roblox-ts-project-template | christopher-buss-roblox-ts-project-template-d9624aa/src/client/ui/components/primitive/padding-component.tsx | roblox-ts | .tsx | import type { PropsWithChildren } from "@rbxts/react";
import React, { forwardRef } from "@rbxts/react";
interface PaddingProps extends PropsWithChildren {
Padding: number;
}
/**
* A component for adding consistent padding around an element.
*
* @example
*
* ```tsx
* <Padding Padding={10}>
* ```
*
* @compon... | 227 |
christopher-buss/roblox-ts-project-template | christopher-buss-roblox-ts-project-template-d9624aa/src/client/ui/components/primitive/scrolling-frame.tsx | roblox-ts | .tsx | import React from "@rbxts/react";
import { useRem, useTheme } from "client/ui/hooks";
interface ScrollingFrameProps extends React.PropsWithChildren {
/** The size of the canvas. */
CanvasSize: Vector2;
/** All the default properties of a `ScrollingFrame` component. */
Native?: Partial<Omit<React.InstanceProps<Scr... | 518 |
christopher-buss/roblox-ts-project-template | christopher-buss-roblox-ts-project-template-d9624aa/src/client/ui/components/primitive/text.tsx | roblox-ts | .tsx | import React, { forwardRef } from "@rbxts/react";
import { useRem, useTheme } from "client/ui/hooks";
import type { BindingValue } from "types/util/react";
import type { FrameProps } from "./frame";
export interface TextLabelProps extends FrameProps<TextLabel> {
/**
* The font of the text, defaults to the primary... | 553 |
christopher-buss/roblox-ts-project-template | christopher-buss-roblox-ts-project-template-d9624aa/src/client/ui/functions/mount.tsx | roblox-ts | .tsx | import React, { StrictMode } from "@rbxts/react";
import { ReflexProvider } from "@rbxts/react-reflex";
import type { Root } from "@rbxts/react-roblox";
import { createPortal, createRoot } from "@rbxts/react-roblox";
import { PlayerGui } from "client/constants";
import { store } from "client/store";
import type { Rem... | 340 |
christopher-buss/roblox-ts-project-template | christopher-buss-roblox-ts-project-template-d9624aa/src/client/ui/functions/profiler.ts | roblox-ts | .ts | import type { FunctionComponent } from "@rbxts/react";
import React, { createElement } from "@rbxts/react";
export function profiler<P extends object>(
name: string,
render: FunctionComponent<P>,
): FunctionComponent<P> {
return (props: P) => {
debug.profilebegin(name);
const result = render(props);
debug.pro... | 307 |
christopher-buss/roblox-ts-project-template | christopher-buss-roblox-ts-project-template-d9624aa/src/client/ui/hooks/use-defined.tsx | roblox-ts | .tsx | import { useLatest } from "@rbxts/pretty-react-hooks";
function isEqualOrUndefined(previousValue: unknown, value: unknown): boolean {
return previousValue === value || value === undefined;
}
/**
* Returns the latest defined value.
*
* @param value - The value to use.
* @param initialValue - The initial value to ... | 154 |
christopher-buss/roblox-ts-project-template | christopher-buss-roblox-ts-project-template-d9624aa/src/client/ui/hooks/use-orientation.tsx | roblox-ts | .tsx | import { useViewport } from "@rbxts/pretty-react-hooks";
import { useEffect, useState } from "@rbxts/react";
type Orientation = "landscape" | "portrait";
export function useOrientation(): Orientation {
const [orientation, setOrientation] = useState<Orientation>("landscape");
const viewportBinding = useViewport((vi... | 141 |
christopher-buss/roblox-ts-project-template | christopher-buss-roblox-ts-project-template-d9624aa/src/client/ui/hooks/use-premium.tsx | roblox-ts | .tsx | import { useEventListener } from "@rbxts/pretty-react-hooks";
import { useState } from "@rbxts/react";
import { Players } from "@rbxts/services";
import { LocalPlayer } from "client/constants";
/**
* Returns whether the local player has a premium membership or not. This will
* update when the player's membership ch... | 170 |
christopher-buss/roblox-ts-project-template | christopher-buss-roblox-ts-project-template-d9624aa/src/client/ui/hooks/use-rem.tsx | roblox-ts | .tsx | import { useCallback, useContext } from "@rbxts/react";
import { DEFAULT_REM, RemContext } from "../providers/rem-provider";
export interface RemOptions {
maximum?: number;
minimum?: number;
}
interface RemFunction {
(value: number, mode?: RemScaleMode): number;
(value: UDim2, mode?: RemScaleMode): UDim2;
(valu... | 468 |
christopher-buss/roblox-ts-project-template | christopher-buss-roblox-ts-project-template-d9624aa/src/client/ui/hooks/use-selector.tsx | roblox-ts | .tsx | import type { UseSelectorHook } from "@rbxts/react-reflex";
import { useSelector } from "@rbxts/react-reflex";
import type { RootStore } from "client/store";
export const useRootSelector: UseSelectorHook<RootStore> = useSelector;
| 56 |
christopher-buss/roblox-ts-project-template | christopher-buss-roblox-ts-project-template-d9624aa/src/client/ui/hooks/use-store.tsx | roblox-ts | .tsx | import type { UseProducerHook } from "@rbxts/react-reflex";
import { useProducer } from "@rbxts/react-reflex";
import type { RootStore } from "client/store";
export const useStore: UseProducerHook<RootStore> = useProducer;
| 57 |
christopher-buss/roblox-ts-project-template | christopher-buss-roblox-ts-project-template-d9624aa/src/client/ui/hooks/use-theme.tsx | roblox-ts | .tsx | import { useSelector } from "@rbxts/react-reflex";
import { selectPlayerTheme } from "client/store/theme";
import type { Theme } from "../themes/theme";
export function useTheme(): Theme {
return useSelector(selectPlayerTheme);
}
| 49 |
christopher-buss/roblox-ts-project-template | christopher-buss-roblox-ts-project-template-d9624aa/src/client/ui/providers/rem-provider.tsx | roblox-ts | .tsx | import { map, useCamera, useDebounceState, useEventListener } from "@rbxts/pretty-react-hooks";
import React, { createContext, useCallback, useEffect } from "@rbxts/react";
export interface RemProviderProps extends React.PropsWithChildren {
baseRem?: number | undefined;
maximumRem?: number | undefined;
minimumRem?:... | 518 |
christopher-buss/roblox-ts-project-template | christopher-buss-roblox-ts-project-template-d9624aa/src/client/ui/react-config.tsx | roblox-ts | .tsx | import type { ProfilerOnRenderCallback } from "@rbxts/react";
import { $NODE_ENV } from "rbxts-transform-env";
export function reactConfig(): void {
if ($NODE_ENV !== "development") {
return;
}
_G.__DEV__ = true;
_G.__PROFILE__ = false;
// Avoid implicit React import before setting the __DEV__ flag
void imp... | 302 |
christopher-buss/roblox-ts-project-template | christopher-buss-roblox-ts-project-template-d9624aa/src/client/ui/ui.storybook.ts | roblox-ts | .ts | import React from "@rbxts/react";
import { GAME_NAME } from "shared/constants";
interface Storybook {
name: string;
react?: typeof React;
storyRoots: Array<Instance | undefined>;
}
export = identity<Storybook>({
name: GAME_NAME,
react: React,
storyRoots: [script.Parent],
});
| 72 |
christopher-buss/roblox-ts-project-template | christopher-buss-roblox-ts-project-template-d9624aa/src/server/mtx-service.ts | roblox-ts | .ts | import type { OnInit, OnStart } from "@flamework/core";
import { Service } from "@flamework/core";
import type { Logger } from "@rbxts/log";
import { Error, Object } from "@rbxts/luau-polyfill";
import Signal from "@rbxts/rbx-better-signal";
import { MarketplaceService, Players } from "@rbxts/services";
import Sift fro... | 2,735 |
christopher-buss/roblox-ts-project-template | christopher-buss-roblox-ts-project-template-d9624aa/src/server/player/character/character-service.ts | roblox-ts | .ts | import type { OnStart } from "@flamework/core";
import { Service } from "@flamework/core";
import type { Logger } from "@rbxts/log";
import { Error } from "@rbxts/luau-polyfill";
import { PhysicsService } from "@rbxts/services";
import { promiseTree } from "@rbxts/validate-tree";
import type { ListenerData } from "sha... | 1,416 |
christopher-buss/roblox-ts-project-template | christopher-buss-roblox-ts-project-template-d9624aa/src/server/player/player-badge-service.ts | roblox-ts | .ts | import { Service } from "@flamework/core";
import type { Logger } from "@rbxts/log";
import { BadgeService } from "@rbxts/services";
import { store } from "server/store";
import { selectPlayerAchievements } from "shared/store/persistent";
import { Badge } from "types/enum/badge";
import type { PlayerEntity } from "./... | 838 |
christopher-buss/roblox-ts-project-template | christopher-buss-roblox-ts-project-template-d9624aa/src/server/player/player-entity.ts | roblox-ts | .ts | import type { Janitor } from "@rbxts/janitor";
import type { Document } from "@rbxts/lapis";
import type { PlayerData } from "shared/store/persistent";
export class PlayerEntity {
/** The player's username. */
public readonly name: string;
/** A string representation of the player's UserId. */
public readonly use... | 126 |
christopher-buss/roblox-ts-project-template | christopher-buss-roblox-ts-project-template-d9624aa/src/server/player/player-service.ts | roblox-ts | .ts | import type { OnStart } from "@flamework/core";
import { Service } from "@flamework/core";
import { Janitor } from "@rbxts/janitor";
import type { Document } from "@rbxts/lapis";
import type { Logger } from "@rbxts/log";
import { Object } from "@rbxts/luau-polyfill";
import Signal from "@rbxts/rbx-better-signal";
impor... | 2,036 |
christopher-buss/roblox-ts-project-template | christopher-buss-roblox-ts-project-template-d9624aa/src/server/runtime.server.ts | roblox-ts | .ts | import { Flamework, Modding } from "@flamework/core";
import type { Logger } from "@rbxts/log";
import Log from "@rbxts/log";
import { GAME_NAME } from "shared/constants";
import { setupLogger } from "shared/functions/setup-logger";
function start(): void {
setupLogger();
Log.Info(`${GAME_NAME} is starting up! Ver... | 125 |
christopher-buss/roblox-ts-project-template | christopher-buss-roblox-ts-project-template-d9624aa/src/server/store/middleware/broadcaster.ts | roblox-ts | .ts | import type { BroadcastAction, ProducerMiddleware } from "@rbxts/reflex";
import { createBroadcaster } from "@rbxts/reflex";
import { Players } from "@rbxts/services";
import { $NODE_ENV } from "rbxts-transform-env";
import { events } from "server/network";
import { IS_EDIT } from "shared/constants";
import type { Ser... | 443 |
christopher-buss/roblox-ts-project-template | christopher-buss-roblox-ts-project-template-d9624aa/src/shared/assets.luau | luau | .luau | return {
badges = {
["example-badge"] = "rbxassetid://18110928024",
},
marketing = {
["example-icon"] = "rbxassetid://18110928241",
googly = "rbxassetid://18110928530",
},
}
| 69 |
christopher-buss/roblox-ts-project-template | christopher-buss-roblox-ts-project-template-d9624aa/src/shared/constants.ts | roblox-ts | .ts | import { RunService } from "@rbxts/services";
export const GAME_NAME = "Template for roblox-ts";
export const IS_EDIT = RunService.IsStudio() && !RunService.IsRunning();
| 41 |
christopher-buss/roblox-ts-project-template | christopher-buss-roblox-ts-project-template-d9624aa/src/shared/functions/game-config.ts | roblox-ts | .ts | import { $NODE_ENV } from "rbxts-transform-env";
export enum GameId {
Development = 6031475575,
Production = 6110424408,
}
function isGameId(value: number): value is GameId {
return value in GameId;
}
export function getConfigValueForGame<const T>(gameIdToValueTable: Record<GameId, T>): T {
if ($NODE_ENV === "de... | 143 |
christopher-buss/roblox-ts-project-template | christopher-buss-roblox-ts-project-template-d9624aa/src/shared/functions/setup-logger.ts | roblox-ts | .ts | import Log, { Logger, LogLevel } from "@rbxts/log";
import type { ILogEventSink, LogEvent } from "@rbxts/log/out/Core";
import { MessageTemplateParser, PlainTextMessageTemplateRenderer } from "@rbxts/message-templates";
import { RunService } from "@rbxts/services";
import { $package } from "rbxts-transform-debug";
imp... | 603 |
christopher-buss/roblox-ts-project-template | christopher-buss-roblox-ts-project-template-d9624aa/src/shared/modules/3d-sound-system/init.luau | luau | .luau | -- Services
local RunService = game:GetService("RunService")
local SoundService = game:GetService("SoundService")
if not RunService:IsClient() then
error("Sound System 3D is to be run on the client. Use RemoteEvents to have the client create the sound.")
end
-- Localize maths for optimization
-- local acos, cos, pi ... | 1,307 |
christopher-buss/roblox-ts-project-template | christopher-buss-roblox-ts-project-template-d9624aa/src/shared/modules/make.ts | roblox-ts | .ts | /* eslint-disable eslint-comments/no-unlimited-disable -- See below. */
/* eslint-disable -- Taken directly from https://www.npmjs.com/package/@rbxts/make due to compiler type mismatch. */
type WritablePropertyNames<T> = {
readonly [K in keyof T]-?: T[K] extends Callback
? never
: (<F>() => F extends { [Q in K]: T... | 669 |
christopher-buss/roblox-ts-project-template | christopher-buss-roblox-ts-project-template-d9624aa/src/shared/network.ts | roblox-ts | .ts | import { Networking } from "@flamework/networking";
import type { BroadcastAction } from "@rbxts/reflex";
import type { GamePass } from "types/enum/mtx";
import type { SerializedSharedState } from "./store";
/** Fired by client to server. */
interface ClientToServerEvents {
mtx: {
/**
* Sets the active state o... | 356 |
christopher-buss/roblox-ts-project-template | christopher-buss-roblox-ts-project-template-d9624aa/src/shared/store/index.ts | roblox-ts | .ts | import { createBinarySerializer } from "@rbxts/flamework-binary-serializer";
import type { CombineStates } from "@rbxts/reflex";
import { persistentSlice } from "./persistent/persistent-slice";
export type SharedState = CombineStates<typeof slices>;
export type SerializedSharedState = ReturnType<typeof stateSerDes.se... | 92 |
christopher-buss/roblox-ts-project-template | christopher-buss-roblox-ts-project-template-d9624aa/src/shared/store/middleware/profiler.ts | roblox-ts | .ts | import type { ProducerMiddleware } from "@rbxts/reflex";
export const profilerMiddleware: ProducerMiddleware = () => {
return (dispatch, name) => {
return (...args) => {
debug.profilebegin(name);
const result = dispatch(...args);
debug.profileend();
return result;
};
};
};
| 69 |
christopher-buss/roblox-ts-project-template | christopher-buss-roblox-ts-project-template-d9624aa/src/shared/store/persistent/persistent-selectors.ts | roblox-ts | .ts | import { createSelector } from "@rbxts/reflex";
import type { SharedState } from "..";
import type { PlayerData } from "./persistent-slice";
export function selectPlayerAchievements(playerId: string) {
return (state: SharedState) => state.persistent.achievements[playerId];
}
export function selectPlayerBalance(play... | 266 |
christopher-buss/roblox-ts-project-template | christopher-buss-roblox-ts-project-template-d9624aa/src/shared/store/persistent/persistent-slice/achievements.ts | roblox-ts | .ts | import { createProducer } from "@rbxts/reflex";
import type { Badge } from "types/enum/badge";
import type { PlayerAchievements, PlayerData } from "./default-data";
export type AchievementState = Readonly<Record<string, PlayerAchievements | undefined>>;
const initialState: AchievementState = {};
export const achie... | 333 |
christopher-buss/roblox-ts-project-template | christopher-buss-roblox-ts-project-template-d9624aa/src/shared/store/persistent/persistent-slice/balance.ts | roblox-ts | .ts | import { createProducer } from "@rbxts/reflex";
import type { PlayerBalance, PlayerData } from "./default-data";
export type BalanceState = Readonly<Record<string, PlayerBalance | undefined>>;
const initialState: BalanceState = {};
export const balanceSlice = createProducer(initialState, {
/** @ignore */
closePla... | 209 |
christopher-buss/roblox-ts-project-template | christopher-buss-roblox-ts-project-template-d9624aa/src/shared/store/persistent/persistent-slice/index.ts | roblox-ts | .ts | import { combineProducers } from "@rbxts/reflex";
import { achievementsSlice } from "./achievements";
import { balanceSlice } from "./balance";
import { mtxSlice } from "./mtx";
import { settingsSlice } from "./settings";
export * from "./achievements";
export * from "./balance";
export * from "./default-data";
expor... | 117 |
christopher-buss/roblox-ts-project-template | christopher-buss-roblox-ts-project-template-d9624aa/src/shared/store/persistent/persistent-slice/settings.ts | roblox-ts | .ts | import { createProducer } from "@rbxts/reflex";
import type { PlayerData, PlayerSettings } from "./default-data";
export type SettingsState = Readonly<Record<string, PlayerSettings | undefined>>;
const initialState: SettingsState = {};
export const settingsSlice = createProducer(initialState, {
/** @ignore */
clo... | 226 |
christopher-buss/roblox-ts-project-template | christopher-buss-roblox-ts-project-template-d9624aa/src/shared/util/core-call/init.luau | luau | .luau | local coreCall
do
local MAX_RETRIES = 8
local StarterGui = game:GetService("StarterGui")
local RunService = game:GetService("RunService")
function coreCall(method, ...)
local result = {}
for _ = 1, MAX_RETRIES do
result = { pcall(StarterGui[method], StarterGui, ...) }
if result[1] then
break
end
... | 116 |
christopher-buss/roblox-ts-project-template | christopher-buss-roblox-ts-project-template-d9624aa/src/shared/util/no-yield/init.luau | luau | .luau | --!strict
--[[
Calls a function and throws an error if it attempts to yield.
Pass any number of arguments to the function after the callback.
This function supports multiple return; all results returned from the
given function will be returned.
]]
local function resultHandler(co: thread, ok: boolean, ...)
if not... | 240 |
christopher-buss/roblox-ts-project-template | christopher-buss-roblox-ts-project-template-d9624aa/src/shared/util/player-util.ts | roblox-ts | .ts | import { Players } from "@rbxts/services";
import type { EvaluateInstanceTree } from "@rbxts/validate-tree";
export const CHARACTER_LOAD_TIMEOUT = 10;
export type CharacterRig = EvaluateInstanceTree<typeof CharacterSchema>;
export const CharacterSchema = {
$className: "Model",
Head: "MeshPart",
Humanoid: {
$cla... | 815 |
littensy/pretty-react-hooks | littensy-pretty-react-hooks-d8fe499/src/use-async-callback/use-async-callback.ts | roblox-ts | .ts | import { useCallback, useRef, useState } from "@rbxts/react";
import { useUnmountEffect } from "../use-unmount-effect";
export type AsyncState<T> =
| {
status: PromiseConstructor["Status"]["Started"];
message?: undefined;
value?: undefined;
}
| {
status: PromiseConstructor["Status"]["Resolved"];
me... | 414 |
littensy/pretty-react-hooks | littensy-pretty-react-hooks-d8fe499/src/use-async-effect/use-async-effect.ts | roblox-ts | .ts | import { useEffect } from "@rbxts/react";
/**
* Runs an async effect and cancels the promise when unmounting the effect.
* Note that effects paused by `await` still run while cancelled, so prefer
* to use promise chaining instead.
* @param effect The async effect to run.
* @param deps The dependencies to run the ... | 122 |
littensy/pretty-react-hooks | littensy-pretty-react-hooks-d8fe499/src/use-async/use-async.ts | roblox-ts | .ts | import { useEffect } from "@rbxts/react";
import { AsyncState, useAsyncCallback } from "../use-async-callback";
type AsyncStateTuple<T extends AsyncState<unknown>> = LuaTuple<
[result: T["value"], status: T["status"], message: T["message"]]
>;
/**
* Returns a tuple containing the result and status of a promise. Whe... | 203 |
littensy/pretty-react-hooks | littensy-pretty-react-hooks-d8fe499/src/use-binding-listener/use-binding-listener.ts | roblox-ts | .ts | import { Binding, useEffect, useMemo } from "@rbxts/react";
import { useLatestCallback } from "../use-latest-callback";
import { getBindingApi, isBinding } from "../utils/binding";
/**
* Subscribes to a binding and calls the given listener when the binding
* updates. If the value passed is not a binding, the listene... | 247 |
littensy/pretty-react-hooks | littensy-pretty-react-hooks-d8fe499/src/use-binding-state/use-binding-state.ts | roblox-ts | .ts | import { Binding, useState } from "@rbxts/react";
import { useBindingListener } from "../use-binding-listener";
import { getBindingValue } from "../utils/binding";
/**
* Returns the value of a binding. If the binding updates, the component will
* be re-rendered. Non-binding values will be returned as-is.
* @param b... | 135 |
littensy/pretty-react-hooks | littensy-pretty-react-hooks-d8fe499/src/use-camera/use-camera.ts | roblox-ts | .ts | import { useState } from "@rbxts/react";
import { Workspace } from "@rbxts/services";
import { useEventListener } from "../use-event-listener";
/**
* Returns the current camera. Updates when the current camera changes.
* @returns A camera instance.
*/
export function useCamera() {
const [camera, setCamera] = useSt... | 116 |
littensy/pretty-react-hooks | littensy-pretty-react-hooks-d8fe499/src/use-composed-ref/use-composed-ref.ts | roblox-ts | .ts | import { useMemo } from "@rbxts/react";
import { useLatestCallback } from "../use-latest-callback";
export type RefFunction<T> = (rbx?: T) => void;
/**
* Composes multiple ref functions into a single ref function and memoizes
* the result.
*
* To prevent excess ref calls, the composed ref is only created once on ... | 314 |
littensy/pretty-react-hooks | littensy-pretty-react-hooks-d8fe499/src/use-debounce-callback/use-debounce-callback.ts | roblox-ts | .ts | import { useMemo } from "@rbxts/react";
import { DebounceOptions, Debounced, debounce } from "@rbxts/set-timeout";
import { useLatest } from "../use-latest";
import { useUnmountEffect } from "../use-unmount-effect";
export interface UseDebounceOptions extends DebounceOptions {
/**
* The amount of time to wait befor... | 462 |
littensy/pretty-react-hooks | littensy-pretty-react-hooks-d8fe499/src/use-debounce-effect/use-debounce-effect.ts | roblox-ts | .ts | import { useEffect } from "@rbxts/react";
import { UseDebounceOptions, useDebounceCallback } from "../use-debounce-callback";
import { useUpdate } from "../use-update";
import { useUpdateEffect } from "../use-update-effect";
/**
* Creates a debounced effect that delays invoking `effect` until after `wait`
* seconds ... | 231 |
littensy/pretty-react-hooks | littensy-pretty-react-hooks-d8fe499/src/use-debounce-state/use-debounce-state.ts | roblox-ts | .ts | import { Dispatch, SetStateAction, useState } from "@rbxts/react";
import { UseDebounceOptions, useDebounceCallback } from "../use-debounce-callback";
/**
* Delays updating `state` until after `wait` seconds have elapsed since the
* last time the debounced function was invoked. Set to the most recently passed
* `st... | 225 |
littensy/pretty-react-hooks | littensy-pretty-react-hooks-d8fe499/src/use-defer-callback/use-defer-callback.ts | roblox-ts | .ts | import { useCallback, useRef } from "@rbxts/react";
import { RunService } from "@rbxts/services";
import { useLatest } from "../use-latest";
/**
* Defers a callback to be executed on the next Heartbeat frame. Consecutive
* calls to the returned `execute` function will cancel the previous call.
* @param callback The... | 238 |
littensy/pretty-react-hooks | littensy-pretty-react-hooks-d8fe499/src/use-defer-effect/use-defer-effect.ts | roblox-ts | .ts | import { useEffect } from "@rbxts/react";
import { useDeferCallback } from "../use-defer-callback";
/**
* Like `useEffect`, but the callback is deferred to the next Heartbeat frame.
* @param callback The callback to run
* @param dependencies Optional dependencies to trigger the effect
*/
export function useDeferEf... | 117 |
littensy/pretty-react-hooks | littensy-pretty-react-hooks-d8fe499/src/use-event-listener/use-event-listener.ts | roblox-ts | .ts | import { useEffect } from "@rbxts/react";
import { useLatest } from "../use-latest";
interface EventListenerOptions {
/**
* Whether the event should be connected or not. Defaults to `true`.
*/
connected?: boolean;
/**
* Whether the event should be disconnected after the first invocation.
* Defaults to `fals... | 733 |
littensy/pretty-react-hooks | littensy-pretty-react-hooks-d8fe499/src/use-interval/use-interval.ts | roblox-ts | .ts | import { useCallback, useEffect, useRef } from "@rbxts/react";
import { setInterval } from "@rbxts/set-timeout";
import { useLatestCallback } from "../use-latest-callback";
export interface UseIntervalOptions {
/**
* Whether the callback should run immediately when the interval is set.
* Defaults to `false`.
*/... | 285 |
littensy/pretty-react-hooks | littensy-pretty-react-hooks-d8fe499/src/use-key-press/use-key-press.ts | roblox-ts | .ts | import { InferEnumNames, useEffect, useMemo, useState } from "@rbxts/react";
import { ContextActionService, HttpService, UserInputService } from "@rbxts/services";
import { useEventListener } from "../use-event-listener";
/**
* A single key code name.
*/
export type KeyCode = InferEnumNames<Enum.KeyCode>;
/**
* A ... | 963 |
littensy/pretty-react-hooks | littensy-pretty-react-hooks-d8fe499/src/use-latest-callback/use-latest-callback.ts | roblox-ts | .ts | import { useCallback, useRef } from "@rbxts/react";
/**
* Returns a memoized callback that wraps the latest version of the input
* callback.
* @param callback The callback to memoize.
* @returns The memoized callback.
*/
export function useLatestCallback<T extends Callback>(callback: T): T {
const callbackRef = ... | 104 |
littensy/pretty-react-hooks | littensy-pretty-react-hooks-d8fe499/src/use-latest/use-latest.ts | roblox-ts | .ts | import { useMemo, useRef } from "@rbxts/react";
import { Predicate, isStrictEqual } from "../use-previous";
/**
* Returns a mutable ref that points to the latest value of the input.
*
* Takes an optional `predicate` function as the second argument that receives
* the previous and current value. If the predicate re... | 167 |
littensy/pretty-react-hooks | littensy-pretty-react-hooks-d8fe499/src/use-lifetime/use-lifetime.ts | roblox-ts | .ts | import { useBinding, useEffect } from "@rbxts/react";
import { RunService } from "@rbxts/services";
import { useEventListener } from "../use-event-listener";
/**
* Returns the lifetime of the component in seconds. Updates every frame on
* the Heartbeat event.
*
* If the dependency array is provided, the lifetime t... | 181 |
littensy/pretty-react-hooks | littensy-pretty-react-hooks-d8fe499/src/use-motion/use-motion.ts | roblox-ts | .ts | import type { Binding } from "@rbxts/react";
import { useBinding, useEffect, useMemo } from "@rbxts/react";
import type { Motion, MotionGoal } from "@rbxts/ripple";
import { createMotion } from "@rbxts/ripple";
import { RunService } from "@rbxts/services";
const callbacks = new Set<(dt: number) => void>();
let connect... | 340 |
littensy/pretty-react-hooks | littensy-pretty-react-hooks-d8fe499/src/use-mount-effect/use-mount-effect.ts | roblox-ts | .ts | import { EffectCallback, useEffect } from "@rbxts/react";
/**
* Runs a callback when the component is mounted.
* @param callback The callback to run.
*/
export function useMountEffect(callback: EffectCallback) {
useEffect(callback, []);
}
| 52 |
littensy/pretty-react-hooks | littensy-pretty-react-hooks-d8fe499/src/use-mouse/use-mouse.ts | roblox-ts | .ts | import { Binding, useBinding, useMemo } from "@rbxts/react";
import { UserInputService } from "@rbxts/services";
import { useEventListener } from "../use-event-listener";
import { useMountEffect } from "../use-mount-effect";
/**
* Returns a binding to the mouse position.
* @param listener Optional listener to be cal... | 232 |
littensy/pretty-react-hooks | littensy-pretty-react-hooks-d8fe499/src/use-previous/use-previous.ts | roblox-ts | .ts | import { useMemo, useRef } from "@rbxts/react";
export type Predicate<T> = (previous: T | undefined, current: T) => boolean;
export const isStrictEqual = (a: unknown, b: unknown) => a === b;
/**
* Returns the most recent value from the previous render. Returns `undefined`
* on the first render.
*
* Takes an opti... | 252 |
littensy/pretty-react-hooks | littensy-pretty-react-hooks-d8fe499/src/use-tagged/use-tagged.ts | roblox-ts | .ts | import { useState } from "@rbxts/react";
import { useEventListener } from "../use-event-listener";
import { CollectionService } from "@rbxts/services";
/**
* Wrapper around `CollectionService` that provides a list of `Instance` under the given `tag`.
*
* This list is updated as `Instance` are added and removed. You... | 307 |
littensy/pretty-react-hooks | littensy-pretty-react-hooks-d8fe499/src/use-throttle-callback/use-throttle-callback.ts | roblox-ts | .ts | import { useMemo } from "@rbxts/react";
import { Debounced, ThrottleOptions, throttle } from "@rbxts/set-timeout";
import { UseDebounceResult } from "../use-debounce-callback";
import { useLatest } from "../use-latest";
import { useUnmountEffect } from "../use-unmount-effect";
export interface UseThrottleOptions exten... | 378 |
littensy/pretty-react-hooks | littensy-pretty-react-hooks-d8fe499/src/use-throttle-effect/use-throttle-effect.ts | roblox-ts | .ts | import { useEffect } from "@rbxts/react";
import { UseThrottleOptions, useThrottleCallback } from "../use-throttle-callback";
import { useUpdate } from "../use-update";
import { useUpdateEffect } from "../use-update-effect";
/**
* Creates a throttled effect that only runs at most once per every `wait`
* seconds.
*
... | 219 |
littensy/pretty-react-hooks | littensy-pretty-react-hooks-d8fe499/src/use-throttle-state/use-throttle-state.ts | roblox-ts | .ts | import { Dispatch, SetStateAction, useState } from "@rbxts/react";
import { UseThrottleOptions, useThrottleCallback } from "../use-throttle-callback";
/**
* Creates a throttled state that only updates at most once per every `wait`
* seconds. Set to the most recently passed `state` after each interval.
*
* See [Dav... | 206 |
littensy/pretty-react-hooks | littensy-pretty-react-hooks-d8fe499/src/use-timeout/use-timeout.ts | roblox-ts | .ts | import { useCallback, useEffect, useRef } from "@rbxts/react";
import { setTimeout } from "@rbxts/set-timeout";
import { useLatestCallback } from "../use-latest-callback";
/**
* Sets a timeout that runs the callback function after `delay` seconds. If
* `delay` is `undefined`, the timeout is cleared. If the delay cha... | 208 |
littensy/pretty-react-hooks | littensy-pretty-react-hooks-d8fe499/src/use-timer/use-timer.ts | roblox-ts | .ts | import { Binding, useBinding, useCallback, useRef } from "@rbxts/react";
import { RunService } from "@rbxts/services";
import { useEventListener } from "../use-event-listener";
export interface Timer {
/**
* A binding that represents the current value of the timer.
*/
readonly value: Binding<number>;
/**
* St... | 361 |
littensy/pretty-react-hooks | littensy-pretty-react-hooks-d8fe499/src/use-unmount-effect/use-unmount-effect.ts | roblox-ts | .ts | import { useEffect } from "@rbxts/react";
import { useLatest } from "../use-latest";
/**
* Calls the callback when the component unmounts.
* @param callback The callback to call.
*/
export function useUnmountEffect(callback: () => void) {
const callbackRef = useLatest(callback);
useEffect(() => {
return () => ... | 86 |
littensy/pretty-react-hooks | littensy-pretty-react-hooks-d8fe499/src/use-update-effect/use-update-effect.ts | roblox-ts | .ts | import { useEffect, useRef } from "@rbxts/react";
/**
* Runs a callback when the component is re-rendered. Does not run on the
* first render.
* @param effect The callback to run.
* @param dependencies The dependencies to watch for changes.
*/
export function useUpdateEffect(effect: () => (() => void) | void, dep... | 122 |
littensy/pretty-react-hooks | littensy-pretty-react-hooks-d8fe499/src/use-update/use-update.ts | roblox-ts | .ts | import { useCallback, useState } from "@rbxts/react";
/**
* Returns a function that can be used to force a component to update. The
* function is recreated on the next render if called. This makes it useful as
* a dependency for other hooks.
* @returns A function that forces a rerender.
*/
export function useUpda... | 97 |
littensy/pretty-react-hooks | littensy-pretty-react-hooks-d8fe499/src/use-viewport/use-viewport.ts | roblox-ts | .ts | import { useBinding, useEffect } from "@rbxts/react";
import { useCamera } from "../use-camera";
/**
* Returns the current viewport size of the camera.
* @param listener Optional listener to be called when the viewport changes.
* @returns A binding to the viewport size.
*/
export function useViewport(listener?: (v... | 179 |
littensy/pretty-react-hooks | littensy-pretty-react-hooks-d8fe499/src/utils/binding.ts | roblox-ts | .ts | import { Binding, createBinding, joinBindings } from "@rbxts/react";
import { lerp } from "./math";
export interface BindingApi<T> {
subscribe: (callback: (newValue: T) => void) => () => void;
update: (newValue: T) => void;
getValue: () => T;
}
export interface Lerpable<T> {
Lerp: (this: T, to: T, alpha: number) ... | 1,286 |
littensy/pretty-react-hooks | littensy-pretty-react-hooks-d8fe499/src/utils/hoarcekat.tsx | roblox-ts | .tsx | import { createRoot } from "@rbxts/react-roblox";
import React, { StrictMode } from "@rbxts/react";
/**
* Returns a function that can be used as a Hoarcekat story. This function will
* mount the given component to the target instance and unmount it when the
* story is unmounted.
* @param TestComponent The componen... | 177 |
littensy/charm-example | littensy-charm-example-07db0be/src/client/__stories__/button.story.tsx | roblox-ts | .tsx | import Vide, { mount } from "@rbxts/vide";
import { Button } from "client/components/button";
import { px } from "client/composables/use-px";
export = (target: Instance) => {
return mount(() => {
return (
<Button
text="Hello, world!"
anchor={new Vector2(0.5, 0.5)}
position={new UDim2(0.5, 0, 0.5, 0)}... | 138 |
littensy/charm-example | littensy-charm-example-07db0be/src/client/app/app.tsx | roblox-ts | .tsx | import Vide from "@rbxts/vide";
import { Money } from "client/components/money";
import { TapHere } from "client/components/tap-here";
import { usePx } from "client/composables/use-px";
export function App() {
usePx();
return (
<screengui>
<Money />
<TapHere />
</screengui>
);
}
| 88 |
littensy/charm-example | littensy-charm-example-07db0be/src/client/app/mount.client.tsx | roblox-ts | .tsx | import { Players } from "@rbxts/services";
import Vide, { mount } from "@rbxts/vide";
import { App } from "./app";
mount(() => <App />, Players.LocalPlayer.WaitForChild("PlayerGui"));
| 48 |
littensy/charm-example | littensy-charm-example-07db0be/src/client/components/button.tsx | roblox-ts | .tsx | import Vide, { Derivable, source, spring } from "@rbxts/vide";
import { px } from "client/composables/use-px";
interface ButtonProps {
onClick?: () => void;
text?: Derivable<string>;
anchor?: Derivable<Vector2>;
position?: Derivable<UDim2>;
size?: Derivable<UDim2>;
native?: Vide.InstanceAttributes<TextButton>;
... | 406 |
littensy/charm-example | littensy-charm-example-07db0be/src/client/components/money.tsx | roblox-ts | .tsx | import Vide from "@rbxts/vide";
import { useMoney } from "client/composables/use-money";
import { px } from "client/composables/use-px";
export function Money() {
const money = useMoney();
return (
<textbutton
Text={() => `$${money()}`}
TextSize={() => px(32)}
AnchorPoint={new Vector2(1, 1)}
Position=... | 168 |
littensy/charm-example | littensy-charm-example-07db0be/src/client/components/tap-here.tsx | roblox-ts | .tsx | import Vide from "@rbxts/vide";
import { px } from "client/composables/use-px";
import { remotes } from "shared/remotes";
import { Button } from "./button";
export function TapHere() {
return (
<Button
onClick={() => remotes.tap()}
text="Tap here!"
anchor={new Vector2(1, 1)}
position={() => new UDim2(1... | 160 |
littensy/charm-example | littensy-charm-example-07db0be/src/client/composables/use-event.ts | roblox-ts | .ts | import { cleanup } from "@rbxts/vide";
/**
* Connects a callback to an event and disconnects it when the component is unmounted.
*
* @param event The event to connect to.
* @param callback The callback to connect.
*/
export function useEvent<T extends Callback>(event: RBXScriptSignal<T>, callback: T) {
const con... | 89 |
littensy/charm-example | littensy-charm-example-07db0be/src/client/composables/use-money.ts | roblox-ts | .ts | import { Players } from "@rbxts/services";
import { useAtom } from "@rbxts/vide-charm";
import { getPlayerData } from "shared/store/datastore";
export function useMoney() {
return useAtom(() => {
const data = getPlayerData(Players.LocalPlayer.Name);
return data ? data.money : 0;
});
}
| 75 |
littensy/charm-example | littensy-charm-example-07db0be/src/client/composables/use-px.ts | roblox-ts | .ts | import { Workspace } from "@rbxts/services";
import { source } from "@rbxts/vide";
import { useEvent } from "./use-event";
const BASE_RESOLUTION = new Vector2(1280, 832);
const MIN_SCALE = 0.5;
const DOMINANT_AXIS = 0.5;
const scale = source(1);
/**
* Assigns a call signature to an object.
*
* @param callback Th... | 435 |
littensy/charm-example | littensy-charm-example-07db0be/src/server/lib/datastore.server.ts | roblox-ts | .ts | import { effect } from "@rbxts/charm";
import { createCollection } from "@rbxts/lapis";
import { Players } from "@rbxts/services";
import { t } from "@rbxts/t";
import { deletePlayerData, getPlayerData, PlayerData, setPlayerData } from "shared/store/datastore";
const defaultData: PlayerData = {
money: 0,
};
const co... | 333 |
littensy/charm-example | littensy-charm-example-07db0be/src/server/lib/leaderstats.server.ts | roblox-ts | .ts | import { observe, subscribe } from "@rbxts/charm";
import { Players } from "@rbxts/services";
import { datastore, getPlayerData } from "shared/store/datastore";
observe(datastore.players, (_, name) => {
const player = Players.FindFirstChild(name);
if (!player) {
return;
}
const leaderstats = new Instance("Fold... | 162 |
littensy/charm-example | littensy-charm-example-07db0be/src/shared/remotes/index.ts | roblox-ts | .ts | import { SyncPayload } from "@rbxts/charm-sync";
import { Client, createRemotes, remote, Server } from "@rbxts/remo";
import { GlobalAtoms } from "shared/store/sync/atoms";
export const remotes = createRemotes({
sync: remote<Client, [payload: SyncPayload<GlobalAtoms>]>(),
init: remote<Server>(),
tap: remote<Server>... | 88 |
littensy/charm-example | littensy-charm-example-07db0be/src/shared/store/datastore.ts | roblox-ts | .ts | import { atom } from "@rbxts/charm";
export interface PlayerData {
readonly money: number;
}
type PlayerDataMap = {
readonly [K in string]?: PlayerData;
};
export const datastore = {
players: atom<PlayerDataMap>({}),
};
export function getPlayerData(id: string) {
return datastore.players()[id];
}
export functi... | 195 |
littensy/charm-example | littensy-charm-example-07db0be/src/shared/store/sync/sync.client.ts | roblox-ts | .ts | import { client } from "@rbxts/charm-sync";
import { remotes } from "shared/remotes";
import { atoms } from "./atoms";
const syncer = client({ atoms });
remotes.sync.connect((payload) => {
syncer.sync(payload);
});
remotes.init();
| 60 |
littensy/charm-example | littensy-charm-example-07db0be/src/shared/store/sync/sync.server.ts | roblox-ts | .ts | import { server } from "@rbxts/charm-sync";
import { remotes } from "shared/remotes";
import { atoms } from "./atoms";
import { filterPayload } from "./utils/filter-payload";
const syncer = server({ atoms });
syncer.connect((player, payload) => {
remotes.sync(player, filterPayload(player, payload));
});
remotes.in... | 93 |
littensy/charm-example | littensy-charm-example-07db0be/src/shared/store/sync/utils/filter-payload.ts | roblox-ts | .ts | import { SyncPayload } from "@rbxts/charm-sync";
import { GlobalAtoms } from "../atoms";
/**
* Filters the payload to only include the player's data.
*
* @param player The player to send the payload to.
* @param payload The payload to filter.
* @returns A new payload that only includes the player's data.
*/
exp... | 211 |
littensy/charm-example | littensy-charm-example-07db0be/src/shared/store/sync/utils/flatten-atoms.ts | roblox-ts | .ts | import { AtomMap } from "@rbxts/charm-sync";
type NestedAtomMap = {
readonly [K in string]: AtomMap;
};
type FlattenNestedAtoms<T extends NestedAtomMap> = {
readonly [K in keyof T as `${string & K}/${string & keyof T[K]}`]: T[K][Extract<keyof T[K], string>];
};
/**
* Assigns unique prefixes to each atom and flatt... | 237 |
roblox-ts/types | roblox-ts-types-27a8de7/src/constants.ts | roblox-ts | .ts | import path from "path";
export const INCLUDE_FOLDER_PATH = path.join(__dirname, "..", "include");
export const GENERATED_FOLDER_PATH = path.join(INCLUDE_FOLDER_PATH, "generated");
export const TSCONFIG_PATH = path.join(INCLUDE_FOLDER_PATH, "tsconfig.json");
export const CUSTOM_DEFITIONS_PATH = path.join(INCLUDE_FOLDE... | 1,276 |
roblox-ts/types | roblox-ts-types-27a8de7/tests/selector.ts | roblox-ts | .ts | /// <reference path="../include/roblox.d.ts" />
// Cases for the QueryDescendants selector resolver (include/selector.d.ts), checked by
// `npm test` (src/runTests.ts). `game` is the DataModel global from include/roblox.d.ts.
// `//=> <type>` asserts the type inferred for the declaration; `// @ts-expect-error` asserts... | 1,671 |
littensy/slither | littensy-slither-56545f1/scripts/run-tests.server.lua | luau | .lua | local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerScriptService = game:GetService("ServerScriptService")
local TestEZ = require(ReplicatedStorage.rbxts_include.node_modules["@rbxts"].testez.src)
TestEZ.TestBootstrap:run({
ServerScriptService.TS.test,
ReplicatedStorage.TS.test,
}, TestEZ.Rep... | 80 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.