-
-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SetProperty does a replace. #106
Comments
Since there are no options objects on the methods in this library, maybe a new |
A Should it do shallow or deep merge? |
I feel like I’d expect it to recursively merge, but maybe there can be a |
Should this method support arrays? If yes, it makes sense to merge the contents. However, it does not make sense to merge the contents of the array if it's inside an object, then we should replace. So this would create an inconsistency. |
The issue with the current default replace strategy is that due to the way the JS Proxy/Pass by reference works (the core workings of Vue.js) when you replace a value, it removes the reference between the "reactive" value I have created and it's parent (the page object). My suggestion would be:
Either way, we have an amended version of the library now, as we had to add extra options to some of the methods for our use cases (aside from the above) but either way, amazing library! Happy to share our changes, or at least explain them, and maybe you can do a better job than I did, ping me on Discord if you wanna go through them |
Wouldn't |
No, it doesn't make it clear that it merges an object at that path. |
@dannysmc95 would you mind elaborating on these? Perhaps by providing sample inputs and desired output? |
@PopGoesTheWza Sure, so as noted in the previous response, most of it is about preserving the original object and that any references created to it, are also kept, due to the way the Proxy API works.
I am not 100% sold on the
|
I'm in Paris and one hour "ahead" from you... I get the feeling. In the MergeProperty example, when two arrays are merged:
Without your example, I would have gone with "push whatever is in In the SyncProperty example, when two arrays are merged:
While |
@PopGoesTheWza yeah, I agree that Funnily enough within our custom version, everything is actually an extension to the Functions should be treated as functions, using them via an object I think, could be, dangerous and potentially opens the door to security issues, my assumption would be that you would just use a basic reassignment for a function, not allowing prototype style replacements, at least for us we do not have a need for that - noted below, the data applied can be converted to and from JSON, therefore things like functions would never be apart of our object, but I appreciate some people may use it like this. We also catered for Symbols, using general lookup maps, not perfect, but does a decent job. When it comes to things like Maps, Sets, etc. We avoid this entirely, the way we are using it is purely object based, so it's actually built from JSON (via server API) and then applied into our Vue app that renders the page (dynamic server-rendered pages), so when it comes to things like that, we avoid, I am unsure how a Map/Set could work in this behaviour, I am sure there is a way, but I feel like it adds a level of complexity to something I think may not be worth coding in. tl;dr, i.e. mergeProperty(foo, 'some.path', bar, { syncArray: true }); |
Practically, would a deep: |
Is there a way to make it so
setProperty
can merge, rather than replace?The text was updated successfully, but these errors were encountered: