Skip to content
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

Add dot notation to get/set Parse.Object attributes #1313

Open
dblythy opened this issue Mar 5, 2021 · 7 comments · May be fixed by #1484
Open

Add dot notation to get/set Parse.Object attributes #1313

dblythy opened this issue Mar 5, 2021 · 7 comments · May be fixed by #1484
Labels
type:feature New feature or improvement of existing feature

Comments

@dblythy
Copy link
Member

dblythy commented Mar 5, 2021

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

@dblythy
Copy link
Member Author

dblythy commented Mar 5, 2021

closing for now as this is probably better suited to StackOverflow / the forum

@dblythy dblythy closed this as completed Mar 5, 2021
@bobokeke0
Copy link

bobokeke0 commented Oct 16, 2021

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);
   }
}

@dblythy dblythy reopened this May 24, 2022
@parse-github-assistant
Copy link

parse-github-assistant bot commented May 24, 2022

Thanks for opening this issue!

@mtrezza mtrezza added the type:feature New feature or improvement of existing feature label May 24, 2022
@mtrezza mtrezza changed the title Dot Notation for VueJS Add dot notation to get/set Parse.Object attributes May 27, 2022
@mtrezza mtrezza changed the title Add dot notation to get/set Parse.Object attributes Add dot notation to get/set Parse.Object attributes May 27, 2022
@mtrezza mtrezza pinned this issue May 27, 2022
@dblythy dblythy closed this as completed Mar 4, 2023
@mtrezza mtrezza reopened this Mar 5, 2023
@sadortun
Copy link
Contributor

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.

@mtrezza
Copy link
Member

mtrezza commented Aug 14, 2023

I think this has been discussed in #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.

@mortenmo
Copy link
Contributor

mortenmo commented Sep 22, 2023

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[];
}

@theolundqvist
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:feature New feature or improvement of existing feature
Projects
None yet
6 participants