mathematic-inc / ts-japi

A highly-modular (typescript-friendly)-framework agnostic library for serializing data to the JSON:API specification
Apache License 2.0
203 stars 16 forks source link

Remove unnecessary cycles during recurseRelators method #26

Closed jaridmargolin closed 3 years ago

jaridmargolin commented 3 years ago

Description

Fixes #24

changeset-bot[bot] commented 3 years ago

🦋 Changeset detected

Latest commit: 8cfcd72bb951da04af48c427a390bc057f47d599

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package | Name | Type | | ------- | ----- | | ts-japi | Patch |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

jrandolf commented 3 years ago

I'm not too sure whether this solution works for larger resource counts (> 1). Nevertheless, I wrote a patch for this after seeing your issue. Noticed the problem must have been something within the recurse... function after seeing 11 iterations!

jaridmargolin commented 3 years ago

Hmmm. Not sure if I am understanding correctly, but I have updated tests (locally) to ensure both of these variations work:

await SerializerA.serialize(
  [{ id: "1", prop: "a" }, { id: "2", prop: "a" }],
  { depth: 10 }
)
await SerializerA.serialize(
  { id: "1", prop: "a" },
  { depth: 10 }
)

... but if you have another patch that accomplishes something similar, I can patiently wait :) Thanks for looking into it.

--

EDIT: I gave it a second look, and I have a host of issues in my implementation. Interesting it didn't get flagged by any tests. Anyways, good catch and appreciate the patch you applied 🙏.