Function changedDataFields

  • Returns the changed fields from A -> B. It's assumed that A and B have the same shape. ie. returns an object that only consists of fields which have changed in B compared to A.

    const a = { msg: `hi`, v: 10 };

    changedDataFields(a, { msg: `hi`, v: 10 }); // {}
    changedDataFields(a, { msg: `hi!!`, v: 10 }); // { msg: `hi!!` }
    changedDataFields(a, { msg: `hi!!` }); // { msg: `hi!!`, v: undefined }

    Under the hood, we use compareData(a, b, true). If B has additional or removed fields, this is considered an error.

    If a field is an array, the whole array is returned, rather than a diff.

    Parameters

    • a: object
    • b: object

    Returns any[] | Record<string, any>