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

Well known Symbols in reactvely #14

Open
kwangure opened this issue May 5, 2023 · 1 comment
Open

Well known Symbols in reactvely #14

kwangure opened this issue May 5, 2023 · 1 comment

Comments

@kwangure
Copy link

kwangure commented May 5, 2023

This is a question. Did you explore well known symbols while ideating on Reactively? Symbol.toPrimitive is relevant to Reactively as a convinence so that you don't have to read with signal.value everywhere but the getter is called.

import { primitive } from "@reactively/core";

const counter = primitive(0);
const isEven = primitive(() => (counter & 1) == 0);
								//	^ no dot value
const prefix = primitive('isEven is');
const evenString = primitive(() => prefix + isEven) // isEven is true; 

I haven't looked much at HasReactive but it might have relevance there too. I was wondering whether you excluded it for performance or other reasons. I suppose there's an elegance to having one interface for all data types too.

For context, I was playing with Symbol.toPrimitive at https://github.com/kwangure/eventscript to see how reactive builtins might compose just because. There are probably gains to be had integrating with the Reactively class rather than handling my own reactivity and subscriptions.

@milomg
Copy link
Owner

milomg commented May 5, 2023

This sounds awesome and I've never seen this trick before, the only drawback I can think of is strict equality is more confusing. I've mentioned this to @ryansolid to consider using in SolidJS as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants