docs: rewrite README with namespace examples and better quick start - #1253
Conversation
Performance Check Results |
There was a problem hiding this comment.
Pull request overview
This PR rewrites the README.md to showcase blECSd's namespace-based API and provide better quick start examples. It addresses issue #1250 by replacing low-level SoA component access examples with higher-level factory functions and namespace objects, making the library more approachable for new users.
Changes:
- Replaces Quick Start with a complete terminal app example using factory functions (
createScreenEntity,createBoxEntity, etc.) - Adds comprehensive "Namespace Imports" section demonstrating the
position,scroll,content,rope,colorsnamespace pattern - Adds Import Tiers table explaining the three-tier export system (Tier 1: curated essentials, Tier 2: full module access, Tier 3: deep imports)
- Documents addon packages (@blecsd/3d, @blecsd/ai, @blecsd/audio, @blecsd/game, @blecsd/media) with namespace and subpath import examples
- Updates Components table to include namespace column for discoverability
- Updates Library Design code examples to use namespace imports
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const text = rope.getText(modified); | ||
|
|
||
| // Color utilities | ||
| const hex = colors.rgbToHex(255, 100, 0); |
There was a problem hiding this comment.
The method name should be colors.colorToHex instead of colors.rgbToHex. The colors namespace does not have an rgbToHex method - it exports colorToHex, hexToColor, packColor, unpackColor, and parseColor.
| const hex = colors.rgbToHex(255, 100, 0); | |
| const hex = colors.colorToHex(255, 100, 0); |
| See [API Reference](./docs/api/index.md) for the complete list. | ||
| position.set(world, eid, 10, 5); // set x, y | ||
| content.set(world, eid, 'Hello'); // set text content | ||
| list.select(world, eid, 2); // select item at index |
There was a problem hiding this comment.
The method list.select does not exist. To select an item at a specific index, use list.selection.setIndex(world, eid, 2) instead. The list namespace organizes selection methods under the selection sub-namespace.
| list.select(world, eid, 2); // select item at index | |
| list.selection.setIndex(world, eid, 2); // select item at index |
|
|
||
| // AI widgets via namespaces | ||
| import { conversation, tokenTracker } from '@blecsd/ai'; | ||
| conversation.addMessage(state, { role: 'user', content: 'Hello' }); |
There was a problem hiding this comment.
The conversation.addMessage function signature is incorrect. According to the implementation, addMessage takes (state: ConversationState, role: MessageRole, content: string, id?: string) as parameters, not an object. The correct call should be: conversation.addMessage(state, 'user', 'Hello');
| conversation.addMessage(state, { role: 'user', content: 'Hello' }); | |
| conversation.addMessage(state, 'user', 'Hello'); |
| // 3D math via namespaces | ||
| import { vec3, mat4, projection } from '@blecsd/3d'; | ||
| const v = vec3.add(vec3.create(1, 0, 0), vec3.create(0, 1, 0)); | ||
| const mvp = mat4.multiply(projection.perspective(60, 1.5, 0.1, 100), viewMatrix); |
There was a problem hiding this comment.
The projection.perspective function takes a configuration object, not individual parameters. The correct call should be: projection.perspective({ fov: 60, aspect: 1.5, near: 0.1, far: 100 }) instead of projection.perspective(60, 1.5, 0.1, 100).
| const mvp = mat4.multiply(projection.perspective(60, 1.5, 0.1, 100), viewMatrix); | |
| const mvp = mat4.multiply( | |
| projection.perspective({ fov: 60, aspect: 1.5, near: 0.1, far: 100 }), | |
| viewMatrix | |
| ); |
| scroll.toTop(world, eid); | ||
|
|
||
| // Text manipulation with rope data structure | ||
| const r = rope.create('Hello'); |
There was a problem hiding this comment.
The method name should be rope.createRope instead of rope.create. The rope namespace does not have a create method - it exports createRope and createEmptyRope.
| const r = rope.create('Hello'); | |
| const r = rope.createRope('Hello'); |
Summary
createScreenEntity,createBoxEntity, etc.) instead of raw SoA component accessposition,scroll,content,rope,colorsnamespace usageCloses #1250
Test plan