Skip to content

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

Open
@dblythy

Description

@dblythy
Member

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

Activity

dblythy

dblythy commented on Mar 5, 2021

@dblythy
MemberAuthor

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

bobokeke0

bobokeke0 commented on Oct 16, 2021

@bobokeke0

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);
   }
}
parse-github-assistant

parse-github-assistant commented on May 24, 2022

@parse-github-assistant

Thanks for opening this issue!

changed the title [-]Dot Notation for VueJS[/-] [+]Add dot notation to get/set Parse.Object attributes[/+] on May 27, 2022
changed the title [-]Add dot notation to get/set Parse.Object attributes[/-] [+]Add dot notation to get/set `Parse.Object` attributes[/+] on May 27, 2022
pinned this issue on May 27, 2022
reopened this on Mar 5, 2023
sadortun

sadortun commented on Aug 11, 2023

@sadortun
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

mtrezza commented on Aug 14, 2023

@mtrezza
Member

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

mortenmo commented on Sep 22, 2023

@mortenmo
Contributor

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

theolundqvist commented on Oct 12, 2023

@theolundqvist

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    type:featureNew feature or improvement of existing feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @sadortun@mortenmo@dblythy@mtrezza@theolundqvist

      Issue actions

        Add dot notation to get/set `Parse.Object` attributes · Issue #1313 · parse-community/Parse-SDK-JS