-
Notifications
You must be signed in to change notification settings - Fork 628
Add defaults to records in synchonized objects/arrays #372
Comments
I've solved this by prefixing local-only properties with '$', which I noticed is not deleted because of the way Is this not recommended? Do you envision changing the way |
@joshbowdoin No, you've used it as intended. There are some caveats to using |
Yeah, I submitted an issue with angularjs as far as So, perhaps I should switch to using '_' then, huh? |
We were thinking about prefixing everything with ☃. It's sort of awesome. But yes, _ would work for things you want to work with watch/equals. |
That'd be awesome! :) Josh Bowdoin On Fri, Aug 1, 2014 at 2:27 PM, katowulf [email protected] wrote:
|
The methodology for creating/updating records deletes any keys on the client which don't exist on the server. The original plan of setting defaults inside
$loaded
is effective, but a bit awkward and verbose as it requires advanced knowledge of how to pass a constructor function to $extendFactory:It could also be done by the callee, but then we're back to hacking on the instance externally:
Additionally, they may be deleted again on the next server update if the fields do not exist remotely. This condition shouldn't happen, since the record should not get saved to the server with missing defaults (i.e. required fields) and security rules validation should probably catch this.
However, there are a few cases where it's nice to have a looser interpretation of remote data, such as when a missing remote value has special meaning (but creates a lot of if/else logic locally that we want to avoid). Additionally, if security rule prevents the initial create/set op from succeeding, the local values are inexplicably deleted (because the local
value
event is raised with null to reconcile the server data with local), which compounds the debugging effort.Ideas for a solution: Investigate a simple way to apply local defaults. Something like a
$$defaults
property should be sufficient. It would be applied during$$added
and$$updated
to ensure keys in that list are set locally if not found remotely. This reduces the above syntax to this:Note that this does not resolve the case where users add fields onto their record which do not exist in the remote data. Those fields will be deleted during update. This is easily fixed by overriding $$updated not to delete the fields specified, but should also be pondered. I think this is a sufficient solution but maybe not an obvious one.
The text was updated successfully, but these errors were encountered: