Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add once function #80

Merged
merged 6 commits into from
Jul 8, 2024
Merged

feat: add once function #80

merged 6 commits into from
Jul 8, 2024

Conversation

aleclarson
Copy link
Member

@aleclarson aleclarson commented Jul 4, 2024

Tip

The owner of this PR can publish a preview release by commenting /publish in this PR. Afterwards, anyone can try it out by running pnpm add radashi@pr<PR_NUMBER>.

Summary

  • Add once function that mimics lodash.once but with less bloat.
  • Add once.reset function that allows a “onced” function to be called again.

For any code change,

  • Related documentation has been updated, if needed
  • Related tests have been added or updated, if needed

Does this PR introduce a breaking change?

No

src/curry/once.ts Outdated Show resolved Hide resolved
@@ -0,0 +1,55 @@
const onceResult = '__once__'
Copy link
Member

Choose a reason for hiding this comment

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

We can use Symbol to avoid any potential collisions (but I don't expect too much of them 😄 )

Copy link
Member Author

Choose a reason for hiding this comment

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

I did that originally, but since we use isolated declarations, we would have to export the symbol :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay, I found a way to use a symbol without exporting it! I'm also using that same symbol to represent an uncalled state, instead of using the in and delete operators.

src/curry/once.ts Outdated Show resolved Hide resolved
@aleclarson aleclarson merged commit 3401240 into main Jul 8, 2024
4 checks passed
@aleclarson aleclarson deleted the feat/once branch July 8, 2024 02:29
@aleclarson aleclarson added the new feature This PR adds a new function or extends an existing one label Jul 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature This PR adds a new function or extends an existing one
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants