reactively icon indicating copy to clipboard operation
reactively copied to clipboard

Well known Symbols in reactvely

Open kwangure opened this issue 1 year ago • 1 comments

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.

kwangure avatar May 05 '23 00:05 kwangure

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.

milomg avatar May 05 '23 06:05 milomg