Comments (4)
Here's a grain of salt to go along with my analysis since I'm a noob.
It appears reactive
converts class instances to an object consisting of just the public variables of the class. The root issue can be replicated with the following.
class Test {
#something;
constructor(something) {
this.#something = something;
}
}
const test = new Test("something");
console.log(test.#something);
console.log(Object.entries(test));
// Check van.reactive({ test }) if you want
Conversing with ChatGPT has given a reasonable solution. We just need to change the !(srcObj instanceof Object)
check in the reactive function to
!(srcObj && srcObj.contructor === Object && getPrototypeOf(srcObj))
We can make this smaller if we ignore the case where srcObj is created with Object.create(null)
. There may be other optimizations that I'm unaware of.
I believe this solution would make it so class instances are never reactive, which doesn't seem the greatest. There's probably another solution I'm missing.
from van.
Well, my noobness was shining bright.
Seems the issue is more with how Date operates, specifically the value of this
gets changed to the proxy instead of the Date object, which is what the functions in Date expect. Changing the get trap in the Proxy created in reactive to set the proper context on function calls might do the trick.
from van.
See https://vanjs.org/x#caveat-native-reactivity.
from van.
ok got it, I guess I'll stringify the date before inserting into state. Thanks.
from van.
Related Issues (20)
- Update Van JSX HOT 5
- Abnormal behavior under the input box. HOT 4
- vanX.list also looping empty values HOT 2
- Add a callback with just created element HOT 2
- Lifecycle event: mount and unmount HOT 1
- Download table broken HOT 2
- how to manually re-render? HOT 8
- Clear reactive array HOT 18
- Script children should not be escaped HOT 6
- Intersection observer HOT 11
- Can createDocumentFragment be used directly? HOT 2
- Smallest reactive library HOT 6
- A way to make VanJS even smaller HOT 2
- iOS usecase?
- Array type for properties values HOT 2
- A new version of the TodoList in Javascript with editable input fields
- vanjs-jsx Fragment missing HOT 6
- [vanjs-jsx] Add missing ./src/jsx-runtime.js HOT 3
- [vanjs-jsx] style property no more handled HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from van.