lib/changed.js
function convertItemsToProperties(items) {

    // The object that contains the converted items
    const result = {}

    // Loop through all the inserted items
    _.mapKeys(items, (changes, itemId) => {

      // Loop through changes for this item
      _.mapKeys(changes, (value, property) => {

        // Add basic structure to hold ids and values
        if (_.isUndefined(result[property])) {
          result[property] = { ids: {}, values: {} }
        }

        // Create an array to hold ids for each value
        if (_.isUndefined(result[property].values[value])) {
          result[property].values[value] = []
        }

        // Create an object { itemId: value }
        result[property].ids[itemId] = value

        // Enter itemId in the array for this value
        result[property].values[value].push(itemId)
      })

    })

    const changedProperties = {}

    _.mapKeys(result, (changeset, property) => {
      changedProperties[property] = new ChangeSet(changeset)
    })

    return changedProperties
  }
function convertItemsToProperties(items) {

    // The object that contains the converted items
    const result = {}

    // Loop through all the inserted items
    _.mapKeys(items, (changes, itemId) => {

      // Loop through changes for this item
      _.mapKeys(changes, (value, property) => {

        // Add basic structure to hold ids and values
        if (_.isUndefined(result[property])) {
          result[property] = { ids: {}, values: {} }
        }

        // Create an array to hold ids for each value
        if (_.isUndefined(result[property].values[value])) {
          result[property].values[value] = []
        }

        // Create an object { itemId: value }
        result[property].ids[itemId] = value

        // Enter itemId in the array for this value
        result[property].values[value].push(itemId)
      })

    })

    const changedProperties = {}

    _.mapKeys(result, (changeset, property) => {
      changedProperties[property] = new ChangeSet(changeset)
    })

    return changedProperties
  }
function convertItemsToProperties ( items ) { // The object that contains the converted items const result = { } // Loop through all the inserted items _ . mapKeys ( items , ( changes , itemId ) => { // Loop through changes for this item _ . mapKeys ( changes , ( value , property ) => { // Add basic structure to hold ids and values if ( _ . isUndefined ( result [ property ] ) ) { result [ property ] = { ids : { } , values : { } } } // Create an array to hold ids for each value if ( _ . isUndefined ( result [ property ] . values [ value ] ) ) { result [ property ] . values [ value ] = [ ] } // Create an object { itemId: value } result [ property ] . ids [ itemId ] = value // Enter itemId in the array for this value result [ property ] . values [ value ] . push ( itemId ) } ) } ) const changedProperties = { } _ . mapKeys ( result , ( changeset , property ) => { changedProperties [ property ] = new ChangeSet ( changeset ) } ) return changedProperties }
Helper method that converts the set of items to a set of property
In the future this structure should be used directly by the code
that detects the changes.

Input:

{
'5586c51948fb091e068f80f4': {
status: 'pending'
},
'5586c51948fb091e068f80f5': {
status: 'pending'
}
}

Output:

{
status: {
ids: {
'5586c58848fb091e068f8115': 'pending',
'5586c58848fb091e068f8116': 'pending'
},
values: {
pending: [
'5586c58848fb091e068f8115',
'5586c58848fb091e068f8116'
]
}
}
}

@returns {{}}
Helper method that converts the set of items to a set of property In the future this structure should be used directly by the code that detects the changes .