Texts
backend.Texts (Class)
Implements: spec.Texts
Clay backend implementation for loading text files.
This class handles loading of text-based resources from various sources:
- Local filesystem (when available)
- HTTP/HTTPS URLs
- Application bundle resources
Features:
- Asynchronous and synchronous loading modes
- Request deduplication to prevent redundant loads
- Hot reload support for development
- Automatic UTF-8 text decoding
- URL query parameter stripping for cache busting
Common text file types include JSON, XML, configuration files, shader source code, and other text-based assets.
See: spec.Texts The interface this class implements, TextAsset For the high-level text asset interface
Instance Members
Loads text content from the specified path.
The path can be:
- Relative to the assets directory (e.g., "data/config.json")
- Absolute filesystem path (e.g., "/usr/local/data/config.txt")
- HTTP/HTTPS URL (e.g., "https://example.com/data.json")
Multiple requests for the same path are automatically deduplicated, with all callbacks being notified when the load completes.
Name | Type | Default | Description |
---|---|---|---|
path |
String | Path to the text file to load | |
options |
Null<LoadTextOptions> | (optional) | Optional loading configuration (sync/async, immediate queue) |
_done |
Function | Callback invoked with the loaded text (null on error) |
Indicates whether this backend supports hot reloading of text files. Clay backend always supports hot reload for development efficiency.
Returns | Description |
---|---|
Bool | true, indicating hot reload is supported |
Private Members
Tracks pending load operations to prevent duplicate requests. Maps file paths to arrays of callbacks waiting for that file.