Skip to content

Conversation

@mateuszJS
Copy link
Owner

@mateuszJS mateuszJS commented Jun 8, 2025

Summary by CodeRabbit

  • New Features

    • Added support for initializing and updating image assets with associated URLs and corner points.
    • Introduced automatic calculation of default image placement and scaling on the canvas.
    • Enabled external callbacks to receive updates whenever assets change.
  • Refactor

    • Enhanced asset management to include both image data and metadata.
    • Improved consistency in code formatting and parameter handling.
  • Chores

    • Updated import styles and type declarations for improved code clarity.

@coderabbitai
Copy link

coderabbitai bot commented Jun 8, 2025

Walkthrough

This update refactors asset management and rendering logic by expanding the initCreator API to support serialized assets and asset update callbacks. It introduces new types and utility functions, connects Zig logic for asset updates, and adjusts rendering functions to handle textures with associated URLs, enhancing the integration between TypeScript and Zig modules.

Changes

File(s) Change Summary
integration-tests/index.ts Updated imports, modified initCreator call to accept assets and callback, minor event handler tweaks.
src/WebGPU/pointer.ts Reformatted imports and event listeners, added empty mouseleave handler, no logic changes.
src/index.ts Expanded initCreator API, added types, refactored asset handling, integrated asset update callback.
src/logic/index.d.ts, src/logic/index.zig Added Texture type, asset update callback connection, and related Zig logic for asset notifications.
src/run.ts Changed textures parameter to TextureSource[], updated usage to extract .texture property.
src/utils/getDefaultPoints.ts Added getDefaultPoints utility function for default image placement and scaling.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant UI (integration-tests/index.ts)
    participant Creator (initCreator)
    participant ZigLogic (connectOnAssetUpdateCallback)
    participant Renderer (runCreator)

    User->>UI (integration-tests/index.ts): Selects image file
    UI->>Creator: Calls addImage(id, img, points?)
    Creator->>Renderer: Updates textures with {texture, url}
    Creator->>ZigLogic: Notifies asset update via callback
    ZigLogic->>Creator: Triggers onAssetsUpdate callback with serialized assets
    Creator->>UI: Calls provided onAssetsUpdate(assets)
Loading

Possibly related PRs

Poem

A rabbit hopped through code today,
Refactoring assets in a clever way.
Textures and URLs now hand in paw,
With Zig and TypeScript, they both saw
How callbacks and points could make things bright—
Hooray for code that just feels right!
🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

npm error Exit handler never called!
npm error This is an error with npm itself. Please report this error at:
npm error https://github.com/npm/cli/issues
npm error A complete log of this run can be found in: /.npm/_logs/2025-06-08T15_10_32_924Z-debug-0.log

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 6

🧹 Nitpick comments (3)
src/utils/getDefaultPoints.ts (1)

24-35: Consider edge case handling for zero-dimension images.

The scaling logic is sound, but the function doesn't handle edge cases where the image might have zero width or height, which would result in division by zero.

Consider adding validation:

