JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 14
  • Score
    100M100P100Q57763F
  • License ISC

Package Exports

  • @rbxts/fabric

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@rbxts/fabric) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@rbxts/fabric

roblox-ts typings for evaera's Fabric.

npm i @rbxts/fabric @rbxts/t

NPM

Modifications

Modifications I have made to the original package

Usage

ExampleUnit.ts

import { Fabric, UnitDefinition, ThisFabricUnit } from "@rbxts/fabric";

const fabric = new Fabric("game");

declare global {
    interface FabricUnits {
        ExampleUnit: ExampleUnitDefinition;
    }
}

//NOTE: you should never define the `name` field here. `name` should always be the same as the key in `FabricUnits`, which is done automatically for you.
interface ExampleUnitDefinition extends UnitDefinition<"ExampleUnit"> {
    //IMPORTANT: these three fields are for typing only, and they have to be optional so that the below implementation does not have to define them
    data?: { bar: boolean };
    _addLayerData?: { bar: true }; //if `_addLayerData` is not specified, `data` will be used.
    ref?: Player;
    
    //alternatively, if you are using `defaults` for this unit, you could omit the `data` field above and just add `defaults: { bar: boolean }`,
    //in which you would also have to do `defaults: { bar: true }` in the below implementation of this interface

    foo(this: ThisFabricUnit<"ExampleUnit">): void;
}

const exampleUnitDefinition: ExampleUnitDefinition = {
    name: "ExampleUnit",

    foo() {
        this.addLayer("exampleScope", { bar: true }); //here, `bar` must equal `true`.

        //hypothetically, if `_addLayerData` was not specified, then `bar` would be able to be `true` OR `false`, since those are of type `boolean`.
    },
};

fabric.registerUnit(exampleUnitDefinition);

const unit = fabric.getOrCreateUnitByRef("ExampleUnit", game); //attach an ExampleUnit to `game`
unit.foo();
print(unit.data!.bar); // > true

Changelog

1.1.4

- Fixed defaults typing
- If `data` is not typed, `defaults` will be used
- Expose `DEBUG`

1.1.3

- Rollback fix for #3 (`getUnit` and `getOrCreateUnit`, as well as `UnitDefinition.units` ref validity)

1.1.2

- Fix PickByUnitRef

1.1.1

- `Unit.getUnit` and `Unit.getOrCreateUnit` now check for ref validity
- `UnitDefinition.units` now checks for ref validity and uses the `_addLayerData` type if applicable
- Members of `Reducers`, `Symbol`, and `SinglePromiseEvent` now show in intellisense
- `RoactUnitProps<TInstance, TFabricUnitNames>` exposed, can be used to intersect Roact props
- Unit data is no longer automatically made Partial<TData>
- Reorganized types

1.0.0

- Initial release