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/slotted-data-manager

v1.0.1

Published

A data manager that has full autocomplete for retrieving data

Downloads

7

Readme

@rbxts/slotted-data-manager

IMPORTANT: This is a very hands-on process - the data manager does NOTHING behind the scenes without your consent!

To setup:

import { BaseDataManager } from '@rbxts/slotted-data-manager';

export const dataManager = new BaseDataManager({
    gold: 0,
    class: undefined as undefined | string // this won't be saved in lua, you'll have to manually recreate this when reassigning it
});

Now, the data isn't loaded yet - you have to load the player's data. I use TeleportService to send the player's save slot - though you might do it differently. The save slot system is up to you.

const Players = game.GetService('Players');

interface TeleportData {
    save: number;
}

Players.PlayerAdded.Connect(player => {
    const joinData = player.GetJoinData();

    if (!joinData.TeleportData) {
        player.Kick('Internal error');
        return;
    }

    if (!('save' in joinData.TeleportData)) {
        player.Kick('Internal error');
        return;
    }

    const success = dataManager.loadData(player, (joinData.TeleportData as TeleportData).save);
});

Loading data is also manual. To create a new save for a player (recommended index starting from 0, though it'd probably work with indexes starting with 1):

// You can handle remotes any way you want, but I'm using @rbxts/dispatcher since that's my internal tooling
// .handle is just OnServerInvoke for a RemoteFunction
serverDispatcher.handle('newSave', (player, saveNumber) => {
	if (!typeIs(saveNumber, 'number')) return false;
	if (saveNumber > 4) return false;
	if (saveNumber < 0) return false;

	dataManager.newSave(player, saveNumber);

	return true;
});

To check if a save exists:

serverDispatcher.handle('saveExists', (player, saveNumber) => {
    if (!typeIs(saveNumber, 'number')) return false;

	const saveJsonData = dataManager.getJsonData(player, saveNumber); // This will be undefined if nothing is saved here

    return saveJsonData === undefined ? false : true;
});

Finally, you'll probably also want functionality such as autosaving, and data loss prevention. These can be enabled by using:

dataManager.bindGameClose();
dataManager.bindAutoSave();