Add toString and valueOf methods to RefImpl class
What problem does this feature solve?
Added methods for toString and valueOf to the RefImpl class to make ref a little more nicer to work with, in terms of interpolating the values inside template literals and using the ref in logical operations.
Making the ref less error prone, less verbose and more developer friendly in terms of interpolation and working with the raw value, making the ref easier to use in templates.
valueOf might be too risky to implement as the developer might not know which operations uses valueOf to get the value (only negation operator "!" and strict comparison "===" doesn't ).
But toString is something i think would be a good addition to the RefImpl class.
What does the proposed API look like?
For example:
const count = ref(10);
// to string
const countStr = `Count is: ${count}`; // -> 'Count is: 10'
// valueOf
const countValue = 10 count; // -> 20
const largerThan5 = count > 5; // -> true
This has been discussed in the RFC in depth. We decided against this as these helpers only work in some situations and not in others, leading to code where you see count.value
in some places and not n others, having something work "by accident" without .value
etc.
In other words, we concluded to value explicit and uniform code over an only partially "nicer" syntax