Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/shadow-objects/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to [@spearwolf/shadow-objects](https://github.com/spearwolf/
The format is loosely based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

- renamed `useResource()` to `createResource()` in `ShadowObjectParams` interface

## [0.23.0] - 2025-11-26

- enhance the shadow-objects creation api _aka_ `ShadowObjectParams`
Expand Down
2 changes: 1 addition & 1 deletion packages/shadow-objects/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ The `ShadowObjectParams` object provides all necessary tools to interact with th
| **`useParentContext(name)`** | Skips the current Entity and consumes context directly from the parent. |
| **`provideContext(name, value)`** | Provides a context value (or signal) to descendant Entities. |
| **`provideGlobalContext(name, value)`** | Provides a context value globally to all Entities. |
| **`useResource(factory, cleanup)`** | Manages an external resource (e.g., a Three.js object) with automatic cleanup when dependencies change. |
| **`createResource(factory, cleanup)`** | Manages an external resource (e.g., a Three.js object) with automatic cleanup when dependencies change. |
| **`createEffect(callback)`** | Runs a side effect whenever accessed signals change. |
| **`createSignal(initialValue)`** | Creates a local reactive state signal. |
| **`createMemo(factory)`** | Creates a derived signal that updates only when dependencies change. |
Expand Down
10 changes: 5 additions & 5 deletions packages/shadow-objects/src/in-the-dark/Kernel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ describe('Kernel', () => {
});
});

describe('useResource', () => {
describe('createResource', () => {
it('should create a resource and call cleanup on entity destruction', () => {
const registry = new Registry();
const kernel = new Kernel(registry);
Expand All @@ -559,8 +559,8 @@ describe('Kernel', () => {

@ShadowObject({registry, token: 'testResource'})
class TestResource {
constructor({useResource}: ShadowObjectParams) {
resourceSignal = useResource(createFn, cleanupFn);
constructor({createResource}: ShadowObjectParams) {
resourceSignal = createResource(createFn, cleanupFn);
}
}
expect(TestResource).toBeDefined();
Expand All @@ -587,8 +587,8 @@ describe('Kernel', () => {

@ShadowObject({registry, token: 'testUndefinedResource'})
class TestUndefinedResource {
constructor({useResource}: ShadowObjectParams) {
useResource(createFn, cleanupFn);
constructor({createResource}: ShadowObjectParams) {
createResource(createFn, cleanupFn);
}
}
expect(TestUndefinedResource).toBeDefined();
Expand Down
2 changes: 1 addition & 1 deletion packages/shadow-objects/src/in-the-dark/Kernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ export class Kernel {
return result;
},

useResource<T>(factory: () => T | undefined, cleanup?: (resource: T) => void): Signal<T | undefined> {
createResource<T>(factory: () => T | undefined, cleanup?: (resource: T) => void): Signal<T | undefined> {
const resourceSignal = createSignal<T | undefined>(undefined);
unsubscribeSecondary.add(() => destroySignal(resourceSignal));

Expand Down
2 changes: 1 addition & 1 deletion packages/shadow-objects/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export interface ShadowObjectParams {
useProperty<T = any>(name: string, isEqual?: CompareFunc<T>): SignalReader<T>;
useProperties<K extends string>(props: Record<K, string>): Record<K, SignalReader<any>>;

useResource<T>(factory: () => T | undefined, cleanup?: (resource: T) => void): Signal<T | undefined>;
createResource<T>(factory: () => T | undefined, cleanup?: (resource: T) => void): Signal<T | undefined>;

createEffect(...args: Parameters<typeof createEffect>): ReturnType<typeof createEffect>;
createSignal<T = unknown>(...args: Parameters<typeof createSignal<T>>): ReturnType<typeof createSignal<T>>;
Expand Down