You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@VueStore wraps the class's constructor in a new function, but this leads to several issues:
Static properties and methods are no longer accessible
store instanceof StoreClass returns false
The constructor name is always construct. This isn't a huge problem, but it would be a nice-to-have.
Implementation
Statics
In ES6, classes inherit statics by defining the superclass constructor as their prototype. It makes sense to me to do the same, so we just have to do Object.setPrototypeOf(wrapper, constructor)
instanceof
Solving this issue is also straightforward. The instanceof operation just checks to see if the constructor's prototype is part of the instance's prototype chain, so we just have to set wrapper.prototype = constructor.prototype
Constructor name
Setting a function name dynamically isn't as straightforward, but it's not terribly complex. (See this answer on StackOverflow.) Note that we can't use the { [name]() {...} } syntax because functions declared with the ES6 class syntax aren't constructable. Instead we use { [name]: function() {...} }, which still sets the name but is also constructable.
The text was updated successfully, but these errors were encountered:
Background
@VueStore
wraps the class's constructor in a new function, but this leads to several issues:store instanceof StoreClass
returns falseconstruct
. This isn't a huge problem, but it would be a nice-to-have.Implementation
Statics
In ES6, classes inherit statics by defining the superclass constructor as their prototype. It makes sense to me to do the same, so we just have to do
Object.setPrototypeOf(wrapper, constructor)
instanceof
Solving this issue is also straightforward. The
instanceof
operation just checks to see if the constructor'sprototype
is part of the instance's prototype chain, so we just have to setwrapper.prototype = constructor.prototype
Constructor name
Setting a function name dynamically isn't as straightforward, but it's not terribly complex. (See this answer on StackOverflow.) Note that we can't use the
{ [name]() {...} }
syntax because functions declared with the ES6 class syntax aren't constructable. Instead we use{ [name]: function() {...} }
, which still sets the name but is also constructable.The text was updated successfully, but these errors were encountered: