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/replicaservice

v1.1.0-ts.2

Published

ReplicaService typings.

Downloads

17

Readme

ReplicaService Typings

roblox-ts typings for ReplicaService made by MadStudio.

Table of Contents

TypeScript Example

src/Types/Replicas.d.ts

import { Replica } from "@rbxts/replicaservice";
import PlayerDataReplicaWriteLib from "../Shared/WriteLibs/PlayerData";

declare global {
  interface Replicas {
    PlayerData: {
      Data: {
        Money: number;
      };
      Tags: {};
      WriteLib: typeof PlayerDataReplicaWriteLib;
    };
  }
}

export type PlayerDataReplica = Replica<"PlayerData">;

src/Shared/WriteLibs/PlayerData.ts

import { PlayerDataReplica } from "../../Types/Replicas.d";

export = {
  ChangeMoney: (
    replica: PlayerDataReplica,
    method: "Add" | "Sub",
    value: number
  ) => {
    const FinalValue =
      method === "Add"
        ? replica.Data.Money + value
        : replica.Data.Money - value;
    if (FinalValue < 0) return replica.SetValue(["Money"], 0);
    replica.SetValue(["Money"], FinalValue);
  },
};

src/Server/Main.server.ts

import { ReplicaService } from "@rbxts/replicaservice";
import { Players, ReplicatedStorage } from "@rbxts/services";

const PlayerDataReplicaWriteLib: ModuleScript = ReplicatedStorage.WaitForChild(
  "WriteLibs"
).WaitForChild("PlayerData") as ModuleScript; // This varies depending on your "default.project.json" paths.

Players.PlayerAdded.Connect((player: Player) => {
  const PlayerDataReplica = ReplicaService.NewReplica({
    ClassToken: ReplicaService.NewClassToken("PlayerData"),
    Data: {
      Money: 500,
    },
    Replication: player,
    WriteLib: PlayerDataReplicaWriteLib,
  });

  while (task.wait(1)) {
    PlayerDataReplica.Write("ChangeMoney", "Add", 500);
    // This example uses WriteLib feature of ReplicaService, but if you don't want/don't need to use a WriteLib, then you can do: PlayerDataReplica.SetValue(["Money"], PlayerDataReplica.Data.Money + 500)
  }
});

src/Client/Main.client.ts

import { ReplicaController } from "@rbxts/replicaservice";

ReplicaController.ReplicaOfClassCreated("PlayerData", (replica) => {
  print(
    `PlayerData replica received! Received player money: ${replica.Data.Money}`
  );

  replica.ListenToChange(["Money"], (newValue) => {
    print(`Money changed: ${newValue}`);
  });
});

ReplicaController.RequestData(); // This function should only be called once in the entire codebase! Read the documentation for more information.

Recommendations

  • Make your Replica.Data simple and small without too many keys inside another keys.

Limitations

  • Paths (StringPath and ArrayPath) can only access 21 keys of an object (this was added as a fix to the issue "Type instantiation is excessively deep and possibly infinite").

Frequently Asked Questions

  1. My editor features (autocomplete, others) are laggy, what can I do? Reopen your code editor (or if you're using Visual Studio Code, restart the TypeScript server), if it's still laggy, contact any of the collaborators in the roblox-ts server.
  2. I can't access a key in my object that is inside 35 keys! Read the limitations and recommendations.

Documentation

Visit the following website to go to the official ReplicaService documentation: https://madstudioroblox.github.io/ReplicaService/

Support

If you are having issues with typings, join roblox-ts Discord server and mention any of the collaborators (Mixu_78, or Sandy Stone) with your issue and we'll try to help the maximum we can.

If you are having issues with ReplicaService and not the typings, file an issue in the GitHub repository.