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/fast-replica

v3.0.2

Published

A simple and intuitive package for sharing data from server to client.

Downloads

24

Readme

Fast Replica

A simple and intuitive package for sharing data from server to client. Structured in a similar manner to @flamework/networking.

This is preferable to @rbxts/replica-service if you are looking for fully pre-defined replicas that will be automatically initialized before use.

API:

FastReplica (Shared)

FastReplica.createReplicas(initialData: Replicas): GlobalReplicas The Replicas that will be created, it is considered good practice to only call this once.

Replica Client

readonly Replica.Name: string

The ID the Replica identifies as.

Replica.Loaded

Whether the server has sent information to the replica yet. Do NOT modify this value.

Replica.GetValue(): DeepReadonly

Returns the current value of the Replica.

Replica.Started: Signal<(data: DeepReadonly) => void>

A signal that fires when the replica is first initialized by the server. Do note that you can use the Replica before then, but it will only contain the initial value.

Replica.Changed: Signal<(data: DeepReadonly) => void>

A signal that fires every time the server sends new data to the client.

Replica.PathChanged: Signal<(path: Path, value: PathValue) => void>

A signal that fires when the server only changes a specific path.

Replica Server

readonly Replica.Name: string

The ID the Replica identifies as.

Replica.SetValue(clients: Player | Player[] | "All", Value: Data): void

Syncs the value provided with the clients specified within the arguments.

Replica.SetPath(clients: Player | Player[] | "All", path: Path Value: Data): void

Syncs the specific path value to the clients provided

Replica.Assimilate(clients: Player | Player[]): void

Assimilate the client's value back to what "All" should have.

Replica.GetValue(player: Player): Data

Fetches the value the specific player current is using.

Replica.Started: Signal<(player: Player, data: DeepReadonly) => void>

A signal that fires when a player is first initialized by the server.

Replica.Changed: Signal<(player: Player, data: DeepReadonly) => void>

A signal that fires every time the server sends new data to a client.

Replica.PathChanged: Signal<(path: Path, value: PathValue) => void>

A signal that fires when the only a specific path on the provided clients will be changed.

Code Examples:

Shared

// shared/replicas.ts
import { FastReplica } from "@rbxts/fast-replica";

type Replicas = { Profile: { Level: number } };
export const globalReplicas = FastReplica.createReplicas<Replicas>({
    Profile: { Level: 0 }, // Initial Value (For when not replicated and default replication)
    State: "Intermission", // Can be any value that could be naturally replicated via RemoteEvents!
    ExtraData: {
        Players: {
            Local: 1,
        },
    },
})

Client

// client/replicas.ts
import { globalReplicas } from "shared/replicas";
export const Replicas = globalReplicas.client;
import { Replicas } from "client/replicas";

Replicas.Profile.Changed.Connect((value, old) => print(value.Level)); // Fires every time the Value is changed on the server.
Replicas.State.Started.Connect((value) => print(value)); // This fires when the server first syncs the data.
print(Replicas.State.GetValue()); // Fetches and prints the value.
Replicas.ExtraData.PathChanged.Connect((path, value) => print(`Path changed: ${path}: ${value}`));

Server

// server/replicas.ts
import { globalReplicas } from "shared/replicas";
export const Replicas = globalReplicas.server;
import { Replicas } from "client/replicas";
import { Players } from "@rbxts/services";

task.wait(2.5)
Replicas.Profile.Started.Connect((player: Player, value) => print(`${player.DisplayName}: ${tostring(value)}`)); // Fires when the server sends the initial data to a player.
Replicas.Profile.Changed.Connect((player: Player, value) => print(`${player.DisplayName}: ${tostring(value)}`)); // Fires every time the server sends data to a player.
Replicas.Profile.SetPath("All", "Level", { Level: 10 }); // Sets the value to every player.
Replicas.State.SetValue(Players.GetPlayers(), "Spectating"); // This accepts Player instances or an array of Players as well!
print(Replicas.State.GetValue(Players.GetPlayers()[0])); // Prints the value for a specific player.
Replicas.ExtraData.SetPath("All", "Players.Local", 2);