我可以用自定义Getter观察到MOBX吗?
我需要一个可观察到的对象,该对象只是将其归还为字符串的任何属性。例如,myobs.description将简单地返回字符串“描述”。使用普通的JS对象,我将使用具有自定义Getter的代理使用,例如:
new Proxy({}, {
get: (obj, prop) => {
return prop.toString();
}})
我无法使用MOBX进行此操作,因为API使用了无法更新的代理对象。 有没有一种方法可以使用MOBX创建一个可观察到的对象,该对象可以为传递给其的任何属性具有自定义计算值吗?
I have a need for a Mobx observable object which simply returns whichever property is asked of it as a string. For example, myObs.description would simply return the string "description". With a normal JS object, I would use a proxy with a custom getter, like so:
new Proxy({}, {
get: (obj, prop) => {
return prop.toString();
}})
I can't do this with Mobx as the API uses a Proxy object that I can't update.
Is there a way to use Mobx to create an observable object that can have a custom computed value for any and every property passed to it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论