-
-
Notifications
You must be signed in to change notification settings - Fork 95
Detect and unwrap signal properties #424
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
Conversation
🦋 Changeset detectedLatest commit: e7d241c The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
709101f
to
e7d241c
Compare
src/index.js
Outdated
function isSignal(x) { | ||
return x instanceof Signal; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wondering if we should use duck-typing here like https://github.com/denoland/fresh/blob/e65643c482de9b5afee5d52af3ccc88941c35b5c/src/runtime/server/preact_hooks.tsx#L355-L362 . That way we can keep rts dependency free and don't have to keep it in sync with major @preact/signals
version increases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might end up being a much larger perf hit in the critical path though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if x !== null && typeof x === "object"
is more or less expensive than an instanceof
check. I let you decide on that one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather avoid adding a dep for a singular instanceof
check myself, and at least as of a few years ago, duck-typing with 1-2 properties usually outperformed instanceof
in Chrome. No idea of what fully happens internally there, but naively, makes sense to me.
If you've measured it & it is a perf issue, fair enough of course. I'll have some time in a bit to check the benches (if you haven't already).
Edit: At least on my system, the check Marvin linked to above doesn't seem to perform any worse than instanceof
. Ran the benches a few times and there wasn't any noticeable drop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Fixes #422