addMethodChaining
addMethodChaining
Registers a chainable method name to an implementation function. Warns and returns on name collision; throws if the implementation is not a function.
Core Advantages
Duplicate-safe and type-checked extension point. Add chainable sugar across node types without touching core code.
Common Uses
Provide convenience operators for scalar/vector/color nodes (e.g., .saturate(), .remap()).
Wrap common multi-step math into a single chainable call for readability.
Define project-specific, domain-oriented TSL method extensions.
How to adjust
Method names must be unique. To replace an existing one, use a new name or alter the underlying registry first. The implementation typically receives the callee node (or uses `this`), depending on runtime wiring.
Code Examples
1// 1) Valid registration
2addMethodChaining('saturate', (node) => node.saturate());
3
4// 2) Duplicate name -> warning and ignored
5addMethodChaining('saturate', () => {/* ... */}); // -> console.warn
6
7// 3) Non-function implementation -> Error
8addMethodChaining('bad', 123); // -> throw Error
9
10// 4) Typical usage: the runtime attaches the method to node instances (framework-dependent)
11// Example: color(0xff8844).saturate();