Skip to content

Suggestion on getModified() #705

@karthage-spartacus

Description

@karthage-spartacus

Hi,

I'd like to suggest a modification concerning getModifed().

I think getModified() should return a dictionary (hash map) instead of an Array.
It would then enable us to make decisions based on the modified fields way more easily (calling external APIs, or throwing errors).

for example :

//model (not the complete definition)
{
      name: String,
      firstname: String
}

//setting firstname
doc.set('firstname', 'Arthur')

//getting modified value
const modified = doc.getModified() // { firstname: true, lastname: false }

if (modified.firstname || modified.lastname) {
   console.log("Hello there, I see you've changed your identity 🤓")
}

We could implement it by adding an optional field to the current API :

getModified({ toHashMap: true }) by converting the array to a hash map when necessary.

Or we could replace the current API.

In any case I find it way more practical to have a dictionary (which can be easily converted to an Array with the ES5 Object.keys() API)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions