zapier-platform icon indicating copy to clipboard operation
zapier-platform copied to clipboard

Allow "destructuring assignment" and merging objects using the return values of dehydration functions

Open eengoron opened this issue 4 years ago • 3 comments

Current Behavior

Right now, when you use z.dehydrate you can only assign the results to a single field in a dictionary. Example:

data.custom = z.dehydrate(getLeadCustomInfo, { lead_id: data.lead_id });

However, if your dehydration function returns a dictionary of its own, you can't merge the dictionaries together. Example:

const leadInfoDict  = z.dehydrate(getLeadCustomInfo, {`lead_id`: data.lead_id });
return {...leadInfoDict, ...data}

Additionally, if your dehydration function returns an array of values, you can't use destructuring assignment to assign values to multiple fields:

[data.custom, data.lead_name] =  z.dehydrate(getLeadCustomInfo, {`lead_id`: data.lead_id });

Desired Behavior

When using z.dehydrate, and it returns an array, you should be able to assign multiple fields in a dictionary using the return value. Example:

const mainFunc = () => {
  [note.custom, note.user, note.id] = z.dehydrate(dehydrationFunc, {});
};

const dehydrationFunc = () => {
   return ['custom1', 'eric', 'note1'];
};

You should also be able to merge dictionaries using dehydration:

const mainFunc = () => {
   const data = { test : 'yes' };
   const note = z.dehydration(dehydrationFunc, {});
   return { ...data, ...note };
};

const dehydrationFunc = () => {
   return {id: 'custom1', user: 'eric'};
};

This would allow us to reduce the number of API calls when polling, to increase the efficiency of our app. Right now, we're making way too many dehydration calls because we can't assign multiple fields and there are few ways to avoid this.

Initially reported in this slack thread on Zapier Platform

eengoron avatar Jul 10 '20 16:07 eengoron