-
Consider the following code snippet:
The POJO reports ["data", "func"] and the observable only ["data"]. In most situations this makes no problem especially since most observables will be used to carry data and not functions. But we have some use case where the observable is something that will be passed as spread to a React component (<Comp {...props} />) [in this case through semantic-ui-react but I'm currently not sure if this matters]. Somewhere in there is some Object.assign({}, defaultProps, props) which in the case of the POJO will consider func (to be specific: onClick) but the observable will just get data from the props. Loosing onClick isn't really funny... If the situation was as simple as the repro we could just use annotations on the observable to force func not to become an action but an observable itself.
But live isn't that easy: the func (onClick) is on a deeper level in the observable making it quite hard to explicitly disable auto-generation of an action. And we have absolulty no influence on the library getting the fields from the object. For now the first short question: is there a way to tell the observable proxy generator just to keep ALL fields in EVERY nesting level as simple observables - and not just guessing functions will be actions? Or is the current behavior in principal (say better than 90:10) "right" and we have to check for some other way to come around the problem? Thanks Jochen |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
That sounds like a really bad idea. If you are not careful, you might lose reactivity for any primitive values. I would really recommend passing a whole object and destructure in the component. So generally I think your use case is built around wrong assumptions on how to use observables. Besides, we can't really afford to change this behavior as it might break a whole number of codebases relying on the opposite. You can also try |
Beta Was this translation helpful? Give feedback.
-
In case of plain objects, I think it would be reasonable to preserve enumerability and doing both - making field observable and wrapping the value (function) in action. I dunno if we can do a change like that, but I think it's worth discussing. |
Beta Was this translation helpful? Give feedback.
In case of plain objects, I think it would be reasonable to preserve enumerability and doing both - making field observable and wrapping the value (function) in action. I dunno if we can do a change like that, but I think it's worth discussing.
Would it solve your problem?