[GH-ISSUE #1] Proxyfied array .indexOf issue #2

Closed
opened 2026-05-23 08:36:09 -06:00 by gitea-mirror · 1 comment
Owner

Originally created by @appy-one on GitHub (Feb 18, 2021).
Original GitHub issue: https://github.com/appy-one/acebase-core/issues/1

Originally assigned to: @appy-one on GitHub.

The indexOf function of a proxified array value does not return expected result.

Example:

const proxy = await db.ref('chats/chat1').proxy();
const liveChat = proxy.value;
const member1 = liveChat.members[0]; // Assuming members is an array of objects
liveChat.members.indexOf(member1); // -1, should be 0

The reason this fails, is because member1 is the proxified version of the object, which is not found in the internal array of liveChat.members.

Current workaround is to use getTarget() on member1:

liveChat.members.indexOf(member1.getTarget()); // === 0

Suggested fix: override indexOf in data-proxy.ts and check if provided value is a Proxy, if so, call getTarget() on it and pass it on to native indexOf.

Originally created by @appy-one on GitHub (Feb 18, 2021). Original GitHub issue: https://github.com/appy-one/acebase-core/issues/1 Originally assigned to: @appy-one on GitHub. The ```indexOf``` function of a proxified array value does not return expected result. Example: ```js const proxy = await db.ref('chats/chat1').proxy(); const liveChat = proxy.value; const member1 = liveChat.members[0]; // Assuming members is an array of objects liveChat.members.indexOf(member1); // -1, should be 0 ``` The reason this fails, is because ```member1``` is the proxified version of the object, which is not found in the internal array of ```liveChat.members```. Current workaround is to use ```getTarget()``` on ```member1```: ```js liveChat.members.indexOf(member1.getTarget()); // === 0 ``` Suggested fix: override ```indexOf``` in [data-proxy.ts](https://github.com/appy-one/acebase-core/blob/master/src/data-proxy.ts#L710) and check if provided value is a Proxy, if so, call ```getTarget()``` on it and pass it on to native ```indexOf```.
gitea-mirror 2026-05-23 08:36:09 -06:00
Author
Owner

@appy-one commented on GitHub (Feb 19, 2021):

Fixed in v1.0.2

<!-- gh-comment-id:782177486 --> @appy-one commented on GitHub (Feb 19, 2021): Fixed in v1.0.2
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/acebase-core#2
No description provided.