function getDefaultTextureScale(img: HTMLImageElement, canvas: HTMLCanvasElement) {
+ if (img.width === 0 || img.height === 0) {
+   return 1 // or throw an error
+ }
+ 
  const heightDiff = canvas.height - img.height
  const widthDiff = canvas.width - img.width
src/WebGPU/pointer.ts (1)

20-20: Remove empty event listener or add implementation.

The empty mouseleave event listener serves no purpose and adds unnecessary overhead. Either implement the logic or remove it entirely.

- canvas.addEventListener('mouseleave', () => {})

If you need to track when the mouse leaves the canvas (e.g., to reset pointer state), consider implementing it:

- canvas.addEventListener('mouseleave', () => {})
+ canvas.addEventListener('mouseleave', () => {
+   // Reset pointer state or handle mouse leave
+ })
integration-tests/index.ts (1)

11-20: Consider uncommenting the example asset for more comprehensive testing.

The commented-out serialized asset example could provide valuable test coverage for the asset loading functionality. Consider creating a test case that actually uses this asset.

🧰 Tools
🪛 GitHub Check: CodeQL

[warning] 16-16: DOM text reinterpreted as HTML
DOM text is reinterpreted as HTML without escaping meta-characters.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2421444 and 8382929.

📒 Files selected for processing (7)
  • integration-tests/index.ts (1 hunks)
  • src/WebGPU/pointer.ts (2 hunks)
  • src/index.ts (2 hunks)
  • src/logic/index.d.ts (2 hunks)
  • src/logic/index.zig (2 hunks)
  • src/run.ts (3 hunks)
  • src/utils/getDefaultPoints.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (4)
src/run.ts (2)
src/index.ts (1)
  • TextureSource (24-27)
src/WebGPU/programs/initPrograms.ts (3)
  • drawTexture (16-16)
  • drawTriangle (10-10)
  • pickTexture (17-17)
integration-tests/index.ts (1)
src/index.ts (1)
  • initCreator (29-101)
src/utils/getDefaultPoints.ts (1)
src/utils/clamp.ts (1)
  • clamp (1-3)
src/index.ts (4)
src/run.ts (1)
  • runCreator (11-56)
src/logic/index.d.ts (3)
  • connectOnAssetUpdateCallback (32-32)
  • ASSET_ID_TRESHOLD (16-16)
  • add_texture (18-18)
src/WebGPU/getTexture/index.ts (1)
  • createTextureFromSource (106-117)
src/utils/getDefaultPoints.ts (1)
  • getDefaultPoints (3-19)
🪛 GitHub Check: CodeQL
integration-tests/index.ts

[warning] 16-16: DOM text reinterpreted as HTML
DOM text is reinterpreted as HTML without escaping meta-characters.

🔇 Additional comments (10)
src/utils/getDefaultPoints.ts (2)

3-19: LGTM! Well-structured utility function with proper scaling logic.

The function correctly calculates default points for texture mapping with appropriate centering and scaling. The implementation properly handles the coordinate transformation from canvas space to UV coordinates.


28-31: Verify logic for determining dominant dimension.

The condition heightDiff < widthDiff determines whether to scale by height or width, but this logic might not always produce the expected result. When heightDiff is smaller, it means the image height is closer to canvas height, so scaling by height makes sense. However, consider if this aligns with the intended behavior.

Would you like me to verify this logic with some test cases to ensure it produces the expected scaling behavior?

src/WebGPU/pointer.ts (1)

1-6: LGTM! Consistent formatting improvements.

The formatting changes improve code consistency by using single quotes, proper indentation, and multi-line imports. Moving updatePointer inside the function scope is appropriate since it's only used within initMouseController.

Also applies to: 14-18, 22-25, 39-42

integration-tests/index.ts (2)

8-23: LGTM! Proper integration with updated initCreator API.

The changes correctly implement the new initCreator signature with serialized assets and asset update callback. The empty array and console.log callback are appropriate for testing purposes.

🧰 Tools
🪛 GitHub Check: CodeQL

[warning] 16-16: DOM text reinterpreted as HTML
DOM text is reinterpreted as HTML without escaping meta-characters.


27-27: Static analysis warning is a false positive.

The CodeQL warning about "DOM text reinterpreted as HTML" on line 16 appears to be a false positive. Line 27 shows a standard type assertion for accessing files property from an input element, which is safe and doesn't involve HTML interpretation.

src/run.ts (2)

6-6: LGTM! Proper type integration with TextureSource interface.

The import and parameter type change correctly align with the new TextureSource interface that includes both texture and URL information.

Also applies to: 16-16


26-27: LGTM! Correct extraction of GPU texture from TextureSource wrapper.

The changes properly access the .texture property from TextureSource objects, maintaining the existing WebGPU rendering functionality while supporting the enhanced texture metadata structure.

Also applies to: 29-30

src/logic/index.d.ts (1)

9-13: Good addition of type definitions and callback mechanism.

The new Texture type and connectOnAssetUpdateCallback function provide proper type safety for the asset update flow between Zig and TypeScript. The quote style change also improves consistency.

Also applies to: 15-15, 32-32

src/index.ts (2)

73-84: Good validation and integration with the new texture management.

The ID validation and integration with the getDefaultPoints utility function improves the robustness of the API.


15-27: Well-structured type definitions for the new asset management system.

The SerializedAsset and TextureSource types provide clear interfaces for the expanded functionality, and the updated function signature properly reflects the new requirements.

Also applies to: 29-33

Comment on lines +26 to +30
draw_texture: (vertex_data, texture_id) =>
drawTexture(canvasPass, canvasMatrix, vertex_data.typedArray, textures[texture_id].texture),
draw_triangle: (vertex_data) => drawTriangle(canvasPass, canvasMatrix, vertex_data.typedArray),
pick_texture: (vertex_data, texture_id) =>
pickTexture(pickPass, pickMatrix, vertex_data.typedArray, textures[texture_id]),
pickTexture(pickPass, pickMatrix, vertex_data.typedArray, textures[texture_id].texture),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider adding bounds checking for texture array access.

The code accesses textures[texture_id] without bounds checking. If texture_id is out of range, this will cause a runtime error.

Consider adding bounds validation:

  connectWebGPUPrograms({
    draw_texture: (vertex_data, texture_id) => {
+     if (texture_id >= textures.length) {
+       console.error(`Invalid texture_id: ${texture_id}`)
+       return
+     }
      drawTexture(canvasPass, canvasMatrix, vertex_data.typedArray, textures[texture_id].texture)
    },
    pick_texture: (vertex_data, texture_id) => {
+     if (texture_id >= textures.length) {
+       console.error(`Invalid texture_id: ${texture_id}`)
+       return
+     }
      pickTexture(pickPass, pickMatrix, vertex_data.typedArray, textures[texture_id].texture)
    },
  })
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
draw_texture: (vertex_data, texture_id) =>
drawTexture(canvasPass, canvasMatrix, vertex_data.typedArray, textures[texture_id].texture),
draw_triangle: (vertex_data) => drawTriangle(canvasPass, canvasMatrix, vertex_data.typedArray),
pick_texture: (vertex_data, texture_id) =>
pickTexture(pickPass, pickMatrix, vertex_data.typedArray, textures[texture_id]),
pickTexture(pickPass, pickMatrix, vertex_data.typedArray, textures[texture_id].texture),
connectWebGPUPrograms({
draw_texture: (vertex_data, texture_id) => {
if (texture_id < 0 || texture_id >= textures.length) {
console.error(`Invalid texture_id: ${texture_id}`)
return
}
drawTexture(
canvasPass,
canvasMatrix,
vertex_data.typedArray,
textures[texture_id].texture
)
},
draw_triangle: (vertex_data) =>
drawTriangle(canvasPass, canvasMatrix, vertex_data.typedArray),
pick_texture: (vertex_data, texture_id) => {
if (texture_id < 0 || texture_id >= textures.length) {
console.error(`Invalid texture_id: ${texture_id}`)
return
}
pickTexture(
pickPass,
pickMatrix,
vertex_data.typedArray,
textures[texture_id].texture
)
},
})
🤖 Prompt for AI Agents
In src/run.ts around lines 26 to 30, the code accesses textures[texture_id]
without checking if texture_id is within the valid range, which can cause
runtime errors. Add bounds checking before accessing textures[texture_id] to
ensure texture_id is a valid index within the textures array. If texture_id is
invalid, handle the case gracefully, such as by returning early, throwing a
descriptive error, or using a default texture.

declare module '*.zig' {
export const ASSET_ID_TRESHOLD: number
export const init_state: (width: number, height: number) => void
export const add_texture: (id: number, points: PointUV[], textre_index: number) => void
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix the typo in the parameter name.

The parameter textre_index should be texture_index.

-export const add_texture: (id: number, points: PointUV[], textre_index: number) => void
+export const add_texture: (id: number, points: PointUV[], texture_index: number) => void
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export const add_texture: (id: number, points: PointUV[], textre_index: number) => void
export const add_texture: (id: number, points: PointUV[], texture_index: number) => void
🤖 Prompt for AI Agents
In src/logic/index.d.ts at line 18, there is a typo in the parameter name
`textre_index`. Rename this parameter to `texture_index` to correct the
spelling.

Comment on lines +21 to +24
var on_asset_update_cb: *const fn ([]Texture) void = undefined;
pub fn connectOnAssetUpdateCallback(cb: *const fn ([]Texture) void) void {
on_asset_update_cb = cb;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Initialize the callback pointer to prevent undefined behavior.

The on_asset_update_cb is declared as undefined, which could cause a crash if on_pointer_up is called before connectOnAssetUpdateCallback.

Consider initializing with a no-op function or checking for undefined before calling:

-var on_asset_update_cb: *const fn ([]Texture) void = undefined;
+var on_asset_update_cb: ?*const fn ([]Texture) void = null;

Then update the invocation to check for null:

-if (result.len > 0) {
-    on_asset_update_cb(result);
-}
+if (result.len > 0 and on_asset_update_cb != null) {
+    on_asset_update_cb.?(result);
+}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
var on_asset_update_cb: *const fn ([]Texture) void = undefined;
pub fn connectOnAssetUpdateCallback(cb: *const fn ([]Texture) void) void {
on_asset_update_cb = cb;
}
// src/logic/index.zig
// Change the callback pointer to an optional initialized to null
-var on_asset_update_cb: *const fn ([]Texture) void = undefined;
+var on_asset_update_cb: ?*const fn ([]Texture) void = null;
pub fn connectOnAssetUpdateCallback(cb: *const fn ([]Texture) void) void {
on_asset_update_cb = cb;
}
// …
// In on_pointer_up (around lines 86–97), guard against a null callback before calling
- if (result.len > 0) {
- on_asset_update_cb(result);
- }
+ if (result.len > 0 and on_asset_update_cb != null) {
+ on_asset_update_cb.?(result);
+ }
🤖 Prompt for AI Agents
In src/logic/index.zig around lines 21 to 24, the callback pointer
on_asset_update_cb is initialized as undefined, which risks undefined behavior
if called before being set. Fix this by initializing on_asset_update_cb to a
no-op function that matches its signature or by adding a check before invoking
it to ensure it is not undefined. This prevents crashes by ensuring the callback
pointer is always valid or safely skipped.

Comment on lines +87 to +97
var result = std.heap.page_allocator.alloc(Texture, state.assets.count()) catch unreachable;
var iterator = state.assets.iterator();
var i: usize = 0;
while (iterator.next()) |entry| {
result[i] = entry.value_ptr.*;
i += 1;
}

if (result.len > 0) {
on_asset_update_cb(result);
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix memory leak - allocated array is never freed.

The array allocated with std.heap.page_allocator.alloc is never deallocated, causing a memory leak on every pointer up event.

Since the callback likely needs to process the data asynchronously, consider either:

  1. Documenting that the callback is responsible for freeing the memory
  2. Using a different allocation strategy (e.g., arena allocator)
  3. Keeping a persistent buffer that gets reused

For immediate fix, if the callback processes synchronously, add deallocation:

 if (result.len > 0) {
     on_asset_update_cb(result);
 }
+defer std.heap.page_allocator.free(result);

However, this won't work if the callback stores the reference. Consider passing ownership to the JavaScript side or using a different memory management approach.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
var result = std.heap.page_allocator.alloc(Texture, state.assets.count()) catch unreachable;
var iterator = state.assets.iterator();
var i: usize = 0;
while (iterator.next()) |entry| {
result[i] = entry.value_ptr.*;
i += 1;
}
if (result.len > 0) {
on_asset_update_cb(result);
}
var result = std.heap.page_allocator.alloc(Texture, state.assets.count()) catch unreachable;
var iterator = state.assets.iterator();
var i: usize = 0;
while (iterator.next()) |entry| {
result[i] = entry.value_ptr.*;
i += 1;
}
if (result.len > 0) {
on_asset_update_cb(result);
}
defer std.heap.page_allocator.free(result);
🤖 Prompt for AI Agents
In src/logic/index.zig around lines 87 to 97, the array allocated with
std.heap.page_allocator.alloc is not freed, causing a memory leak. To fix this,
if the on_asset_update_cb callback processes the data synchronously and does not
retain the reference, add a call to free the allocated array immediately after
the callback returns. If the callback stores the reference asynchronously,
update the design to either transfer ownership to the caller or use a persistent
or arena allocator to manage the buffer lifecycle properly.

Comment on lines +86 to +92
assets.forEach((asset) => {
const img = new Image()
img.src = asset.url
img.onload = () => {
addImage(asset.id, img, asset.points)
}
})
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add error handling for image loading failures.

If an image fails to load, the error is silently ignored, which could lead to missing assets without any indication to the user.

 assets.forEach((asset) => {
   const img = new Image()
   img.src = asset.url
   img.onload = () => {
     addImage(asset.id, img, asset.points)
   }
+  img.onerror = (error) => {
+    console.error(`Failed to load asset ${asset.id} from ${asset.url}:`, error)
+  }
 })
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
assets.forEach((asset) => {
const img = new Image()
img.src = asset.url
img.onload = () => {
addImage(asset.id, img, asset.points)
}
})
assets.forEach((asset) => {
const img = new Image()
img.src = asset.url
img.onload = () => {
addImage(asset.id, img, asset.points)
}
img.onerror = (error) => {
console.error(`Failed to load asset ${asset.id} from ${asset.url}:`, error)
}
})
🤖 Prompt for AI Agents
In src/index.ts around lines 86 to 92, the image loading process lacks error
handling for failures. Add an onerror event handler to the Image object that
logs or handles the error appropriately when an image fails to load, ensuring
that loading failures are detected and reported instead of being silently
ignored.

Comment on lines +59 to +71
connectOnAssetUpdateCallback((serializedData: Texture[]) => {
const serializedAssetsTextureUrl = [...serializedData].map<SerializedAsset>((asset) => ({
id: asset.id,
points: [...asset.points].map((point) => ({
x: point.x,
y: point.y,
u: point.u,
v: point.v,
})),
url: textures[asset.texture_id].url,
}))
onAssetsUpdate(serializedAssetsTextureUrl)
})
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Simplify the deep copy of serialized data.

The spread operators and map functions create unnecessary copies. Since you're transforming the data anyway, the explicit copying is redundant.

-connectOnAssetUpdateCallback((serializedData: Texture[]) => {
-  const serializedAssetsTextureUrl = [...serializedData].map<SerializedAsset>((asset) => ({
-    id: asset.id,
-    points: [...asset.points].map((point) => ({
-      x: point.x,
-      y: point.y,
-      u: point.u,
-      v: point.v,
-    })),
-    url: textures[asset.texture_id].url,
-  }))
-  onAssetsUpdate(serializedAssetsTextureUrl)
-})
+connectOnAssetUpdateCallback((serializedData: Texture[]) => {
+  const serializedAssetsTextureUrl = serializedData.map<SerializedAsset>((asset) => ({
+    id: asset.id,
+    points: asset.points,
+    url: textures[asset.texture_id].url,
+  }))
+  onAssetsUpdate(serializedAssetsTextureUrl)
+})
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
connectOnAssetUpdateCallback((serializedData: Texture[]) => {
const serializedAssetsTextureUrl = [...serializedData].map<SerializedAsset>((asset) => ({
id: asset.id,
points: [...asset.points].map((point) => ({
x: point.x,
y: point.y,
u: point.u,
v: point.v,
})),
url: textures[asset.texture_id].url,
}))
onAssetsUpdate(serializedAssetsTextureUrl)
})
connectOnAssetUpdateCallback((serializedData: Texture[]) => {
const serializedAssetsTextureUrl = serializedData.map<SerializedAsset>((asset) => ({
id: asset.id,
points: asset.points,
url: textures[asset.texture_id].url,
}))
onAssetsUpdate(serializedAssetsTextureUrl)
})
🤖 Prompt for AI Agents
In src/index.ts around lines 59 to 71, the current code uses spread operators
and map functions to create deep copies of serializedData and its nested points,
which is redundant because you are already transforming the data. Simplify the
code by directly mapping over serializedData and points without spreading them
into new arrays, as the transformation itself produces new objects and no
explicit deep copy is needed.

@mateuszJS mateuszJS merged commit ac0d8e4 into next Jun 8, 2025
4 checks passed
@github-actions
Copy link

🎉 This PR is included in version 0.1.0-next.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants