Add dot notation to get/set `Parse.Object` attributes
Is your feature request related to a problem? Please describe.
VueJS is pretty heavy on binding data using dot notation. This makes things pretty difficult when using Parse, as to get properties you need to use .get(key) and .set(key).
This means that you have to constantly convert your data to and from JSON and Parse Objects.
Describe the solution you'd like
Be able to use dot notation for .get(key) and .set(key). This would mean, for example, you could bind an input to obj.toJSON().name <input v-model="obj.toJSON().name" placeholder="edit me">, without having to have a function to pass it to another JSON object.
Describe alternatives you've considered Subclassing using Proxy, but doesn't work with vueJS
Additional context
closing for now as this is probably better suited to StackOverflow / the forum
use getters and setters;
constructor () {
super ("ClassName");
}
get property1() {
//feel free to do some data manipulation here if you want to before returning the data
return this.get('property1');
}
set property1(value) {
//feel free to do some data manipulation here if you want to before saving the data
this.set('property1', value);
}
}
Thanks for opening this issue!
This would cause backwards compatibility issues if this feature is enable by default.
If some users are using the ParseObject to store extra temporary info, the get/set intercept temporary user data.
I think this has been discussed in https://github.com/parse-community/Parse-SDK-JS/pull/1484 and been accepted as a caveat that would go into the docs. Setting a custom property on a foreign-managed object is always at risk of breaking and probably not good practice, because Parse.Object could get a new property in the future that conflicts with the custom property. And adding a new property would not be considered a breaking change.
If someone else is interested, we've used decorators on custom parse objects to add get/set notation on the properties we want saved:
decorator:
export function ParseField<T>(
target: Parse.Object,
key: string,
): void {
Object.defineProperty(target, key, {
get: function () {
return (this as Parse.Object).get(key);
},
set: function (value: T) {
if (value === undefined || value === null) {
(this as Parse.Object).unset(key);
} else {
(this as Parse.Object).set(key, value);
}
},
enumerable: true,
configurable: true,
});
}
example:
export class MyObject extends Parse.Object {
@ParseField
public type: ProcessTypes;
@ParseField
public name: string;
@ParseField
public description: string;
@ParseField
public steps: Step[];
}
Hello, if anyone is interested I open sourced my solution for providing types and dot notation for custom database classes. https://www.npmjs.com/package/parse-sdk-ts