1.1.0 • Published 5 years ago

@rbxts/yield-for-tree v1.1.0

Weekly downloads
22
License
ISC
Repository
github
Last release
5 years ago

yield-for-tree

Returns a yieldForTree function, which can be used like so:

Demo

yieldForTree(game.GetService("Workspace"), {
	$className: "Workspace",

	SpawnLocation: {
		$className: "SpawnLocation",

		Decal: {
			$className: "Decal",

			Value: {
				$className: "IntValue",
				Folder: "Folder",
			},
		},
	},
} as const).then(workspace => {
	print(++workspace.SpawnLocation.Decal.Value.Value);
	const count = workspace.SpawnLocation.Decal.Value.Clone();
	count.Parent = workspace;

	// Members are preserved by the `Clone` method!
	print((count.Folder.Name = "Soup"), ++count.Value);
});

The first parameter must be an Instance (or extend from it). The second parameter must be an object tree similar to ones considered valid by Rojo. Every tree must have a $className member, and can have any number of keys which represent the name of a child instance, which should have a corresponding value which is this same kind of tree. There is also a shorthand syntax, seen above with Folder: "Folder", which is equivalent to Folder: { $className: "Folder" }.

Note: Currently, the as const may be necessary to preserve the true type of the object tree. Your types will not work if you do not use the tree object in-line or declare it with as const after it.

This library also exports EvaluateInstanceTree if you want to use it for your own nefarious purposes.

Note: This library doesn't mutate/modify anything, it only yields until the tree is fully detected.

Also see validate-tree

1.1.0

5 years ago

1.0.9

5 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago